diff options
author | Justin Ruggles | 2012-04-05 17:47:20 -0400 |
---|---|---|
committer | Justin Ruggles | 2012-04-10 11:30:01 -0400 |
commit | 95a8dac57b1bc21891387c554e0e8b872bef6103 (patch) | |
tree | 1f3c2136e4d8b4525a6afe0a2acd23fa9d9a2f66 /avconv.c | |
parent | a559d65c0711284fc63689991f69db01bcfbb140 (diff) |
avconv: parse channel layout string
This allows the user to use channel layout names instead of having to use the
channel mask values.
Diffstat (limited to 'avconv.c')
-rw-r--r-- | avconv.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -4377,6 +4377,41 @@ static void parse_cpuflags(int argc, char **argv, const OptionDef *options) opt_cpuflags("cpuflags", argv[idx + 1]); } +static int opt_channel_layout(OptionsContext *o, const char *opt, const char *arg) +{ + char layout_str[32]; + char *stream_str; + char *ac_str; + int ret, channels, ac_str_size; + uint64_t layout; + + layout = av_get_channel_layout(arg); + if (!layout) { + av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg); + return AVERROR(EINVAL); + } + snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout); + ret = opt_default(opt, layout_str); + if (ret < 0) + return ret; + + /* set 'ac' option based on channel layout */ + channels = av_get_channel_layout_nb_channels(layout); + snprintf(layout_str, sizeof(layout_str), "%d", 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; +} + #define OFFSET(x) offsetof(OptionsContext, x) static const OptionDef options[] = { /* main options */ @@ -4465,6 +4500,7 @@ static const OptionDef options[] = { { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" }, { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, // { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" }, + { "channel_layout", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_channel_layout}, "set channel layout", "layout" }, /* subtitle options */ { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" }, |