diff --git a/filter_context.go b/filter_context.go index 31ebc15..2a4e4b3 100644 --- a/filter_context.go +++ b/filter_context.go @@ -40,6 +40,18 @@ func (fc *FilterContext) Class() *Class { return newClassFromC(unsafe.Pointer(fc.c)) } +// https://ffmpeg.org/doxygen/7.0/structAVFilterContext.html#addd946fbe5af506a2b19f9ad7cb97c35 +func (fc *FilterContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) { + if fc.c.hw_device_ctx != nil { + C.av_buffer_unref(&fc.c.hw_device_ctx) + } + if hdc != nil { + fc.c.hw_device_ctx = C.av_buffer_ref(hdc.c) + } else { + fc.c.hw_device_ctx = nil + } +} + // https://ffmpeg.org/doxygen/7.0/structAVFilterContext.html#a6eee53e57dddfa7cca1cade870c8a44e func (fc *FilterContext) Filter() *Filter { return newFilterFromC(fc.c.filter) diff --git a/filter_graph.go b/filter_graph.go index 46ec6a2..bd26739 100644 --- a/filter_graph.go +++ b/filter_graph.go @@ -4,6 +4,7 @@ package astiav import "C" import ( "errors" + "math" "unsafe" ) @@ -154,3 +155,17 @@ func (g *FilterGraph) SendCommand(target, cmd, args string, f FilterCommandFlags }) return } + +// https://ffmpeg.org/doxygen/7.0/structAVFilterGraph.html#a0ba5c820c760788ea5f8e40c476f9704 +func (g *FilterGraph) NbFilters() int { + return int(g.c.nb_filters) +} + +// https://ffmpeg.org/doxygen/7.0/structAVFilterGraph.html#a1dafd3d239f7c2f5e3ac109578ef926d +func (g *FilterGraph) Filters() (fs []*FilterContext) { + fcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVFilterContext)(nil))](*C.AVFilterContext))(unsafe.Pointer(g.c.filters)) + for i := 0; i < g.NbFilters(); i++ { + fs = append(fs, newFilterContext(fcs[i])) + } + return +} diff --git a/filter_graph_test.go b/filter_graph_test.go index 9a5b6d2..c4a32a9 100644 --- a/filter_graph_test.go +++ b/filter_graph_test.go @@ -195,6 +195,14 @@ func TestFilterGraph(t *testing.T) { outputs = o } + require.Equal(t, len(buffersrcContexts)+1, fg.NbFilters()) + fs := fg.Filters() + require.Equal(t, len(buffersrcContexts)+1, len(fs)) + require.Equal(t, buffersinkContext.FilterContext(), fs[0]) + for idx, c := range fs[1:] { + require.Equal(t, buffersrcContexts[idx].FilterContext(), c) + } + require.NoError(t, fg.Parse(v.content, inputs, outputs)) require.NoError(t, fg.Configure())