Depending on the filters used, the filtergraph may produce trailing data after feeding it the last input frame. Update the example to include the necessary loop for draining the filtergraph.
Unified · Split
| @@ -276,6 +276,25 @@ int main(int argc, char **argv) · 275 unmodified lines | |||
| 276 | } | 276 | } |
| 277 | av_packet_unref(packet); | 277 | av_packet_unref(packet); |
| 278 | } | 278 | } |
| 279 | if (ret == AVERROR_EOF) { | ||
| 280 | /* signal EOF to the filtergraph */ | ||
| 281 | if (av_buffersrc_add_frame_flags(buffersrc_ctx, NULL, 0) < 0) { | ||
| 282 | av_log(NULL, AV_LOG_ERROR, "Error while closing the filtergraph\n"); | ||
| 283 | goto end; | ||
| 284 | } | ||
| 285 | |||
| 286 | /* pull remaining frames from the filtergraph */ | ||
| 287 | while (1) { | ||
| 288 | ret = av_buffersink_get_frame(buffersink_ctx, filt_frame); | ||
| 289 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) | ||
| 290 | break; | ||
| 291 | if (ret < 0) | ||
| 292 | goto end; | ||
| 293 | display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base); | ||
| 294 | av_frame_unref(filt_frame); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 279 | end: | 298 | end: |
| 280 | avfilter_graph_free(&filter_graph); | 299 | avfilter_graph_free(&filter_graph); |
| 281 | avcodec_free_context(&dec_ctx); | 300 | avcodec_free_context(&dec_ctx); |