examples/filtering_video: update to the new API

Update the video filtering example program based on the audio one.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
This commit is contained in:
Gavin Kinsey 2012-06-26 09:16:16 +01:00 committed by Stefano Sabatini
parent 37c3864ef7
commit 9ebed95db6

View File

@ -34,6 +34,7 @@
#include <libavfilter/avfiltergraph.h> #include <libavfilter/avfiltergraph.h>
#include <libavfilter/avcodec.h> #include <libavfilter/avcodec.h>
#include <libavfilter/buffersink.h> #include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
const char *filter_descr = "scale=78:24"; const char *filter_descr = "scale=78:24";
@ -87,13 +88,17 @@ static int init_filters(const char *filters_descr)
AVFilterInOut *outputs = avfilter_inout_alloc(); AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc(); AVFilterInOut *inputs = avfilter_inout_alloc();
enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE }; enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE };
AVBufferSinkParams *buffersink_params;
filter_graph = avfilter_graph_alloc(); filter_graph = avfilter_graph_alloc();
/* buffer video source: the decoded frames from the decoder will be inserted here. */ /* buffer video source: the decoded frames from the decoder will be inserted here. */
snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d", snprintf(args, sizeof(args),
dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
dec_ctx->time_base.num, dec_ctx->time_base.den, dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den); dec_ctx->time_base.num, dec_ctx->time_base.den,
dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
args, NULL, filter_graph); args, NULL, filter_graph);
if (ret < 0) { if (ret < 0) {
@ -102,8 +107,11 @@ static int init_filters(const char *filters_descr)
} }
/* buffer video sink: to terminate the filter chain. */ /* buffer video sink: to terminate the filter chain. */
buffersink_params = av_buffersink_params_alloc();
buffersink_params->pixel_fmts = pix_fmts;
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
NULL, pix_fmts, filter_graph); NULL, buffersink_params, filter_graph);
av_free(buffersink_params);
if (ret < 0) { if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n"); av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
return ret; return ret;
@ -201,14 +209,22 @@ int main(int argc, char **argv)
frame.pts = av_frame_get_best_effort_timestamp(&frame); frame.pts = av_frame_get_best_effort_timestamp(&frame);
/* push the decoded frame into the filtergraph */ /* push the decoded frame into the filtergraph */
av_vsrc_buffer_add_frame(buffersrc_ctx, &frame, 0); if (av_buffersrc_add_frame(buffersrc_ctx, &frame, 0) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
break;
}
/* pull filtered pictures from the filtergraph */ /* pull filtered pictures from the filtergraph */
while (avfilter_poll_frame(buffersink_ctx->inputs[0])) { while (1) {
av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0); ret = av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
if (ret < 0)
goto end;
if (picref) { if (picref) {
display_picref(picref, buffersink_ctx->inputs[0]->time_base); display_picref(picref, buffersink_ctx->inputs[0]->time_base);
avfilter_unref_buffer(picref); avfilter_unref_bufferp(&picref);
} }
} }
} }