Skip to content

Commit

Permalink
Fix transcoding example about timebase (#69)
Browse files Browse the repository at this point in the history
* Fix transcoding example about timebase

* applied review feedback

* remove comment
  • Loading branch information
hsnks100 authored Aug 31, 2024
1 parent 9b42cf0 commit 75ad7b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/transcoding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}

Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions rational.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
1 change: 1 addition & 0 deletions rational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 75ad7b5

Please sign in to comment.