From b09923632fdb6e5580340ef0e26240a419922389 Mon Sep 17 00:00:00 2001 From: oldma3095 <43288861+oldma3095@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:40:48 +0800 Subject: [PATCH] bufferSrcCtx.Initialize with dictionary (#124) * 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 * bufferSrcCtx initialize with dictionary * bufferSrcCtx initialize with dictionary * SetHardwareDeviceContext * SetHardwareDeviceContext --- buffersrc_filter_context.go | 8 ++++++-- buffersrc_filter_context_test.go | 16 ++++++++++++++++ examples/filtering/main.go | 2 +- examples/hardware_decoding_filtering/main.go | 2 +- examples/transcoding/main.go | 2 +- filter_graph_test.go | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 buffersrc_filter_context_test.go diff --git a/buffersrc_filter_context.go b/buffersrc_filter_context.go index 131722f..86caf2e 100644 --- a/buffersrc_filter_context.go +++ b/buffersrc_filter_context.go @@ -25,8 +25,12 @@ func (bfc *BuffersrcFilterContext) FilterContext() *FilterContext { } // https://ffmpeg.org/doxygen/7.0/group__lavfi.html#ga8c15af28902395399fe455f6f8236848 -func (bfc *BuffersrcFilterContext) Initialize() error { - return newError(C.avfilter_init_dict(bfc.fc.c, nil)) +func (bfc *BuffersrcFilterContext) Initialize(d *Dictionary) error { + var dc **C.AVDictionary + if d != nil { + dc = &d.c + } + return newError(C.avfilter_init_dict(bfc.fc.c, dc)) } // https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersrc.html#ga398cd2a84f8b4a588197ab9d90135048 diff --git a/buffersrc_filter_context_test.go b/buffersrc_filter_context_test.go new file mode 100644 index 0000000..b363fed --- /dev/null +++ b/buffersrc_filter_context_test.go @@ -0,0 +1,16 @@ +package astiav + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestBuffersrcFilterContext(t *testing.T) { + fg := AllocFilterGraph() + filter := FindFilterByName("movie") + bufferSrcCtx, err := fg.NewBuffersrcFilterContext(filter, "movie") + require.NoError(t, err) + d := NewDictionary() + require.NoError(t, d.Set("filename", "testdata/video.mp4", 0)) + require.NoError(t, bufferSrcCtx.Initialize(d)) +} diff --git a/examples/filtering/main.go b/examples/filtering/main.go index cbf57f8..3b667df 100644 --- a/examples/filtering/main.go +++ b/examples/filtering/main.go @@ -274,7 +274,7 @@ func initFilter() (err error) { } // Initialize buffersrc context - if err = s.buffersrcContext.Initialize(); err != nil { + if err = s.buffersrcContext.Initialize(nil); err != nil { err = fmt.Errorf("main: initializing buffersrc context failed: %w", err) return } diff --git a/examples/hardware_decoding_filtering/main.go b/examples/hardware_decoding_filtering/main.go index 0d3fade..2a0dc6d 100644 --- a/examples/hardware_decoding_filtering/main.go +++ b/examples/hardware_decoding_filtering/main.go @@ -319,7 +319,7 @@ func initFilter() (err error) { } // Initialize buffersrc context - if err = buffersrcContext.Initialize(); err != nil { + if err = buffersrcContext.Initialize(nil); err != nil { err = fmt.Errorf("main: initializing buffersrc context failed: %w", err) return } diff --git a/examples/transcoding/main.go b/examples/transcoding/main.go index 0576388..657201d 100644 --- a/examples/transcoding/main.go +++ b/examples/transcoding/main.go @@ -431,7 +431,7 @@ func initFilters() (err error) { } // Initialize buffersrc context - if err = s.buffersrcContext.Initialize(); err != nil { + if err = s.buffersrcContext.Initialize(nil); err != nil { err = fmt.Errorf("main: initializing buffersrc context failed: %w", err) return } diff --git a/filter_graph_test.go b/filter_graph_test.go index 8e728f8..9e5d11d 100644 --- a/filter_graph_test.go +++ b/filter_graph_test.go @@ -182,7 +182,7 @@ func TestFilterGraph(t *testing.T) { buffersrcContextParameters.SetWidth(src.width) } buffersrcContext.SetParameters(buffersrcContextParameters) - require.NoError(t, buffersrcContext.Initialize()) + require.NoError(t, buffersrcContext.Initialize(nil)) buffersrcContexts = append(buffersrcContexts, buffersrcContext) o := AllocFilterInOut()