From patchwork Sat May 18 16:11:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 48984 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp3522754pzb; Sat, 18 May 2024 09:11:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnfgDf6WbO8G1NHcP29ZcbC/Y7/8RHQ/t/eVIHYILgPSSWhOa+LAQE0pDqlnige7Zwk+LgrLVyqbKMxF5+TIXUCBEs0p9IB7lTgw== X-Google-Smtp-Source: AGHT+IGx9kjYnx7a8YjLeIwBtMrKUxhrJgzmp1V+Z+T3xAZzC77RY6iF7rrNvw/O+oTuCiTlwqhk X-Received: by 2002:a50:9b0d:0:b0:572:a4eb:6678 with SMTP id 4fb4d7f45d1cf-5752b4e2b0fmr2001861a12.19.1716048696417; Sat, 18 May 2024 09:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716048696; cv=none; d=google.com; s=arc-20160816; b=IGJzdoMjyXnmkAeVMp81ukppyYo0VrpVjC3NNkVDGmasmpcOdWI3xeJ9toXPKZEPLw KMf+nw2I+miJZYjgtmIOkx18tVhUbtBKAD1hO2KMkpWO2UdFz+CW7pZQY9RtUCb374wI gxB5Xmko7dB8xWSw3InbDcQ+7GqQ7iYjvyA/LC1FwUKXNVyj1G+5YTj+qs0Y+8rOF2m5 z8UW3+qW1iLKU7JmBEIIH+TeOT6dSL7PBeH6bAhJewBwc01Ae8KJhUhi9L+ZsgDvXngQ CLLT9ChVaBUKrImSn4D8Nx0tbCeTt6KV3zzFUzz/HT9dlIRcMf+bSW6CNT6mttwoeNnU H/JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=dFe91ATeLJVB47EMEiEUV8tIDtfuB69kldz5p0Hr+tc=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=aN8sdjE2TIowhG7qJmCD2msw7LDnOzZFo/WwoQsKWyzLuMzm5YmgR7VS0drsFguAdQ 83s09PW/rjOOX6bsAboIqGofUNfuNo4OA4/w7go+iL8A986oXyoHLBPTp+Ud7NCYuXC+ aiDY7j298aWbMSF1NxNtKeYLgX43HGVx26kz9mS7vyEtbA6/F9PwMzSm9EiuItUecii3 8vQ53vGfx2BfSU43fffCrHTPA3U7hohjARozvnDHq2zeMoyFdqlk5B6+pBZOiSaLchJX aCZUAVb1quIe33TJRnUV9JOHw25SfSg9PccPMFexVFbHRFQ9baLowMxgu9qdpsaw4w3J 2EIQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5743067d141si8931621a12.208.2024.05.18.09.11.35; Sat, 18 May 2024 09:11:36 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE34D68CE05; Sat, 18 May 2024 19:11:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7D1AB68C094 for ; Sat, 18 May 2024 19:11:25 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EC0D3EA67C; Sat, 18 May 2024 18:11:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X3CuIIXAoBOb; Sat, 18 May 2024 18:11:22 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BE59DEA671; Sat, 18 May 2024 18:11:22 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 May 2024 18:11:12 +0200 Message-Id: <20240518161116.8661-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PwLqzLhwZIsU The code only set the channel layout of the AVFormatContext, so the user could not override the channel layout if the demuxer did not have such parameter. Let's set the specified channel layouts as codec options as well. Fixes ticket #11016. A regression since 639c2f00497257cb60ecaeeac1aacfa80df3be06. Signed-off-by: Marton Balint --- doc/ffmpeg.texi | 7 ++++--- fftools/ffmpeg_demux.c | 46 +++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index da37e3ad37..83db6584fd 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1689,9 +1689,10 @@ demuxers and is mapped to the corresponding demuxer options. @item -aq @var{q} (@emph{output}) Set the audio quality (codec-specific, VBR). This is an alias for -q:a. @item -ac[:@var{stream_specifier}] @var{channels} (@emph{input/output,per-stream}) -Set the number of audio channels. For output streams it is set by -default to the number of input audio channels. For input streams -this option only makes sense for audio grabbing devices and raw demuxers +Set the number of audio channels. For output streams it is set by default to +the number of input audio channels. For input streams it overrides the number +of channels if the decoder allows it. When used without a stream specifier it +also sets the input channel count for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. @item -an (@emph{input/output}) As an input option, blocks all audio streams of a file from being filtered or diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index cba63dab5f..6e23079ceb 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1524,6 +1524,33 @@ static Demuxer *demux_alloc(void) return d; } +static int set_input_ch_layout_opts(const OptionsContext *o) +{ + /* "ch_layout" is only a valid format option for some formats, but we set + * it anyway, because it is also a codec option and we don't report + * unconsumed format options if they are codec options as well. */ + for (int i = 0; i < o->audio_channels.nb_opt; i++) { + char val[32]; + char *spec = o->audio_channels.opt[i].specifier; + char *key = av_asprintf("ch_layout%s%s", spec[0] ? ":" : "", spec); + if (!key) + return AVERROR(ENOMEM); + snprintf(val, sizeof(val), "%dC", o->audio_channels.opt[i].u.i); + av_dict_set(&o->g->format_opts, key, val, 0); + av_dict_set(&o->g->codec_opts, key, val, AV_DICT_DONT_STRDUP_KEY); + } + for (int i = 0; i < o->audio_ch_layouts.nb_opt; i++) { + char *val = o->audio_ch_layouts.opt[i].u.str; + char *spec = o->audio_ch_layouts.opt[i].specifier; + char *key = av_asprintf("ch_layout%s%s", spec[0] ? ":" : "", spec); + if (!key) + return AVERROR(ENOMEM); + av_dict_set(&o->g->format_opts, key, val, 0); + av_dict_set(&o->g->codec_opts, key, val, AV_DICT_DONT_STRDUP_KEY); + } + return 0; +} + int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) { Demuxer *d; @@ -1592,24 +1619,6 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) if (o->audio_sample_rate.nb_opt) { av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate.opt[o->audio_sample_rate.nb_opt - 1].u.i, 0); } - if (o->audio_channels.nb_opt) { - const AVClass *priv_class; - if (file_iformat && (priv_class = file_iformat->priv_class) && - av_opt_find(&priv_class, "ch_layout", NULL, 0, - AV_OPT_SEARCH_FAKE_OBJ)) { - char buf[32]; - snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i); - av_dict_set(&o->g->format_opts, "ch_layout", buf, 0); - } - } - if (o->audio_ch_layouts.nb_opt) { - const AVClass *priv_class; - if (file_iformat && (priv_class = file_iformat->priv_class) && - av_opt_find(&priv_class, "ch_layout", NULL, 0, - AV_OPT_SEARCH_FAKE_OBJ)) { - av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0); - } - } if (o->frame_rates.nb_opt) { const AVClass *priv_class; /* set the format-level framerate option; @@ -1626,6 +1635,7 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) } if (o->frame_pix_fmts.nb_opt) av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0); + ret = set_input_ch_layout_opts(o); video_codec_name = opt_match_per_type_str(&o->codec_names, 'v'); audio_codec_name = opt_match_per_type_str(&o->codec_names, 'a');