diff --git a/examples/transcoding/main.go b/examples/transcoding/main.go index 4e67afb..6eb40e4 100644 --- a/examples/transcoding/main.go +++ b/examples/transcoding/main.go @@ -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") diff --git a/rational.go b/rational.go index ef6cf8f..7f8ed23 100644 --- a/rational.go +++ b/rational.go @@ -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()) +} diff --git a/rational_test.go b/rational_test.go index c34eb14..cc56a74 100644 --- a/rational_test.go +++ b/rational_test.go @@ -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())