mirror of
https://github.com/asticode/go-astiav.git
synced 2025-09-26 20:21:15 +08:00
Fix transcoding example about timebase (#69)
* Fix transcoding example about timebase * applied review feedback * remove comment
This commit is contained in:
@@ -275,7 +275,7 @@ func openOutputFile() (err error) {
|
||||
} else {
|
||||
s.encCodecContext.SetSampleFormat(s.decCodecContext.SampleFormat())
|
||||
}
|
||||
s.encCodecContext.SetTimeBase(s.decCodecContext.TimeBase())
|
||||
s.encCodecContext.SetTimeBase(astiav.NewRational(1, s.encCodecContext.SampleRate()))
|
||||
} else {
|
||||
s.encCodecContext.SetHeight(s.decCodecContext.Height())
|
||||
if v := s.encCodec.PixelFormats(); len(v) > 0 {
|
||||
@@ -284,7 +284,7 @@ func openOutputFile() (err error) {
|
||||
s.encCodecContext.SetPixelFormat(s.decCodecContext.PixelFormat())
|
||||
}
|
||||
s.encCodecContext.SetSampleAspectRatio(s.decCodecContext.SampleAspectRatio())
|
||||
s.encCodecContext.SetTimeBase(s.decCodecContext.TimeBase())
|
||||
s.encCodecContext.SetTimeBase(s.decCodecContext.Framerate().Invert())
|
||||
s.encCodecContext.SetWidth(s.decCodecContext.Width())
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ func initFilters() (err error) {
|
||||
args = astiav.FilterArgs{
|
||||
"pix_fmt": strconv.Itoa(int(s.decCodecContext.PixelFormat())),
|
||||
"pixel_aspect": s.decCodecContext.SampleAspectRatio().String(),
|
||||
"time_base": s.decCodecContext.TimeBase().String(),
|
||||
"time_base": s.inputStream.TimeBase().String(),
|
||||
"video_size": strconv.Itoa(s.decCodecContext.Width()) + "x" + strconv.Itoa(s.decCodecContext.Height()),
|
||||
}
|
||||
buffersrc = astiav.FindFilterByName("buffer")
|
||||
|
@@ -50,3 +50,7 @@ func (r Rational) String() string {
|
||||
}
|
||||
return strconv.Itoa(r.Num()) + "/" + strconv.Itoa(r.Den())
|
||||
}
|
||||
|
||||
func (r Rational) Invert() Rational {
|
||||
return NewRational(r.Den(), r.Num())
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ func TestRational(t *testing.T) {
|
||||
r := NewRational(2, 1)
|
||||
require.Equal(t, 2, r.Num())
|
||||
require.Equal(t, 1, r.Den())
|
||||
require.Equal(t, 0.5, r.Invert().Float64())
|
||||
r.SetNum(1)
|
||||
r.SetDen(2)
|
||||
require.Equal(t, 1, r.Num())
|
||||
|
Reference in New Issue
Block a user