* [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param
@ 2024-05-18 16:11 Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-18 16:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
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 <cus@passwd.hu>
---
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');
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 2/5] doc/ffmpeg: document -channel_layout/ch_layout options
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
@ 2024-05-18 16:11 ` Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 3/5] fftools: move check_avoptions and remove_avoptions to cmdutils Marton Balint
` (4 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-18 16:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Signed-off-by: Marton Balint <cus@passwd.hu>
---
doc/ffmpeg.texi | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 83db6584fd..9b490f523f 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1720,6 +1720,16 @@ This is an alias for @code{-filter:a}, see the @ref{filter_option,,-filter optio
@table @option
@item -atag @var{fourcc/tag} (@emph{output})
Force audio tag/fourcc. This is an alias for @code{-tag:a}.
+@item -ch_layout[:@var{stream_specifier}] @var{layout} (@emph{input/output,per-stream})
+@item -channel_layout[:@var{stream_specifier}] @var{layout} (@emph{input/output,per-stream})
+Set the audio channel layout. For output streams it is set by default to the
+input channel layout. For input streams it overrides the channel layout if the
+decoder allows it. When used without a stream specifier it also sets the input
+channel layout for audio grabbing devices and raw demuxers and is mapped to the
+corresponding demuxer options.
+
+Note that specifying a channel layout also sets the channel count and this
+option has precedence over the @code{-ac} option.
@item -guess_layout_max @var{channels} (@emph{input,per-stream})
If some input channel layout is not known, try to guess only if it
corresponds to at most the specified number of channels. For example, 2
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 3/5] fftools: move check_avoptions and remove_avoptions to cmdutils
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
@ 2024-05-18 16:11 ` Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 4/5] fftools/ffplay: use cmdutils code for checking remaining avoptions Marton Balint
` (3 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-18 16:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Signed-off-by: Marton Balint <cus@passwd.hu>
---
fftools/cmdutils.c | 20 ++++++++++++++++++++
fftools/cmdutils.h | 6 ++++++
fftools/ffmpeg.c | 20 --------------------
fftools/ffmpeg.h | 3 ---
4 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index a8f5c6d89b..8953b21e23 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1146,3 +1146,23 @@ char *file_read(const char *filename)
return NULL;
return str;
}
+
+void remove_avoptions(AVDictionary **a, AVDictionary *b)
+{
+ const AVDictionaryEntry *t = NULL;
+
+ while ((t = av_dict_iterate(b, t))) {
+ av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE);
+ }
+}
+
+int check_avoptions(AVDictionary *m)
+{
+ const AVDictionaryEntry *t;
+ if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
+ return AVERROR_OPTION_NOT_FOUND;
+ }
+
+ return 0;
+}
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index d0c773663b..2125f791d0 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -483,4 +483,10 @@ double get_rotation(const int32_t *displaymatrix);
/* read file contents into a string */
char *file_read(const char *filename);
+/* Remove keys in dictionary b from dictionary a */
+void remove_avoptions(AVDictionary **a, AVDictionary *b);
+
+/* Check if any keys exist in dictionary m */
+int check_avoptions(AVDictionary *m);
+
#endif /* FFTOOLS_CMDUTILS_H */
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1f50ed6805..88ce3007e8 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -473,26 +473,6 @@ const FrameData *packet_data_c(AVPacket *pkt)
return ret < 0 ? NULL : (const FrameData*)pkt->opaque_ref->data;
}
-void remove_avoptions(AVDictionary **a, AVDictionary *b)
-{
- const AVDictionaryEntry *t = NULL;
-
- while ((t = av_dict_iterate(b, t))) {
- av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE);
- }
-}
-
-int check_avoptions(AVDictionary *m)
-{
- const AVDictionaryEntry *t;
- if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
- av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
- return AVERROR_OPTION_NOT_FOUND;
- }
-
- return 0;
-}
-
void update_benchmark(const char *fmt, ...)
{
if (do_benchmark_all) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 885a7c0c10..fe75706afd 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -710,9 +710,6 @@ void term_exit(void);
void show_usage(void);
-void remove_avoptions(AVDictionary **a, AVDictionary *b);
-int check_avoptions(AVDictionary *m);
-
int assert_file_overwrite(const char *filename);
AVDictionary *strip_specifiers(const AVDictionary *dict);
int find_codec(void *logctx, const char *name,
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 4/5] fftools/ffplay: use cmdutils code for checking remaining avoptions
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 3/5] fftools: move check_avoptions and remove_avoptions to cmdutils Marton Balint
@ 2024-05-18 16:11 ` Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 5/5] fftools/ffplay: allow unused format options which are also codec options Marton Balint
` (2 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-18 16:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Signed-off-by: Marton Balint <cus@passwd.hu>
---
fftools/ffplay.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index b9d11eecee..ff48fa5f8c 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2626,7 +2626,6 @@ static int stream_component_open(VideoState *is, int stream_index)
const AVCodec *codec;
const char *forced_codec_name = NULL;
AVDictionary *opts = NULL;
- const AVDictionaryEntry *t = NULL;
int sample_rate;
AVChannelLayout ch_layout = { 0 };
int ret = 0;
@@ -2694,11 +2693,9 @@ static int stream_component_open(VideoState *is, int stream_index)
if ((ret = avcodec_open2(avctx, codec, &opts)) < 0) {
goto fail;
}
- if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
- av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
- ret = AVERROR_OPTION_NOT_FOUND;
+ ret = check_avoptions(opts);
+ if (ret < 0)
goto fail;
- }
is->eof = 0;
ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
@@ -2862,11 +2859,9 @@ static int read_thread(void *arg)
if (scan_all_pmts_set)
av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
- if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
- av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
- ret = AVERROR_OPTION_NOT_FOUND;
+ ret = check_avoptions(format_opts);
+ if (ret < 0)
goto fail;
- }
is->ic = ic;
if (genpts)
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH 5/5] fftools/ffplay: allow unused format options which are also codec options
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
` (2 preceding siblings ...)
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 4/5] fftools/ffplay: use cmdutils code for checking remaining avoptions Marton Balint
@ 2024-05-18 16:11 ` Marton Balint
2024-05-18 21:20 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Michael Niedermayer
2024-05-27 7:51 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Anton Khirnov
5 siblings, 0 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-18 16:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Same as it is handled in ffmpeg, allows using -ch_layout codec option.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
fftools/ffplay.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index ff48fa5f8c..1d0511b254 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2858,6 +2858,7 @@ static int read_thread(void *arg)
}
if (scan_all_pmts_set)
av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
+ remove_avoptions(&format_opts, codec_opts);
ret = check_avoptions(format_opts);
if (ret < 0)
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
` (3 preceding siblings ...)
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 5/5] fftools/ffplay: allow unused format options which are also codec options Marton Balint
@ 2024-05-18 21:20 ` Michael Niedermayer
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-27 7:51 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Anton Khirnov
5 siblings, 1 reply; 13+ messages in thread
From: Michael Niedermayer @ 2024-05-18 21:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1682 bytes --]
On Sat, May 18, 2024 at 06:11:12PM +0200, Marton Balint wrote:
> 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 <cus@passwd.hu>
breaks:
./ffmpeg -f u8 -ar 8000 -ac 1 -i /dev/zero -acodec aac -y -t 1 -b:a 48k /tmp/aac.nut
[aac @ 0x55d4ed264800] Unsupported channel layout "1 channels"
[aac @ 0x55d4ed264800] Qavg: nan
[aost#0:0/aac @ 0x55d4ed24d800] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
[af#0:0 @ 0x55d4ed264cc0] Error sending frames to consumers: Invalid argument
[af#0:0 @ 0x55d4ed264cc0] Task finished with error code: -22 (Invalid argument)
[af#0:0 @ 0x55d4ed264cc0] Terminating thread with return code -22 (Invalid argument)
[aost#0:0/aac @ 0x55d4ed24d800] Could not open encoder before EOF
[aost#0:0/aac @ 0x55d4ed24d800] Task finished with error code: -22 (Invalid argument)
[aost#0:0/aac @ 0x55d4ed24d800] Terminating thread with return code -22 (Invalid argument)
[out#0/nut @ 0x55d4ed254040] Nothing was written into output file, because at least one of its streams received no packets.
size= 0KiB time=N/A bitrate=N/A speed=N/A
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout
2024-05-18 21:20 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Michael Niedermayer
@ 2024-05-19 19:52 ` Marton Balint
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-19 19:52 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
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.
This used to work via the respective AVCodecContext option, but since
639c2f00497257cb60ecaeeac1aacfa80df3be06 it no longer gets passed to the
decoders. It is actually better if we set it manually, instead of using the
codec option because that way we can also override it on the stream level, so
it will also work for stream copy or bitstream filtering.
We don't allow changing the number of channels, because that can cause
unexpected results. We disable layout guessing, if a channel layout is
specified.
Fixes ticket #11016.
Signed-off-by: Marton Balint <cus@passwd.hu>
---
fftools/ffmpeg_demux.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index cba63dab5f..1ca8d804ae 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1386,9 +1386,30 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
break;
case AVMEDIA_TYPE_AUDIO: {
- int guess_layout_max = INT_MAX;
- MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
- guess_input_channel_layout(ist, par, guess_layout_max);
+ char *ch_layout_str = NULL;
+ MATCH_PER_STREAM_OPT(audio_ch_layouts, str, ch_layout_str, ic, st);
+ if (ch_layout_str) {
+ AVChannelLayout ch_layout;
+ ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
+ if (ret < 0) {
+ av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
+ return ret;
+ }
+ if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
+ av_channel_layout_uninit(&par->ch_layout);
+ par->ch_layout = ch_layout;
+ } else {
+ av_log(ist, AV_LOG_ERROR,
+ "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
+ ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
+ av_channel_layout_uninit(&ch_layout);
+ return AVERROR(EINVAL);
+ }
+ } else {
+ int guess_layout_max = INT_MAX;
+ MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
+ guess_input_channel_layout(ist, par, guess_layout_max);
+ }
break;
}
case AVMEDIA_TYPE_DATA:
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/5] doc/ffmpeg: document -channel_layout/ch_layout options
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
@ 2024-05-19 19:52 ` Marton Balint
2024-05-25 16:57 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-27 8:01 ` Anton Khirnov
2 siblings, 0 replies; 13+ messages in thread
From: Marton Balint @ 2024-05-19 19:52 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Marton Balint
Signed-off-by: Marton Balint <cus@passwd.hu>
---
doc/ffmpeg.texi | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index da37e3ad37..f25f6192eb 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1719,12 +1719,21 @@ This is an alias for @code{-filter:a}, see the @ref{filter_option,,-filter optio
@table @option
@item -atag @var{fourcc/tag} (@emph{output})
Force audio tag/fourcc. This is an alias for @code{-tag:a}.
+@item -ch_layout[:@var{stream_specifier}] @var{layout} (@emph{input/output,per-stream})
+Alias for @code{-channel_layout}.
+@item -channel_layout[:@var{stream_specifier}] @var{layout} (@emph{input/output,per-stream})
+Set the audio channel layout. For output streams it is set by default to the
+input channel layout. For input streams it overrides the channel layout of the
+input. Not all decoders respect the overridden channel layout. This option
+also sets the channel layout for audio grabbing devices and raw demuxers
+and is mapped to the corresponding demuxer option.
@item -guess_layout_max @var{channels} (@emph{input,per-stream})
If some input channel layout is not known, try to guess only if it
corresponds to at most the specified number of channels. For example, 2
tells to @command{ffmpeg} to recognize 1 channel as mono and 2 channels as
stereo but not 6 channels as 5.1. The default is to always try to guess. Use
-0 to disable all guessing.
+0 to disable all guessing. Using the @code{-channel_layout} option to
+explicitly specify an input layout also disables guessing.
@end table
@section Subtitle options
--
2.35.3
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
@ 2024-05-25 16:57 ` Marton Balint
2024-05-25 19:20 ` Anton Khirnov
2024-05-27 8:01 ` Anton Khirnov
2 siblings, 1 reply; 13+ messages in thread
From: Marton Balint @ 2024-05-25 16:57 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 19 May 2024, Marton Balint wrote:
> 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.
>
> This used to work via the respective AVCodecContext option, but since
> 639c2f00497257cb60ecaeeac1aacfa80df3be06 it no longer gets passed to the
> decoders. It is actually better if we set it manually, instead of using the
> codec option because that way we can also override it on the stream level, so
> it will also work for stream copy or bitstream filtering.
>
> We don't allow changing the number of channels, because that can cause
> unexpected results. We disable layout guessing, if a channel layout is
> specified.
>
> Fixes ticket #11016.
Will apply the series.
Regards,
Marton
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> fftools/ffmpeg_demux.c | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index cba63dab5f..1ca8d804ae 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -1386,9 +1386,30 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
>
> break;
> case AVMEDIA_TYPE_AUDIO: {
> - int guess_layout_max = INT_MAX;
> - MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
> - guess_input_channel_layout(ist, par, guess_layout_max);
> + char *ch_layout_str = NULL;
> + MATCH_PER_STREAM_OPT(audio_ch_layouts, str, ch_layout_str, ic, st);
> + if (ch_layout_str) {
> + AVChannelLayout ch_layout;
> + ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
> + if (ret < 0) {
> + av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
> + return ret;
> + }
> + if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
> + av_channel_layout_uninit(&par->ch_layout);
> + par->ch_layout = ch_layout;
> + } else {
> + av_log(ist, AV_LOG_ERROR,
> + "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
> + ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
> + av_channel_layout_uninit(&ch_layout);
> + return AVERROR(EINVAL);
> + }
> + } else {
> + int guess_layout_max = INT_MAX;
> + MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
> + guess_input_channel_layout(ist, par, guess_layout_max);
> + }
> break;
> }
> case AVMEDIA_TYPE_DATA:
> --
> 2.35.3
>
> _______________________________________________
> 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".
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout
2024-05-25 16:57 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
@ 2024-05-25 19:20 ` Anton Khirnov
0 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2024-05-25 19:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Marton Balint (2024-05-25 18:57:32)
>
>
> On Sun, 19 May 2024, Marton Balint wrote:
>
> > 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.
> >
> > This used to work via the respective AVCodecContext option, but since
> > 639c2f00497257cb60ecaeeac1aacfa80df3be06 it no longer gets passed to the
> > decoders. It is actually better if we set it manually, instead of using the
> > codec option because that way we can also override it on the stream level, so
> > it will also work for stream copy or bitstream filtering.
> >
> > We don't allow changing the number of channels, because that can cause
> > unexpected results. We disable layout guessing, if a channel layout is
> > specified.
> >
> > Fixes ticket #11016.
>
> Will apply the series.
Could you please wait a few days?
I'm just freshly back from a vacation and didn't have time to look at
this in detail yet.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
` (4 preceding siblings ...)
2024-05-18 21:20 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Michael Niedermayer
@ 2024-05-27 7:51 ` Anton Khirnov
2024-05-27 7:57 ` Anton Khirnov
5 siblings, 1 reply; 13+ messages in thread
From: Anton Khirnov @ 2024-05-27 7:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Marton Balint
Quoting Marton Balint (2024-05-18 18:11:12)
> 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);
I don't like modifying OptionsContext in its consumers (it's const for a
reason), and it's probably not even necessary - if the semantics of the
option is "override demuxer-reported channel layout", then you can just
override the demuxer-reported channel layout (similarly to how
guess_input_channel_layout() does it) and it will be communicated to the
decoder automagically.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param
2024-05-27 7:51 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Anton Khirnov
@ 2024-05-27 7:57 ` Anton Khirnov
0 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2024-05-27 7:57 UTC (permalink / raw)
To: FFmpeg development discussions and patches, Marton Balint
Quoting Anton Khirnov (2024-05-27 09:51:49)
> I don't like modifying OptionsContext in its consumers (it's const for a
> reason), and it's probably not even necessary - if the semantics of the
> option is "override demuxer-reported channel layout", then you can just
> override the demuxer-reported channel layout (similarly to how
> guess_input_channel_layout() does it) and it will be communicated to the
> decoder automagically.
I see that's pretty much what you did in v2, so disregard the above
email.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
2024-05-25 16:57 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
@ 2024-05-27 8:01 ` Anton Khirnov
2 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2024-05-27 8:01 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Marton Balint
Quoting Marton Balint (2024-05-19 21:52:57)
> 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.
>
> This used to work via the respective AVCodecContext option, but since
> 639c2f00497257cb60ecaeeac1aacfa80df3be06 it no longer gets passed to the
> decoders. It is actually better if we set it manually, instead of using the
> codec option because that way we can also override it on the stream level, so
> it will also work for stream copy or bitstream filtering.
>
> We don't allow changing the number of channels, because that can cause
> unexpected results. We disable layout guessing, if a channel layout is
> specified.
>
> Fixes ticket #11016.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> fftools/ffmpeg_demux.c | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
Looks ok
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-05-27 8:01 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-18 16:11 [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 3/5] fftools: move check_avoptions and remove_avoptions to cmdutils Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 4/5] fftools/ffplay: use cmdutils code for checking remaining avoptions Marton Balint
2024-05-18 16:11 ` [FFmpeg-devel] [PATCH 5/5] fftools/ffplay: allow unused format options which are also codec options Marton Balint
2024-05-18 21:20 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Michael Niedermayer
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-19 19:52 ` [FFmpeg-devel] [PATCH v2 2/5] doc/ffmpeg: document -channel_layout/ch_layout options Marton Balint
2024-05-25 16:57 ` [FFmpeg-devel] [PATCH v2 1/5] fftools/ffmpeg_demux: honor -ch_layout options for overriding input stream channel layout Marton Balint
2024-05-25 19:20 ` Anton Khirnov
2024-05-27 8:01 ` Anton Khirnov
2024-05-27 7:51 ` [FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param Anton Khirnov
2024-05-27 7:57 ` Anton Khirnov
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