diff mbox series

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

Message ID 20230902151921.1712373-12-stefasab@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Stefano Sabatini Sept. 2, 2023, 3:19 p.m. UTC
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(-)

Comments

Paul B Mahol Sept. 3, 2023, 7:41 a.m. UTC | #1
Decoder formats may not relate to encoder formats, thus this one looks too
hackish to me to accept.
Stefano Sabatini Sept. 5, 2023, 11:48 p.m. UTC | #2
On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> Decoder formats may not relate to encoder formats, thus this one looks too
> hackish to me to accept.

Agreed, but this is yet another change unrelated to the fix.
Stefano Sabatini Sept. 5, 2023, 11:49 p.m. UTC | #3
On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> Decoder formats may not relate to encoder formats, thus this one looks too
> hackish to me to accept.

Agreed but this is unrelated to the crash fix.
Paul B Mahol Sept. 6, 2023, 12:37 a.m. UTC | #4
On Wed, Sep 6, 2023 at 1:49 AM Stefano Sabatini <stefasab@gmail.com> wrote:

> On date Sunday 2023-09-03 09:41:49 +0200, Paul B Mahol wrote:
> > Decoder formats may not relate to encoder formats, thus this one looks
> too
> > hackish to me to accept.
>
> Agreed but this is unrelated to the crash fix.
>

And what if decoder ones are empty too?
diff mbox series

Patch

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};
             }