[Libav-user] yadif deinterlace how?

Robert Nagy ronag89 at gmail.com
Sat Jun 18 13:13:32 CEST 2011


An update, with less questions.

struct deinterlacer::implementation
{
std::shared_ptr<AVFilterGraph> graph_;
 std::queue<std::shared_ptr<AVFrame>> out_buffer_;

implementation(size_t width, size_t height, PixelFormat pix_fmt)
: graph_(avfilter_graph_alloc(), [](AVFilterGraph*
p){avfilter_graph_free(&p);})
{
// The filter contexts doesn't need to be freed? Does avfilter_graph_free
handle this?
AVFilterContext* video_in_filter;
AVFilterContext* video_yadif_filter;
AVFilterContext* video_out_filter;

// What is this "buffer" filter and why do I need to configure it with
time_base?
    char args[256];
std::printf(args, "%d:%d:%d:%d:%d", width, height, pix_fmt, 0, 0); // is 0,
0 ok?

    avfilter_graph_create_filter(&video_in_filter,
avfilter_get_by_name("buffer"),
  "src", args, NULL, graph_.get());
    avfilter_graph_create_filter(&video_yadif_filter,
avfilter_get_by_name("yadif"),  "deinterlace", NULL, NULL, graph_.get());
    avfilter_graph_create_filter(&video_out_filter,
avfilter_get_by_name("nullsink"),
"out", NULL, NULL, graph_.get());

avfilter_graph_add_filter(graph_.get(), video_in_filter);
avfilter_graph_add_filter(graph_.get(), video_yadif_filter);
avfilter_graph_add_filter(graph_.get(), video_out_filter);
    avfilter_graph_config(graph_.get(), NULL);
}

std::shared_ptr<AVFrame> execute(const safe_ptr<AVFrame>& frame)
{
if(!out_buffer_.empty())
{
auto result = out_buffer_.front();
out_buffer_.pop();
return result;
}

AVFilterLink* out = graph_->filters[graph_->filter_count-1]->inputs[0]; //
last filter input

// How do I send frames into the filter graph?
// Is av_vsrc_out_buffer_add_frame removed? What should I use instead?
//av_vsrc_out_buffer_add_frame(video_in_filter, frame, 0);

// Is this the correct way to read filter output?
int ret = avfilter_poll_frame(out) ;
for(int n = 0; n < ret; ++n)
     out_buffer_.push(get_frame(out));
}

std::shared_ptr<AVFrame> get_frame(AVFilterLink* link)
{
        avfilter_request_frame(link);

auto buf = link->cur_buf;

std::shared_ptr<AVFrame> result(avcodec_alloc_frame(), av_free);
avcodec_get_frame_defaults(result.get());
 result->format = buf->format;
result->width  = buf->video->w;
result->height = buf->video->h;

assert(sizeof(result->linesize) == sizeof(buf->linesize));
memcpy(result->linesize, buf->linesize, sizeof(buf->linesize)/sizeof(int));

// Copy buf->data to result->data, is there any function that does this for
me?
 return result;
}
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110618/a55ac4c0/attachment.html>


More information about the Libav-user mailing list