From patchwork Sun Aug 21 20:42:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 37377 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp957913pzh; Sun, 21 Aug 2022 13:42:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4I8oyK2WbrlU52z2Zi1oAnUFYSltLah5l0e92ihOvQhk3KnNulOred0m3YPZ5Z8IEFLrK4 X-Received: by 2002:a17:907:2c5b:b0:73c:5bcb:8eb2 with SMTP id hf27-20020a1709072c5b00b0073c5bcb8eb2mr9547294ejc.38.1661114571992; Sun, 21 Aug 2022 13:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661114571; cv=none; d=google.com; s=arc-20160816; b=xeHsxyBNuVj62bAdipPVt/oZIFjRyO6x+klt0oZZgbDBrOLviqg67ZcsspAv7nEBUX adR099ziekFp1Gf5NM53mPuTI5DCECxCXCmT/k3ox6PQh4WSvv0mzUXsJsm7I4W9k9ke iZVyqPckWs7RM6y94Ncwb510lew61IUwaLmnWIRx0+IJT4GYUu0sN3y6Gcp/5j+9hVia rjt64auGXVhOTE2BeNw5xfelaGOa2+yWEbYENCyhl1oUL06KjGxzj3RUZgKrV0/+6jJ7 H1QN7wbIdqdh4K+jzb7Vyt5tQWNy/dityULDK9w2ZlSbMHqENGh2oOfyyHWro7Gt/Gp4 /g6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=+kcTA0v/DBHmWsHoTeqPUKitDF/bTSy6CbfFlNTOvgc=; b=HgReAwuupvt0Q98g2DVZKh2wAJBGEHwPbJnDGmapgkzvKQVMMPTROVLdClyzP0dJXJ ARnq9xNrD+Hndc8QTlnyQvMMgXEzrlM5+8kp74u658mIWtcgSs/X+ZbDfBYoD/j0dQzH 8or1Soq3xmDfM1WfuJNLg1Pw9TZ2fnolaLrZgYq+F1PuTyudaqcaP95vEcJm2KO3tVDA gKtPCcLA3NOFNB4y0OO1LFnDJOT658qKxlbytAhye4TGVEdIhQj/kfmg8pDLqKghQIBq zSq75OmTxZYRpIDd/V0g764sxLuzzlgJXEelNl935Dn5P3a879+YOrM+igJeHqPfLSsY CSug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="UUiRuPV/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i18-20020a170906091200b0073d786c730fsi1811728ejd.237.2022.08.21.13.42.51; Sun, 21 Aug 2022 13:42:51 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="UUiRuPV/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0E0F68B93A; Sun, 21 Aug 2022 23:42:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: w422aVM6JsA2 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; }