[FFmpeg-devel] PATCH: examples/transcode_aac.c drain/flush to output

Ray whatdoineed2do at yahoo.co.uk
Fri May 7 20:05:13 EEST 2021


Example transocde_aac.c does not drain queue and write to output when requested, resulting in "frames left in queue on closing" warning messages and samples/frames lost.

$ ./transcode_aac foo.wav foo.aac
[aac @ 0x1e299c0] Qavg: 55159.750
[aac @ 0x1e299c0] 1 frames left in the queue on closing

An attempt to drain the Q exists (a loop calling encode_audio_frame() with a NULL frame), but inside the function it mishandles the avcodec_send_frame() return code, forcing it to cleanup upon EOF (due to the NULL frame) instead of continuing to avcodec_recieve_frame() and av_write_frame().

Tested with transcode_aac and ffmpeg on the same input following patch to confirm identifcal
$ ffmpeg -i foo.wav -ab 96k -ac 2 bar.aac
$ diff foo.aac bar.aac


>From 321a4459c406b9fcb332a64bfac43f718f262309 Mon Sep 17 00:00:00 2001
From: whatdoineed2do/Ray <whatdoineed2do at gmail.com>
Date: Fri, 7 May 2021 17:23:56 +0100
Subject: [PATCH] Fixes mishandling of return code from avcodec_send_frame()
 (EOF) when attempting to drain and flush all frames to output file.

Signed-off-by: whatdoineed2do/Ray <whatdoineed2do at gmail.com>
---
 doc/examples/transcode_aac.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index 711076b5a5..c9badaa561 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -685,7 +685,6 @@ static int encode_audio_frame(AVFrame *frame,
     /* The encoder signals that it has nothing more to encode. */
     if (error == AVERROR_EOF) {
         error = 0;
-        goto cleanup;
     } else if (error < 0) {
         fprintf(stderr, "Could not send packet for encoding (error '%s')\n",
                 av_err2str(error));
--
2.26.3




More information about the ffmpeg-devel mailing list