#include <libavfilter/avfiltergraph.h>
#include <libavfilter/avcodec.h>
#include <libavfilter/buffersink.h>
+#include <libavfilter/buffersrc.h>
const char *filter_descr = "scale=78:24";
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE };
+ AVBufferSinkParams *buffersink_params;
+
filter_graph = avfilter_graph_alloc();
/* buffer video source: the decoded frames from the decoder will be inserted here. */
- snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d",
- dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
- dec_ctx->time_base.num, dec_ctx->time_base.den,
- dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);
+ snprintf(args, sizeof(args),
+ "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
+ dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+ 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",
args, NULL, filter_graph);
if (ret < 0) {
}
/* 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",
- NULL, pix_fmts, filter_graph);
+ NULL, buffersink_params, filter_graph);
+ av_free(buffersink_params);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
return ret;
frame.pts = av_frame_get_best_effort_timestamp(&frame);
/* 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 */
- while (avfilter_poll_frame(buffersink_ctx->inputs[0])) {
- av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
+ while (1) {
+ 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) {
display_picref(picref, buffersink_ctx->inputs[0]->time_base);
- avfilter_unref_buffer(picref);
+ avfilter_unref_bufferp(&picref);
}
}
}