From a27bb0fbfdc2ff0b99bee5361782822b9c2e548f Mon Sep 17 00:00:00 2001 From: ma3315865 Date: Wed, 18 Dec 2024 18:25:27 +0800 Subject: [PATCH] MaxBFrames() SetMaxBFrames(n int) RcMaxRate() SetRcMaxRate(n int64) RcMinRate() SetRcMinRate(n int64) RcBufferSize() SetRcBufferSize(n int) --- codec_context.go | 40 ++++++++++++++++++++++++++++++++++++++++ codec_context_test.go | 8 ++++++++ program_test.go | 6 ------ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/codec_context.go b/codec_context.go index d92215f..4edf11a 100644 --- a/codec_context.go +++ b/codec_context.go @@ -455,3 +455,43 @@ func goAstiavCodecContextGetFormat(cc *C.AVCodecContext, pfsCPtr *C.enum_AVPixel // Callback return C.enum_AVPixelFormat(c(pfs)) } + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3e5334a611a3e2a6a653805bb9e2d4d4 +func (cc *CodecContext) MaxBFrames() int { + return int(cc.c.max_b_frames) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3e5334a611a3e2a6a653805bb9e2d4d4 +func (cc *CodecContext) SetMaxBFrames(n int) { + cc.c.max_b_frames = C.int(n) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#aa2b5582f1a360534310b686cc3f7c668 +func (cc *CodecContext) RcMaxRate() int64 { + return int64(cc.c.rc_max_rate) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#aa2b5582f1a360534310b686cc3f7c668 +func (cc *CodecContext) SetRcMaxRate(n int64) { + cc.c.rc_max_rate = C.int64_t(n) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#ac265c70b89e87455ec05eb2978def81b +func (cc *CodecContext) RcMinRate() int64 { + return int64(cc.c.rc_min_rate) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#ac265c70b89e87455ec05eb2978def81b +func (cc *CodecContext) SetRcMinRate(n int64) { + cc.c.rc_min_rate = C.int64_t(n) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a15000607a7e2371162348bb35b0184c1 +func (cc *CodecContext) RcBufferSize() int { + return int(cc.c.rc_buffer_size) +} + +// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a15000607a7e2371162348bb35b0184c1 +func (cc *CodecContext) SetRcBufferSize(n int) { + cc.c.rc_buffer_size = C.int(n) +} diff --git a/codec_context_test.go b/codec_context_test.go index 6f18b6c..57fef52 100644 --- a/codec_context_test.go +++ b/codec_context_test.go @@ -101,6 +101,10 @@ func TestCodecContext(t *testing.T) { cc4.SetTimeBase(NewRational(15, 1)) cc4.SetWidth(16) cc4.SetExtraHardwareFrames(4) + cc4.SetMaxBFrames(1) + cc4.SetRcMaxRate(1_5000_000) + cc4.SetRcMinRate(1_5000_000) + cc4.SetRcBufferSize(1_5000_000) require.Equal(t, int64(1), cc4.BitRate()) require.True(t, cc4.ChannelLayout().Equal(ChannelLayout21)) require.Equal(t, NewCodecContextFlags(4), cc4.Flags()) @@ -121,6 +125,10 @@ func TestCodecContext(t *testing.T) { require.Equal(t, NewRational(15, 1), cc4.TimeBase()) require.Equal(t, 16, cc4.Width()) require.Equal(t, 4, cc4.ExtraHardwareFrames()) + require.Equal(t, 1, cc4.MaxBFrames()) + require.Equal(t, 1_5000_000, cc4.RcMaxRate()) + require.Equal(t, 1_5000_000, cc4.RcMinRate()) + require.Equal(t, 1_5000_000, cc4.RcBufferSize()) cc5 := AllocCodecContext(nil) require.NotNil(t, cc5) diff --git a/program_test.go b/program_test.go index db8ede3..9445e7d 100644 --- a/program_test.go +++ b/program_test.go @@ -33,14 +33,8 @@ func TestProgram(t *testing.T) { s := fc.NewStream(nil) s.SetID(2) require.Equal(t, 0, p.NbStreams()) - require.Nil(t, p.StreamIndex(), nil) p.AddStream(s) require.Equal(t, 1, p.NbStreams()) - require.Equal(t, uint(0), *p.StreamIndex()) - var streamIndex uint = 1 - p.SetStreamIndex(streamIndex) - require.Equal(t, streamIndex, *p.StreamIndex()) - s.SetIndex(int(streamIndex)) ss := p.Streams() require.Equal(t, 1, len(ss)) require.Equal(t, s.ID(), ss[0].ID())