From patchwork Sun Mar 20 19:36:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 34865 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:ed11:0:0:0:0 with SMTP id hi17csp1115120nkc; Sun, 20 Mar 2022 12:38:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYw0Ubq1nriAOgGgdJ8xG8yQMaG4otd7ugHQDVfhFEN6bakqvb7/BZaKCigmDx9OBUbOIL X-Received: by 2002:a17:907:2d0a:b0:6df:8bc8:236f with SMTP id gs10-20020a1709072d0a00b006df8bc8236fmr17055535ejc.527.1647805086308; Sun, 20 Mar 2022 12:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647805086; cv=none; d=google.com; s=arc-20160816; b=ENYxnjQvzIFFOK37ZjlJfqDkvqwH3i9w/jtDLuoQmF1QuNxlyhrVMguXYiT9mwqn8H VmRE+6Eg65wDdoQ80t7dCp+S7STHgGD09+jvgf/3rddSnzZJQcM6YvlKsi70AH1OCRxA Hbuqa65bkmGcg+Dqs/FAEg1/hxhwHT46A5QR5s6VWzTCTd14NdZzxXURekEHSxM6OpeN Gv8DWclU2xbpWkAlG1GC40DcHT+Y+GaoFsTyU0ZNPbfs7ZO6WE2AfpI6xY6WuubkxPG7 YWd3Hw5Ct7FjxG9O46erldr7gl4Pr43BxGTlwlVYV1krIrwiV3kHDXWz/hgDjyCjVBKq d1Yw== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=NyxmYm3Jry461GeCi5EkTR/r06pfeifllBBZVi6IAKo=; b=t+FV5NDDfyw4mFMpdLbnbvUfb+7Kz2qUsQOsI3NjHujuek6mzi1FoiQEupnvUg893/ uFDW9WTsXenSySgcfw/JY1BP8RizcdjsQse106lw14E4TXhZ6isML4B1Vbf1MZvoO80o Jt14f8p84EIbKbsdGn4U1ygT5Q+xASBMxP3rArRMtc2E8BeQMmpkPqpLvwrdwLd1fU5y kleTQTGjAujbbkXJ3a/g/osMsGWv+pbxpTMt4AIQNSaVLxVSy33NNBby+irQdXOwzzez AmFpZ8HWrV/boo45AT2kwOUzBGSq2wp/7PCoYD/awkWMOOZ23oXJzpAP/oViBChfB9CF yi3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IqDwPyEr; 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 hb42-20020a170907162a00b006df76385bd5si6145502ejc.117.2022.03.20.12.38.06; Sun, 20 Mar 2022 12:38:06 -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=IqDwPyEr; 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 009FA68B181; Sun, 20 Mar 2022 21:37:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB14568B143 for ; Sun, 20 Mar 2022 21:37:23 +0200 (EET) Received: by mail-oo1-f49.google.com with SMTP id u30-20020a4a6c5e000000b00320d8dc2438so16844556oof.12 for ; Sun, 20 Mar 2022 12:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=AHyhiFIH8SX0iJ5kyIdiyZkkPxWPaC/e2YMhYF42Oto=; b=IqDwPyEr/nUt0AE+VF/vsGO0AbxRqKhwOPfEtoXe91DB9BjNS/2KGg6k8yBiXatp2M mk92goT1trCKlXyDtzKpz7Qa9woCqQViGIRf5dkhTQEl6cCT7B5DGagsc43/kwetXZls 02mXepkdMkW+LTIY7dfSGVxHXvEbyGTpo14o/7TiJA5s9re3TeDYACdjxOY/Ln3LpVwE bSYE/q9e+24s8JgeuNRxl/jNgVO9Q2JTZYV0Kthy1ZNJB6GiWAty/i1NQwUxWxJg8hVN QJyrdaVYlnPIK7kl9EGP4Ho9M2fhLFDn3XlSrRB9eFQcDXcYq7kQh7vONE32WGbqJk7F 2Azw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AHyhiFIH8SX0iJ5kyIdiyZkkPxWPaC/e2YMhYF42Oto=; b=tg66JUF2ttjxDv4/tBedLwNmlL+1iswZjMuP+S0f1KNVzwewwM49LiNuuC1bra7scl 3AdqNkZuq1Km9cI5JElX1HuPY5gFaafQRV/aKRFnUodjbBR+rOWClWSTy9P9eikaexEv OVJR3Yo/mHLtzoyysx2yXiW/gdFjZHlEUV4U1y132cDgLdROFyWqCMfDtc9YVSABKgV6 jUL5GWLBorcW0waikctZKwpjjSMCAzoxCg6a6wVe2WlVIxtLhjZk1Nmep51BrlcxV6Vr +0/ih5J+I98TjbvzNic9KZGerC/fAuAsXS5hxSLeIxhNt62xsvrd5ijG5y6MRKgvRQoR AYNw== X-Gm-Message-State: AOAM532COXINwLpxVUrgjvAd69HcjPCkLE63VT6Tf/PdGcUgbOFogXtf W+gdKrusX/w8fGF9cyhv9Og2Z1nII2086w== X-Received: by 2002:a05:6870:9126:b0:de:ef8:8a16 with SMTP id o38-20020a056870912600b000de0ef88a16mr1123977oae.95.1647805041830; Sun, 20 Mar 2022 12:37:21 -0700 (PDT) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id y15-20020a056870b00f00b000d75f1d9b81sm5418483oae.46.2022.03.20.12.37.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Mar 2022 12:37:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Mar 2022 16:36:17 -0300 Message-Id: <20220320193619.51185-5-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220320193619.51185-1-jamrial@gmail.com> References: <20220320193619.51185-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7 v2] ffmpeg: replace custom channel_layout code with an SpecifierOpt based one 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: xok7IHJWSngB This is cleaner and allows fine tuning which stream the option is applied to. Signed-off-by: James Almer --- No changes since last version. fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 84 ++++++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6a19dc9c7c..1e14bf9fa9 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -96,6 +96,8 @@ typedef struct OptionsContext { SpecifierOpt *codec_names; int nb_codec_names; + SpecifierOpt *audio_ch_layouts; + int nb_audio_ch_layouts; SpecifierOpt *audio_channels; int nb_audio_channels; SpecifierOpt *audio_sample_rate; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 70e6502f22..f5c759c6d1 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -55,6 +55,7 @@ static const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL}; static const char *const opt_name_audio_channels[] = {"ac", NULL}; +static const char *const opt_name_audio_ch_layouts[] = {"channel_layout", NULL}; static const char *const opt_name_audio_sample_rate[] = {"ar", NULL}; static const char *const opt_name_frame_rates[] = {"r", NULL}; static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL}; @@ -1124,6 +1125,15 @@ static int open_input_file(OptionsContext *o, const char *filename) av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0); } } + if (o->nb_audio_ch_layouts) { + 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[o->nb_audio_ch_layouts - 1].u.str, 0); + } + + } if (o->nb_frame_rates) { const AVClass *priv_class; /* set the format-level framerate option; @@ -1946,6 +1956,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in if (!ost->stream_copy) { int channels = 0; + char *layout = NULL; char *sample_fmt = NULL; MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st); @@ -1954,6 +1965,27 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in audio_enc->ch_layout.nb_channels = channels; } + MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st); + if (layout) { + if (av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + uint64_t mask; + AV_NOWARN_DEPRECATED({ + mask = av_get_channel_layout(layout); + }) + if (!mask) { +#endif + av_log(NULL, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout); + exit_program(1); +#if FF_API_OLD_CHANNEL_LAYOUT + } + av_log(NULL, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", + layout); + av_channel_layout_from_mask(&audio_enc->ch_layout, mask); +#endif + } + } + MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); if (sample_fmt && (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) { @@ -3235,54 +3267,6 @@ static int opt_timecode(void *optctx, const char *opt, const char *arg) return ret; } -static int opt_channel_layout(void *optctx, const char *opt, const char *arg) -{ - OptionsContext *o = optctx; - char layout_str[32]; - char *stream_str; - char *ac_str; - int ret, ac_str_size; - AVChannelLayout layout = { 0 }; - - ret = av_channel_layout_from_string(&layout, arg); - if (ret < 0) { -#if FF_API_OLD_CHANNEL_LAYOUT - uint64_t mask; - AV_NOWARN_DEPRECATED({ - mask = av_get_channel_layout(arg); - }) - if (!mask) { -#endif - av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg); - return AVERROR(EINVAL); -#if FF_API_OLD_CHANNEL_LAYOUT - } - av_log(NULL, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", - arg); - av_channel_layout_from_mask(&layout, mask); -#endif - } - - ret = opt_default_new(o, opt, arg); - if (ret < 0) - return ret; - - /* set 'ac' option based on channel layout */ - snprintf(layout_str, sizeof(layout_str), "%d", layout.nb_channels); - stream_str = strchr(opt, ':'); - ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0); - ac_str = av_mallocz(ac_str_size); - if (!ac_str) - return AVERROR(ENOMEM); - av_strlcpy(ac_str, "ac", 3); - if (stream_str) - av_strlcat(ac_str, stream_str, ac_str_size); - ret = parse_option(o, ac_str, layout_str, options); - av_free(ac_str); - - return ret; -} - static int opt_audio_qscale(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; @@ -3827,8 +3811,8 @@ const OptionDef options[] = { { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(sample_fmts) }, "set sample format", "format" }, - { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE | - OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout }, + { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC | + OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) }, "set channel layout", "layout" }, { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters }, "set audio filters", "filter_graph" },