@@ -18,6 +18,7 @@ import (
18
18
19
19
type Par struct {
20
20
ff.AVCodecParameters
21
+ timebase ff.AVRational
21
22
}
22
23
23
24
///////////////////////////////////////////////////////////////////////////////
@@ -76,7 +77,7 @@ func NewVideoPar(pixfmt string, size string, framerate float64) (*Par, error) {
76
77
if framerate < 0 {
77
78
return nil , ErrBadParameter .Withf ("negative framerate %v" , framerate )
78
79
} else {
79
- par .SetFramerate (ff .AVUtil_rational_d2q (framerate , 1 << 24 ))
80
+ par .timebase = ff . AVUtil_rational_invert (ff .AVUtil_rational_d2q (framerate , 1 << 24 ))
80
81
}
81
82
82
83
// Set default sample aspect ratio
@@ -152,7 +153,8 @@ func (ctx *Par) WidthHeight() string {
152
153
}
153
154
154
155
func (ctx * Par ) FrameRate () float64 {
155
- return ff .AVUtil_rational_q2d (ctx .Framerate ())
156
+ framerate := ff .AVUtil_rational_invert (ctx .timebase )
157
+ return ff .AVUtil_rational_q2d (framerate )
156
158
}
157
159
158
160
func (ctx * Par ) ValidateFromCodec (codec * ff.AVCodec ) error {
@@ -250,8 +252,7 @@ func (ctx *Par) copyVideoCodec(codec *ff.AVCodecContext) error {
250
252
codec .SetWidth (ctx .Width ())
251
253
codec .SetHeight (ctx .Height ())
252
254
codec .SetSampleAspectRatio (ctx .SampleAspectRatio ())
253
- codec .SetFramerate (ctx .Framerate ())
254
- codec .SetTimeBase (ff .AVUtil_rational_invert (ctx .Framerate ()))
255
+ codec .SetTimeBase (ctx .timebase )
255
256
return nil
256
257
}
257
258
@@ -265,9 +266,9 @@ func (ctx *Par) validateVideoCodec(codec *ff.AVCodec) error {
265
266
ctx .SetPixelFormat (pixelformats [0 ])
266
267
}
267
268
}
268
- if ctx .Framerate () .Num () == 0 || ctx .Framerate () .Den () == 0 {
269
+ if ctx .timebase .Num () == 0 || ctx .timebase .Den () == 0 {
269
270
if len (framerates ) > 0 {
270
- ctx .SetFramerate (framerates [0 ])
271
+ ctx .timebase = ff . AVUtil_rational_invert (framerates [0 ])
271
272
}
272
273
}
273
274
@@ -286,18 +287,18 @@ func (ctx *Par) validateVideoCodec(codec *ff.AVCodec) error {
286
287
if ctx .SampleAspectRatio ().Num () == 0 || ctx .SampleAspectRatio ().Den () == 0 {
287
288
ctx .SetSampleAspectRatio (ff .AVUtil_rational (1 , 1 ))
288
289
}
289
- if ctx .Framerate () .Num () == 0 || ctx .Framerate () .Den () == 0 {
290
+ if ctx .timebase .Num () == 0 || ctx .timebase .Den () == 0 {
290
291
return ErrBadParameter .With ("framerate not set" )
291
292
} else if len (framerates ) > 0 {
292
293
valid := false
293
294
for _ , fr := range framerates {
294
- if ff .AVUtil_rational_equal (fr , ctx . Framerate ( )) {
295
+ if ff .AVUtil_rational_equal (fr , ff . AVUtil_rational_invert ( ctx . timebase )) {
295
296
valid = true
296
297
break
297
298
}
298
299
}
299
300
if ! valid {
300
- return ErrBadParameter .Withf ("unsupported framerate %v" , ctx . Framerate ( ))
301
+ return ErrBadParameter .Withf ("unsupported framerate %v" , ff . AVUtil_rational_invert ( ctx . timebase ))
301
302
}
302
303
}
303
304
0 commit comments