diff options
author | Zhao Zhili <zhilizhao@tencent.com> | 2023-08-11 00:54:27 +0800 |
---|---|---|
committer | Zhao Zhili <zhilizhao@tencent.com> | 2023-08-26 17:02:21 +0800 |
commit | 67d392b97941bb51fb7af3a3c9387f5ab895fa46 (patch) | |
tree | c459615156114f8d03f1285b00c727324881b5de /doc | |
parent | 2387328fa2044e49f635dc2bcafe49c28e02e762 (diff) | |
download | ffmpeg-67d392b97941bb51fb7af3a3c9387f5ab895fa46.tar.gz |
examples/transcode: flush decoder on EOF
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/examples/transcode.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c index 305181663c..ed6ac9fa03 100644 --- a/doc/examples/transcode.c +++ b/doc/examples/transcode.c @@ -585,11 +585,38 @@ int main(int argc, char **argv) av_packet_unref(packet); } - /* flush filters and encoders */ + /* flush decoders, filters and encoders */ for (i = 0; i < ifmt_ctx->nb_streams; i++) { - /* flush filter */ + StreamContext *stream; + if (!filter_ctx[i].filter_graph) continue; + + stream = &stream_ctx[i]; + + av_log(NULL, AV_LOG_INFO, "Flushing stream %u decoder\n", i); + + /* flush decoder */ + ret = avcodec_send_packet(stream->dec_ctx, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Flushing decoding failed\n"); + goto end; + } + + while (ret >= 0) { + ret = avcodec_receive_frame(stream->dec_ctx, stream->dec_frame); + if (ret == AVERROR_EOF) + break; + else if (ret < 0) + goto end; + + stream->dec_frame->pts = stream->dec_frame->best_effort_timestamp; + ret = filter_encode_write_frame(stream->dec_frame, i); + if (ret < 0) + goto end; + } + + /* flush filter */ ret = filter_encode_write_frame(NULL, i); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Flushing filter failed\n"); |