diff --git a/container/mts/encoder_test.go b/container/mts/encoder_test.go index fb32ac24..3c9c5dd5 100644 --- a/container/mts/encoder_test.go +++ b/container/mts/encoder_test.go @@ -191,7 +191,7 @@ func TestEncodePcm(t *testing.T) { sampleSize := 2 blockSize := 16000 writeFreq := float64(sampleRate*sampleSize) / float64(blockSize) - e, err := NewEncoder(nopCloser{&buf}, (*testLogger)(t), PacketBasedPSI(10), Rate(int(writeFreq)), MediaType(EncodeAudio)) + e, err := NewEncoder(nopCloser{&buf}, (*testLogger)(t), PacketBasedPSI(10), Rate(writeFreq), MediaType(EncodeAudio)) if err != nil { t.Fatalf("could not create MTS encoder, failed with error: %v", err) } diff --git a/container/mts/options.go b/container/mts/options.go index eee206cf..0d46692f 100644 --- a/container/mts/options.go +++ b/container/mts/options.go @@ -97,12 +97,12 @@ func MediaType(mt int) func(*Encoder) error { // Rate is an option that can be passed to NewEncoder. It is used to specifiy // the rate at which the access units should be played in playback. This will // be used to create timestamps and counts such as PTS and PCR. -func Rate(r int) func(*Encoder) error { +func Rate(r float64) func(*Encoder) error { return func(e *Encoder) error { if r < 1 || r > 60 { return ErrInvalidRate } - e.writePeriod = time.Duration(float64(time.Second) / float64(r)) + e.writePeriod = time.Duration(float64(time.Second) / r) return nil } } diff --git a/revid/config/config.go b/revid/config/config.go index 9f6a776b..cefe81d4 100644 --- a/revid/config/config.go +++ b/revid/config/config.go @@ -230,9 +230,8 @@ type Config struct { // qualityStandard, qualityFair, qualityGood, qualityGreat and qualityExcellent. VBRQuality Quality - VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input. - Width uint // Width defines the input video width Raspivid input. - WriteRate float64 // WriteRate is how many times a second revid encoders will be written to. + VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input. + Width uint // Width defines the input video width Raspivid input. } // Validate checks for any errors in the config fields and defaults settings diff --git a/revid/config/config_test.go b/revid/config/config_test.go index 36831eda..b59410e3 100644 --- a/revid/config/config_test.go +++ b/revid/config/config_test.go @@ -51,7 +51,6 @@ func TestValidate(t *testing.T) { BurstPeriod: defaultBurstPeriod, MinFrames: defaultMinFrames, FrameRate: defaultFrameRate, - WriteRate: defaultWriteRate, ClipDuration: defaultClipDuration, PSITime: defaultPSITime, FileFPS: defaultFileFPS, diff --git a/revid/config/parameter/generate_parameters.go b/revid/config/parameter/generate_parameters.go index dacdc1bf..ad2cff36 100644 --- a/revid/config/parameter/generate_parameters.go +++ b/revid/config/parameter/generate_parameters.go @@ -130,7 +130,6 @@ var params = []Param{ {N: "VBRQuality", BT: "uint8", E: []string{"Standard", "Fair", "Good", "Great", "Excellent"}}, {N: "VerticalFlip", BT: "bool"}, {N: "Width", BT: "uint", Min: 640, Max: 1920}, - {N: "WriteRate", BT: "float64"}, } const fileHeader = ` diff --git a/revid/config/parameter/parameters.go b/revid/config/parameter/parameters.go index 6d0fa773..bd127ed7 100644 --- a/revid/config/parameter/parameters.go +++ b/revid/config/parameter/parameters.go @@ -915,16 +915,3 @@ func (w *Width) Set(val string) error { *w = Width(_v) return nil } - -type WriteRate float64 - -func (w *WriteRate) Type() string { return "float64" } -func (w *WriteRate) Set(val string) error { - _v, err := strconv.ParseFloat(val, 64) - if err != nil { - return fmt.Errorf("could not convert set string to float: %w", err) - } - - *w = WriteRate(_v) - return nil -} diff --git a/revid/config/variables.go b/revid/config/variables.go index 12959c8d..f84fa02b 100644 --- a/revid/config/variables.go +++ b/revid/config/variables.go @@ -49,7 +49,6 @@ const ( defaultBurstPeriod = 10 // Seconds defaultMinFrames = 100 defaultFrameRate = 25 - defaultWriteRate = 25 defaultClipDuration = 0 defaultPSITime = 2 defaultFileFPS = 0 @@ -536,14 +535,6 @@ var Variables = []struct { Type_: "uint", Update: func(c *Config, v string) { c.Width = parseUint("Width", v, c) }, }, - { - Name: "WriteRate", - Type_: "uint", - Update: func(c *Config, v string) { c.WriteRate = float64(parseUint("WriteRate", v, c)) }, - Validate: func(c *Config) { - c.WriteRate = float64(lessThanOrEqual("WriteRate", uint(c.WriteRate), 0, c, defaultWriteRate)) - }, - }, } func parseUint(n, v string, c *Config) uint { diff --git a/revid/revid.go b/revid/revid.go index e28b44ca..5b9b2fb0 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -169,7 +169,7 @@ func (r *Revid) reset(c config.Config) error { r.cfg.Logger.Log(logger.Debug, "setting up revid pipeline") err = r.setupPipeline( - func(dst io.WriteCloser, fps float64) (io.WriteCloser, error) { + func(dst io.WriteCloser, rate float64) (io.WriteCloser, error) { var st int var encOptions []func(*mts.Encoder) error @@ -212,10 +212,11 @@ func (r *Revid) reset(c config.Config) error { case config.InputAudio: st = mts.EncodeAudio encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second)) + rate = 1 / r.cfg.RecPeriod default: panic("unknown input type") } - encOptions = append(encOptions, mts.MediaType(st), mts.Rate(int(fps))) + encOptions = append(encOptions, mts.MediaType(st), mts.Rate(rate)) return mts.NewEncoder(dst, &encLog{r.cfg.Logger}, encOptions...) }, func(dst io.WriteCloser, fps int) (io.WriteCloser, error) { @@ -311,7 +312,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. // as a destination. if len(mtsSenders) != 0 { mw := multiWriter(mtsSenders...) - e, _ := mtsEnc(mw, r.cfg.WriteRate) + e, _ := mtsEnc(mw, float64(r.cfg.FrameRate)) encoders = append(encoders, e) }