user15971: I'm trying to find out how to call a FFmpeg filter (freezedetect) from within FFmpeg's source code. I see the filter's file is under libavfilter/vf_freezedetect.c, but I don't know how to use that filter inside the source code. How can I do that? And what I need to pass to the function?
My FFmpeg command's high-level API is this:
ffmpeg -i freeze.mp4 -vf "freezedetect=n=-60dB:d=2" -map 0:v:0 -f null -

And what I would need to get the resulting outputs directly after calling a function given its input arguments:
lavfi.freezedetect.freeze_start: 5.005
lavfi.freezedetect.freeze_duration: 2.03537
lavfi.freezedetect.freeze_end: 7.04037
lavfi.freezedetect.freeze_start: 13.0464
lavfi.freezedetect.freeze_duration: 3.03637
lavfi.freezedetect.freeze_end: 16.0827


user4169: You can't just call a filter, You must instantiate a filter graph.
First you need to create a buffer and buffersink via:
AVFilterContext* source = 0;
AVFilterContext* sink = 0;
AVFilterGraph *graph = avfilter_graph_alloc()
avfilter_graph_create_filter(&source, avfilter_get_by_name("buffer"), nullptr, args, nullptr, graph);


AVBufferSinkParams* buffersink_params = av_buffersink_params_alloc();
buffersink_params->pixel_fmts = /*Your pixel format HERE*/;

avfilter_graph_create_filter(&sink, avfilter_get_by_name("buffersink"), nullptr, nullptr, buffersink_params, graph);


You can then create your filter via something like this
snprintf(args, sizeof(args), "n=-60dB:d=2");
avfilter_graph_create_filter(&freezedetect, avfilter_get_by_name("freezedetect"), nullptr, args, nullptr, graph);

Then link it all together:
avfilter_link(source, 0, freezedetect, 0);
avfilter_link(freezedetect, 0, sink, 0);
avfilter_graph_config(graph, 0);

Finally you can send frames to the filter via
av_buffersrc_write_frame(source, frame);

And get the result with 
 av_buffersink_get_frame(sink, frame);

Don't forget to free it all at the end

15971: <p>I'm trying to find out how to call a <code>FFmpeg</code> filter (<code>freezedetect</code>) from within FFmpeg's source code. I see the filter's file is under <code>libavfilter/vf_freezedetect.c</code>, but I don't know how to use that filter inside the source code. How can I do that? And what I need to pass to the function?</p>

<p>My FFmpeg command's high-level API is this:</p>

<pre><code>ffmpeg -i freeze.mp4 -vf "freezedetect=n=-60dB:d=2" -map 0:v:0 -f null -
</code></pre>

<p>And what I would need to get the resulting outputs directly after calling a function given its input arguments:</p>

<pre><code>lavfi.freezedetect.freeze_start: 5.005
lavfi.freezedetect.freeze_duration: 2.03537
lavfi.freezedetect.freeze_end: 7.04037
lavfi.freezedetect.freeze_start: 13.0464
lavfi.freezedetect.freeze_duration: 3.03637
lavfi.freezedetect.freeze_end: 16.0827
</code></pre>
 4169: <p>You can't just call a filter, You must instantiate a filter graph.</p>

<p>First you need to create a <code>buffer</code> and <code>buffersink</code> via:</p>

<pre><code>AVFilterContext* source = 0;
AVFilterContext* sink = 0;
AVFilterGraph *graph = avfilter_graph_alloc()
avfilter_graph_create_filter(&amp;source, avfilter_get_by_name("buffer"), nullptr, args, nullptr, graph);


AVBufferSinkParams* buffersink_params = av_buffersink_params_alloc();
buffersink_params-&gt;pixel_fmts = /*Your pixel format HERE*/;

avfilter_graph_create_filter(&amp;sink, avfilter_get_by_name("buffersink"), nullptr, nullptr, buffersink_params, graph);

</code></pre>

<p>You can then create your filter via something like this</p>

<pre><code>snprintf(args, sizeof(args), "n=-60dB:d=2");
avfilter_graph_create_filter(&amp;freezedetect, avfilter_get_by_name("freezedetect"), nullptr, args, nullptr, graph);
</code></pre>

<p>Then link it all together:</p>

<pre><code>avfilter_link(source, 0, freezedetect, 0);
avfilter_link(freezedetect, 0, sink, 0);
avfilter_graph_config(graph, 0);
</code></pre>

<p>Finally you can send frames to the filter via</p>

<pre><code>av_buffersrc_write_frame(source, frame);
</code></pre>

<p>And get the result with </p>

<pre><code> av_buffersink_get_frame(sink, frame);
</code></pre>

<p>Don't forget to free it all at the end</p>
