[FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder

Stefano Sabatini stefasab at gmail.com
Sat Sep 2 18:19:21 EEST 2023


Fix crash occurring when the list of sample formats is not defined in the encoder,
use the decoder one in that case.

Possibly fix issue:
http://trac.ffmpeg.org/ticket/5849
---
 doc/examples/transcode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 1d22a4b09e..3c72b9377e 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -189,8 +189,10 @@ static int open_output_file(const char *filename)
                 ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
                 if (ret < 0)
                     return ret;
-                /* take first format from list of supported formats */
-                enc_ctx->sample_fmt = encoder->sample_fmts[0];
+
+                /* take first format from list of supported formats or use decoder one */
+                enc_ctx->sample_fmt = encoder->sample_fmts ? encoder->sample_fmts[0] : dec_ctx->sample_fmt;
+
                 enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
             }
 
-- 
2.34.1



More information about the ffmpeg-devel mailing list