X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=doc%2Fexamples%2Ffiltering_video.c;h=105a200d93401f6ea27cd0b8cb71fca8b3ff4b98;hb=41cd5af3250ef976f0a48adeb6dbccc9b2683e58;hp=01d6644620be642b3f78df07865f7100ea752f2f;hpb=4961ddfd3563a075bdea7d729361adc95370d967;p=ffmpeg diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c index 01d6644620b..105a200d934 100644 --- a/doc/examples/filtering_video.c +++ b/doc/examples/filtering_video.c @@ -29,6 +29,8 @@ #define _XOPEN_SOURCE 600 /* for usleep */ #include +#include +#include #include #include @@ -77,7 +79,6 @@ static int open_input_file(const char *filename) if (!dec_ctx) return AVERROR(ENOMEM); avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar); - av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0); /* init the video decoder */ if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) { @@ -210,19 +211,20 @@ int main(int argc, char **argv) { int ret; AVPacket packet; - AVFrame *frame = av_frame_alloc(); - AVFrame *filt_frame = av_frame_alloc(); + AVFrame *frame; + AVFrame *filt_frame; - if (!frame || !filt_frame) { - perror("Could not allocate frame"); - exit(1); - } if (argc != 2) { fprintf(stderr, "Usage: %s file\n", argv[0]); exit(1); } - avfilter_register_all(); + frame = av_frame_alloc(); + filt_frame = av_frame_alloc(); + if (!frame || !filt_frame) { + perror("Could not allocate frame"); + exit(1); + } if ((ret = open_input_file(argv[1])) < 0) goto end; @@ -250,27 +252,25 @@ int main(int argc, char **argv) goto end; } - if (ret >= 0) { - frame->pts = frame->best_effort_timestamp; + frame->pts = frame->best_effort_timestamp; + + /* push the decoded frame into the filtergraph */ + if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n"); + break; + } - /* push the decoded frame into the filtergraph */ - if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) { - av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n"); + /* pull filtered frames from the filtergraph */ + while (1) { + ret = av_buffersink_get_frame(buffersink_ctx, filt_frame); + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; - } - - /* pull filtered frames from the filtergraph */ - while (1) { - ret = av_buffersink_get_frame(buffersink_ctx, filt_frame); - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) - break; - if (ret < 0) - goto end; - display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base); - av_frame_unref(filt_frame); - } - av_frame_unref(frame); + if (ret < 0) + goto end; + display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base); + av_frame_unref(filt_frame); } + av_frame_unref(frame); } } av_packet_unref(&packet);