From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 5/7 v2] ffmpeg: replace custom channel_layout code with an SpecifierOpt based one
Date: Sun, 20 Mar 2022 16:36:17 -0300
Message-ID: <20220320193619.51185-5-jamrial@gmail.com> (raw)
In-Reply-To: <20220320193619.51185-1-jamrial@gmail.com>
This is cleaner and allows fine tuning which stream the option is applied to.
Signed-off-by: James Almer <jamrial@gmail.com>
---
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" },
--
2.35.1
_______________________________________________
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".
next prev parent reply other threads:[~2022-03-20 19:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-20 19:36 [FFmpeg-devel] [PATCH 1/7] avformat/pcmdec: deprecate channels option James Almer
2022-03-20 19:36 ` [FFmpeg-devel] [PATCH 2/7 v2] avformat/pcmdec: add support to set channel layout in sln demuxer James Almer
2022-03-20 19:36 ` [FFmpeg-devel] [PATCH 3/7 v2] avformat/dfpwmdec: add support to set channel layout James Almer
2022-03-20 19:36 ` [FFmpeg-devel] [PATCH 4/7 v2] avformat/test/seek: set ch_layout instead of channels James Almer
2022-03-20 19:36 ` James Almer [this message]
2022-03-20 19:36 ` [FFmpeg-devel] [PATCH 6/7] ffmpeg: add a ch_layout option as an alias to channel_layout James Almer
2022-03-20 19:36 ` [FFmpeg-devel] [PATCH 7/7] ffmpeg: deprecate the ac option James Almer
2022-03-20 19:44 ` Nicolas George
2022-03-20 20:05 ` James Almer
2022-03-20 20:06 ` [FFmpeg-devel] [PATCH 7/7] ffmpeg: make the ac option set the demuxer's ch_layout AVOption James Almer
2022-03-20 20:09 ` Nicolas George
2022-03-20 20:15 ` James Almer
2022-03-21 21:12 ` Andreas Rheinhardt
2022-03-21 21:27 ` James Almer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220320193619.51185-5-jamrial@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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