Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: try to propagate the requested output channel layout
@ 2022-08-21 20:42 James Almer
  2022-08-23 12:26 ` James Almer
  0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2022-08-21 20:42 UTC (permalink / raw)
  To: ffmpeg-devel

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>
---
 fftools/ffmpeg_opt.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 30ca5cd609..3a555c4c16 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2865,6 +2865,42 @@ static void of_add_metadata(AVFormatContext *oc, const OptionsContext *o)
         }
     }
 }
+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)
 {
@@ -3055,7 +3091,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
                     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;
                 }
-- 
2.37.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: try to propagate the requested output channel layout
  2022-08-21 20:42 [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: try to propagate the requested output channel layout James Almer
@ 2022-08-23 12:26 ` James Almer
  0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2022-08-23 12:26 UTC (permalink / raw)
  To: ffmpeg-devel

On 8/21/2022 5:42 PM, James Almer wrote:
> 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>
> ---
>   fftools/ffmpeg_opt.c | 38 +++++++++++++++++++++++++++++++++++++-
>   1 file changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 30ca5cd609..3a555c4c16 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -2865,6 +2865,42 @@ static void of_add_metadata(AVFormatContext *oc, const OptionsContext *o)
>           }
>       }
>   }
> +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)
>   {
> @@ -3055,7 +3091,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
>                       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;
>                   }

Will apply soon.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-23 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-21 20:42 [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: try to propagate the requested output channel layout James Almer
2022-08-23 12:26 ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git