Skip to content

Commit

Permalink
max_b_frame and control bit_rate (#121)
Browse files Browse the repository at this point in the history
* OpenIOContextWithDictionary

* OpenIOContext

* OpenIOContext

* IOInterrupterCB

* OpenIOContext(filename string, flags IOContextFlags, ii *IOInterrupter, d *Dictionary)

* Program and Discard

* Program and Discard

* Program and Discard

* Program and Discard

* Program and Discard

* Program and Discard

* CodecContext
MaxBFrames()
SetMaxBFrames(n int)

* another pr

* delete Flags()

* delete Flags()

* delete Flags()

* delete PmtVersion()

* SetStreamIndex

* SetStreamIndex

* MaxBFrames()
SetMaxBFrames(n int)
RcMaxRate()
SetRcMaxRate(n int64)
RcMinRate()
SetRcMinRate(n int64)
RcBufferSize()
SetRcBufferSize(n int)

* rename rate control methods

* test passed
  • Loading branch information
oldma3095 authored Dec 19, 2024
1 parent ff05de2 commit 34fa811
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions codec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) RateControlMaxRate() int64 {
return int64(cc.c.rc_max_rate)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#aa2b5582f1a360534310b686cc3f7c668
func (cc *CodecContext) SetRateControlMaxRate(n int64) {
cc.c.rc_max_rate = C.int64_t(n)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#ac265c70b89e87455ec05eb2978def81b
func (cc *CodecContext) RateControlMinRate() int64 {
return int64(cc.c.rc_min_rate)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#ac265c70b89e87455ec05eb2978def81b
func (cc *CodecContext) SetRateControlMinRate(n int64) {
cc.c.rc_min_rate = C.int64_t(n)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a15000607a7e2371162348bb35b0184c1
func (cc *CodecContext) RateControlBufferSize() int {
return int(cc.c.rc_buffer_size)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a15000607a7e2371162348bb35b0184c1
func (cc *CodecContext) SetRateControlBufferSize(n int) {
cc.c.rc_buffer_size = C.int(n)
}
8 changes: 8 additions & 0 deletions codec_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func TestCodecContext(t *testing.T) {
cc4.SetTimeBase(NewRational(15, 1))
cc4.SetWidth(16)
cc4.SetExtraHardwareFrames(4)
cc4.SetMaxBFrames(1)
cc4.SetRateControlMaxRate(1_500_000)
cc4.SetRateControlMinRate(1_500_000)
cc4.SetRateControlBufferSize(1_500_000)
require.Equal(t, int64(1), cc4.BitRate())
require.True(t, cc4.ChannelLayout().Equal(ChannelLayout21))
require.Equal(t, NewCodecContextFlags(4), cc4.Flags())
Expand All @@ -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, int64(1_500_000), cc4.RateControlMaxRate())
require.Equal(t, int64(1_500_000), cc4.RateControlMinRate())
require.Equal(t, 1_500_000, cc4.RateControlBufferSize())

cc5 := AllocCodecContext(nil)
require.NotNil(t, cc5)
Expand Down

0 comments on commit 34fa811

Please sign in to comment.