mirror of https://bitbucket.org/ausocean/av.git
revid: simplify write rate
This commit is contained in:
parent
42bf1a379a
commit
cc8d205d67
|
@ -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
|
// 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
|
// 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.
|
// 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 {
|
return func(e *Encoder) error {
|
||||||
if r < 1 || r > 60 {
|
if r < 1 || r > 60 {
|
||||||
return ErrInvalidRate
|
return ErrInvalidRate
|
||||||
}
|
}
|
||||||
e.writePeriod = time.Duration(float64(time.Second) / float64(r))
|
e.writePeriod = time.Duration(float64(time.Second) / r)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -66,6 +66,7 @@ golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQg
|
||||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
|
@ -230,9 +230,8 @@ type Config struct {
|
||||||
// qualityStandard, qualityFair, qualityGood, qualityGreat and qualityExcellent.
|
// qualityStandard, qualityFair, qualityGood, qualityGreat and qualityExcellent.
|
||||||
VBRQuality Quality
|
VBRQuality Quality
|
||||||
|
|
||||||
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
||||||
Width uint // Width defines the input video width 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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate checks for any errors in the config fields and defaults settings
|
// Validate checks for any errors in the config fields and defaults settings
|
||||||
|
|
|
@ -51,7 +51,6 @@ func TestValidate(t *testing.T) {
|
||||||
BurstPeriod: defaultBurstPeriod,
|
BurstPeriod: defaultBurstPeriod,
|
||||||
MinFrames: defaultMinFrames,
|
MinFrames: defaultMinFrames,
|
||||||
FrameRate: defaultFrameRate,
|
FrameRate: defaultFrameRate,
|
||||||
WriteRate: defaultWriteRate,
|
|
||||||
ClipDuration: defaultClipDuration,
|
ClipDuration: defaultClipDuration,
|
||||||
PSITime: defaultPSITime,
|
PSITime: defaultPSITime,
|
||||||
FileFPS: defaultFileFPS,
|
FileFPS: defaultFileFPS,
|
||||||
|
|
|
@ -130,7 +130,6 @@ var params = []Param{
|
||||||
{N: "VBRQuality", BT: "uint8", E: []string{"Standard", "Fair", "Good", "Great", "Excellent"}},
|
{N: "VBRQuality", BT: "uint8", E: []string{"Standard", "Fair", "Good", "Great", "Excellent"}},
|
||||||
{N: "VerticalFlip", BT: "bool"},
|
{N: "VerticalFlip", BT: "bool"},
|
||||||
{N: "Width", BT: "uint", Min: 640, Max: 1920},
|
{N: "Width", BT: "uint", Min: 640, Max: 1920},
|
||||||
{N: "WriteRate", BT: "float64"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileHeader = `
|
const fileHeader = `
|
||||||
|
|
|
@ -915,16 +915,3 @@ func (w *Width) Set(val string) error {
|
||||||
*w = Width(_v)
|
*w = Width(_v)
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ const (
|
||||||
defaultBurstPeriod = 10 // Seconds
|
defaultBurstPeriod = 10 // Seconds
|
||||||
defaultMinFrames = 100
|
defaultMinFrames = 100
|
||||||
defaultFrameRate = 25
|
defaultFrameRate = 25
|
||||||
defaultWriteRate = 25
|
|
||||||
defaultClipDuration = 0
|
defaultClipDuration = 0
|
||||||
defaultPSITime = 2
|
defaultPSITime = 2
|
||||||
defaultFileFPS = 0
|
defaultFileFPS = 0
|
||||||
|
@ -536,14 +535,6 @@ var Variables = []struct {
|
||||||
Type_: "uint",
|
Type_: "uint",
|
||||||
Update: func(c *Config, v string) { c.Width = parseUint("Width", v, c) },
|
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 {
|
func parseUint(n, v string, c *Config) uint {
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (r *Revid) reset(c config.Config) error {
|
||||||
|
|
||||||
r.cfg.Logger.Log(logger.Debug, "setting up revid pipeline")
|
r.cfg.Logger.Log(logger.Debug, "setting up revid pipeline")
|
||||||
err = r.setupPipeline(
|
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 st int
|
||||||
var encOptions []func(*mts.Encoder) error
|
var encOptions []func(*mts.Encoder) error
|
||||||
|
|
||||||
|
@ -212,10 +212,11 @@ func (r *Revid) reset(c config.Config) error {
|
||||||
case config.InputAudio:
|
case config.InputAudio:
|
||||||
st = mts.EncodeAudio
|
st = mts.EncodeAudio
|
||||||
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second))
|
encOptions = append(encOptions, mts.TimeBasedPSI(time.Duration(r.cfg.PSITime)*time.Second))
|
||||||
|
rate = 1 / r.cfg.RecPeriod
|
||||||
default:
|
default:
|
||||||
panic("unknown input type")
|
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...)
|
return mts.NewEncoder(dst, &encLog{r.cfg.Logger}, encOptions...)
|
||||||
},
|
},
|
||||||
func(dst io.WriteCloser, fps int) (io.WriteCloser, error) {
|
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.
|
// as a destination.
|
||||||
if len(mtsSenders) != 0 {
|
if len(mtsSenders) != 0 {
|
||||||
mw := multiWriter(mtsSenders...)
|
mw := multiWriter(mtsSenders...)
|
||||||
e, _ := mtsEnc(mw, r.cfg.WriteRate)
|
e, _ := mtsEnc(mw, float64(r.cfg.FrameRate))
|
||||||
encoders = append(encoders, e)
|
encoders = append(encoders, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue