summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_opt.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-09-02 21:04:30 -0300
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:46 -0300
commit987763ac35d3db8beb77e7c5e8426e1b265b2f95 (patch)
treec9b4a68ff26bc4d8c7c9177e4e0662842079825c /fftools/ffmpeg_opt.c
parent53d60aafaf2649660bea6f1558dd54d50f6cf636 (diff)
ffmpeg: convert to new channel layout-API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'fftools/ffmpeg_opt.c')
-rw-r--r--fftools/ffmpeg_opt.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f983c74a66..70e6502f22 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -507,7 +507,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
/* allow trailing ? to map_channel */
if (allow_unused = strchr(mapchan, '?'))
*allow_unused = 0;
- if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
+ if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
if (allow_unused) {
av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
@@ -1945,9 +1945,14 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
if (!ost->stream_copy) {
+ int channels = 0;
char *sample_fmt = NULL;
- MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
+ MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
+ if (channels) {
+ audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ audio_enc->ch_layout.nb_channels = channels;
+ }
MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
if (sample_fmt &&
@@ -2367,7 +2372,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
for (i = 0; i < ifile->nb_streams; i++) {
int score;
ist = input_streams[ifile->ist_index + i];
- score = ist->st->codecpar->channels
+ score = ist->st->codecpar->ch_layout.nb_channels
+ 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
+ 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
if (ist->user_set_discard == AVDISCARD_ALL)
@@ -2644,10 +2649,10 @@ loop_end:
} else {
f->sample_rates = ost->enc->supported_samplerates;
}
- if (ost->enc_ctx->channels) {
- f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
- } else {
- f->channel_layouts = ost->enc->channel_layouts;
+ if (ost->enc_ctx->ch_layout.nb_channels) {
+ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
+ } else if (ost->enc->ch_layouts) {
+ f->ch_layouts = ost->enc->ch_layouts;
}
break;
}
@@ -3236,22 +3241,34 @@ static int opt_channel_layout(void *optctx, 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;
+ int ret, ac_str_size;
+ AVChannelLayout layout = { 0 };
- layout = av_get_channel_layout(arg);
- if (!layout) {
+ 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
}
- snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
- ret = opt_default_new(o, opt, layout_str);
+
+ ret = opt_default_new(o, opt, arg);
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);
+ 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);