aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/ffmpeg_opt.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2022-08-21 15:53:10 -0300
committerJames Almer <jamrial@gmail.com>2022-08-24 10:41:59 -0300
commitf28cb0c1a8d45bf64953da6331ae4645a0c5d75d (patch)
tree6d7001eb44dfbd7e3a2ec832ef784a978ee297d0 /fftools/ffmpeg_opt.c
parent07286d82f79fe76bf59ec4888dee4bca2022fea1 (diff)
downloadffmpeg-f28cb0c1a8d45bf64953da6331ae4645a0c5d75d.tar.gz
fftools/ffmpeg_opt: try to propagate the requested output channel layout
Don't silently replace it with the default layout for the amount of channels from the requested layout. Should fix ticket #9869 Signed-off-by: James Almer <jamrial@gmail.com> (cherry picked from commit f5a663f2a9d05eddbd50609b45d92d2e39b3f9ed)
Diffstat (limited to 'fftools/ffmpeg_opt.c')
-rw-r--r--fftools/ffmpeg_opt.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index ac7fe3b27a..6e18a4a23e 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2372,6 +2372,43 @@ static int init_complex_filters(void)
return 0;
}
+static void set_channel_layout(OutputFilter *f, OutputStream *ost)
+{
+ int i, err;
+
+ if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+ /* Pass the layout through for all orders but UNSPEC */
+ err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout);
+ if (err < 0)
+ exit_program(1);
+ return;
+ }
+
+ /* Requested layout is of order UNSPEC */
+ if (!ost->enc->ch_layouts) {
+ /* Use the default native layout for the requested amount of channels when the
+ encoder doesn't have a list of supported layouts */
+ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
+ return;
+ }
+ /* Encoder has a list of supported layouts. Pick the first layout in it with the
+ same amount of channels as the requested layout */
+ for (i = 0; ost->enc->ch_layouts[i].nb_channels; i++) {
+ if (ost->enc->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
+ break;
+ }
+ if (ost->enc->ch_layouts[i].nb_channels) {
+ /* Use it if one is found */
+ err = av_channel_layout_copy(&f->ch_layout, &ost->enc->ch_layouts[i]);
+ if (err < 0)
+ exit_program(1);
+ return;
+ }
+ /* If no layout for the amount of channels requested was found, use the default
+ native layout for it. */
+ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
+}
+
static int open_output_file(OptionsContext *o, const char *filename)
{
AVFormatContext *oc;
@@ -2774,7 +2811,7 @@ loop_end:
f->sample_rates = ost->enc->supported_samplerates;
}
if (ost->enc_ctx->ch_layout.nb_channels) {
- av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
+ set_channel_layout(f, ost);
} else if (ost->enc->ch_layouts) {
f->ch_layouts = ost->enc->ch_layouts;
}