An update, with less questions.<div><br></div><div><span class="Apple-style-span"><div>struct deinterlacer::implementation</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::shared_ptr<AVFilterGraph> graph_;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::queue<std::shared_ptr<AVFrame>> out_buffer_;</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>implementation(size_t width, size_t height, PixelFormat pix_fmt)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>: graph_(avfilter_graph_alloc(), [](AVFilterGraph* p){avfilter_graph_free(&p);})</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>{<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// The filter contexts doesn't need to be freed? Does avfilter_graph_free handle this? </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>AVFilterContext* video_in_filter;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>AVFilterContext* video_yadif_filter;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>AVFilterContext* video_out_filter;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// What is this "buffer" filter and why do I need to configure it with time_base?</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> char args[256];</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>std::printf(args, "%d:%d:%d:%d:%d", width, height, pix_fmt, 0, 0); // is 0, 0 ok?</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span> avfilter_graph_create_filter(&video_in_filter,<span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_get_by_name("buffer"), "src",<span class="Apple-tab-span" style="white-space:pre"> </span> args, NULL, graph_.get());<span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> avfilter_graph_create_filter(&video_yadif_filter,<span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_get_by_name("yadif"),<span class="Apple-tab-span" style="white-space:pre"> </span> "deinterlace", NULL, NULL, graph_.get());</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> avfilter_graph_create_filter(&video_out_filter,<span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_get_by_name("nullsink"), "out",<span class="Apple-tab-span" style="white-space:pre"> </span> NULL, NULL, graph_.get());</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_graph_add_filter(graph_.get(), video_in_filter);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_graph_add_filter(graph_.get(), video_yadif_filter);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>avfilter_graph_add_filter(graph_.get(), video_out_filter);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span> avfilter_graph_config(graph_.get(), NULL);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::shared_ptr<AVFrame> execute(const safe_ptr<AVFrame>& frame)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if(!out_buffer_.empty())</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>auto result = out_buffer_.front();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>out_buffer_.pop();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return result;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>AVFilterLink* out = graph_->filters[graph_->filter_count-1]->inputs[0]; // last filter input</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// How do I send frames into the filter graph?</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Is av_vsrc_out_buffer_add_frame removed? What should I use instead?</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>//av_vsrc_out_buffer_add_frame(video_in_filter, frame, 0);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Is this the correct way to read filter output?</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>int ret = avfilter_poll_frame(out) ;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for(int n = 0; n < ret; ++n)<span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> out_buffer_.push(get_frame(out));<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::shared_ptr<AVFrame> get_frame(AVFilterLink* link)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><span class="Apple-tab-span" style="white-space: pre; "> </span> avfilter_request_frame(</span>link);</div>
<div><br><div><span class="Apple-tab-span" style="white-space:pre"> </span>auto buf = link->cur_buf;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::shared_ptr<AVFrame> result(avcodec_alloc_frame(), av_free);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>avcodec_get_frame_defaults(result.get());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>result->format = buf->format;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>result->width = buf->video->w;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>result->height = buf->video->h;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>assert(sizeof(result->linesize) == sizeof(buf->linesize));</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>memcpy(result->linesize, buf->linesize, sizeof(buf->linesize)/sizeof(int));</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Copy buf->data to result->data, is there any function that does this for me?</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>return result;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>};</div></div><div><br></div>