From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 842B9403FC for ; Sun, 21 Aug 2022 20:42:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 880D368B939; Sun, 21 Aug 2022 23:42:47 +0300 (EEST) Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FCA668B580 for ; Sun, 21 Aug 2022 23:42:41 +0300 (EEST) Received: by mail-vk1-f177.google.com with SMTP id t64so4642347vkb.12 for ; Sun, 21 Aug 2022 13:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=Vr+jAnZx6QYnLLlCd0FGpHF6s70OpCK1Q9viNVlun2o=; b=UUiRuPV//J2dRZoy6eSsccn8Rf2pRapef3jbJYe5cIB1CLx1tSfYKm7+g8QaSI7iZi TiPx7lqQS2Fu1nhL3pco6kgp/bVOu83anB7/KewwuivGw0iWMBNXaa1fIQ0V6dD1Q9Wf NqLaAqScGzhh/RU/Y927TIcRPX+nIaHWdgh/hQKYX7dcggtspmY03PytYDtv4maIhCU6 QUa45YP46HpQVyr85qqDCpYJ6SIguCMz0VxWb0rVAZc9WYNnDDmxIMqS3sbdrm3dvQws 2pEor4dCuJdW8ZIfokLNgaVBkDH+XmfN1bPcwLs8vd3h3WkWcrpM63fWNZH1bsD1Pcq+ jmjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=Vr+jAnZx6QYnLLlCd0FGpHF6s70OpCK1Q9viNVlun2o=; b=BraXzQwqkxeHYiNZ+AVQkiKqiCezYq/AmQEoabConrq0RI8uFLN4Dj+t+gOpyIVcUx FUybSD1ichu/E2kzA4Y+UdyRD4THWpedIFdEIIZdiCw3+FmaIWxY13tGtj4o5BgCJ1Tu ivyYgSTo1VguACqie2yyQQALFfaMkuolkNhjvRfMFqhbhi9dH01u7K1pzf7tGHMudtXr 2ukiI8hRjmpL6E6GVQjW9i1N55J3Wp4gdBYWoIa1rLikiilVRxqU9F+Gi2uRKbqB/T+l 86XI1AGHPvWwWctg0QI4H7S0XKVuzNo07nXatan/n2TZyxN809pxHb94wuhaZ0NVnsPC KyRQ== X-Gm-Message-State: ACgBeo1SY6jwKhlX3nvo6zSz8ocE5JOjAllgiXnTsr/seBYWpHpmGcde QOfod/fV4bGXj7zla9tatX/GlvYlKtk= X-Google-Smtp-Source: AA6agR7v8CCDomRM9jTXDhxB+31yevMfWLxHC/u5L9/zluDi9sHFMNNy14v48U+GuveaQoLMJ2iqMw== X-Received: by 2002:a1f:3f49:0:b0:38a:d56f:b713 with SMTP id m70-20020a1f3f49000000b0038ad56fb713mr3015945vka.26.1661114558885; Sun, 21 Aug 2022 13:42:38 -0700 (PDT) Received: from localhost.localdomain ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id x23-20020a9f3e97000000b00390cd0c5154sm7869434uai.26.2022.08.21.13.42.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 13:42:38 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Aug 2022 17:42:28 -0300 Message-Id: <20220821204228.2287-1-jamrial@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: try to propagate the requested output channel layout X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".