From a24d493bba1f60ff91b94a95917be12f707d1bb8 Mon Sep 17 00:00:00 2001 From: ma3315865 Date: Mon, 16 Dec 2024 15:19:45 +0800 Subject: [PATCH] CodecContext MaxBFrames() SetMaxBFrames(n int) --- codec_context.go | 10 ++++++++++ codec_context_test.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/codec_context.go b/codec_context.go index d92215f..fba3a7c 100644 --- a/codec_context.go +++ b/codec_context.go @@ -455,3 +455,13 @@ 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) +} diff --git a/codec_context_test.go b/codec_context_test.go index 6f18b6c..759234b 100644 --- a/codec_context_test.go +++ b/codec_context_test.go @@ -101,6 +101,7 @@ func TestCodecContext(t *testing.T) { cc4.SetTimeBase(NewRational(15, 1)) cc4.SetWidth(16) cc4.SetExtraHardwareFrames(4) + cc4.SetMaxBFrames(1) require.Equal(t, int64(1), cc4.BitRate()) require.True(t, cc4.ChannelLayout().Equal(ChannelLayout21)) require.Equal(t, NewCodecContextFlags(4), cc4.Flags()) @@ -121,6 +122,7 @@ 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()) cc5 := AllocCodecContext(nil) require.NotNil(t, cc5)