From patchwork Wed Dec 8 01:06:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32133 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047792iog; Tue, 7 Dec 2021 17:12:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxYl899RE00XTvACQ3kuXN/hxjuPNm4SJvr8bihVrfB3eqPyp9Vx7q0pWDpAmOrao2ZCDa X-Received: by 2002:a17:906:ad89:: with SMTP id la9mr3546933ejb.178.1638925961156; Tue, 07 Dec 2021 17:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925961; cv=none; d=google.com; s=arc-20160816; b=QxLR0Anf0mdu3+zR8XKLG1uekcjv/T3vseGcBXSrIkrG6V4CCqn5dsLNDs+AGec+4B g8hSvPZtlYZomEjfRbYP/EI8d1A3hGLNQnZu9yQrOsEbFGIfoA0CzTkbmpWFIYtTMvuw FH//z1fm0ntUqv/O3+XhaPlR7JQas9Guix2A5y6ai4RG1eeYjgjTjF0Rvy4TpRgrIz3r 9eFdComcgcCa4PFqgh3Aur22Kbl+79yZA/heqr1AD/0RBovdcrvnhJQzDzURB0yqLtEv 7eRAlknLwagLzoVNM/Q3KOfdh/ATYz6uQ2CnTPguSJvEDWVdbldVOlSCijDDMOo2HyTl OFsA== 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=gvGobYR8bjsqFwQbmKGE0AT9Gq/AK77crHMiccnFmXQ=; b=QIbaN6bM91kePVJ0qHuHSuj86qKONtQpPGTguaz0rfSWS/St+LG5UQc46nddUcbGSj l+mEn8+Uzq6FnXQm7y5opJfeKjsDuN8ZZ7mjpvug+6/aOjjvLMkUdTopq1N+LonFquhi 9OrouXvMX+BRocqXW+Q6M4BvPAau8bF+xLAU7tJwq7oeeS6/j2peuUSH78tPaR3T7CMk u2fziVfvXyBdpjnAEg1wC/YpMGrA0oIJeWscNyt4xGlJ+ClLkGMvsQsmwYIkczxUbNGs W2mBbGJc8cssP17sljvjYypPl6naLZAQ55gmw/IMHv07wT+TEN7evxEZBG/BWg4a7qWz zkfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="ktUW/WlI"; 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 y19si2922372edc.31.2021.12.07.17.12.40; Tue, 07 Dec 2021 17:12:41 -0800 (PST) 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="ktUW/WlI"; 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 4049C68AF8A; Wed, 8 Dec 2021 03:08:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CE6B68AF5D for ; Wed, 8 Dec 2021 03:08:07 +0200 (EET) Received: by mail-ua1-f44.google.com with SMTP id i6so1904333uae.6 for ; Tue, 07 Dec 2021 17:08:07 -0800 (PST) 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=asbF1PVUyNV9/PupJmltUYpUGyMUJyg+qZvI0Qvf8zQ=; b=ktUW/WlISKCAAYX20IwIXb0z6/SuBAAkvO8QT3EwpvzVPkjozNd6nkfCvuaLto47sb 1X8XxQcGZJHFQplKxIAUDLX7Q2v4DJ5On5U9L33oyHS8pwQjmaJrrNEGq/yH+KWqz1TQ 7ZkmeOMWWUGwnSajOCCJkbKHBFc68ppLwy3pU84OPUwOGJw8zAeDhNM+mPiSx8PdmVCz wIAckY6m0sVnbCuakWDDcGmNDBjqXs/8GovtE1g4r1rFzgPcBgtp85o+QDW6HPqxmxQT OARlfvbzu/pECpIwThM7c/uesaZSjP8cR5uiC3S8MIHwZOE8X9u5nc8ZbC3Ndsf61kYG 2uYw== 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=asbF1PVUyNV9/PupJmltUYpUGyMUJyg+qZvI0Qvf8zQ=; b=x8UOUmzD2Xk6Z7IyUI0J3WVfdLruxuk0EeXGndf2SUwKsK/clErGVLoLPBK8/QSBDy Khb50HMclm0JMOC4tTLyWJWgFaFRhSSxYmCxAzLW1oTi3n5mLClDp45CpWxfOk0kKgs9 XPt75pJRmbajKTYyZwVTvSXmVzR1RtYFtNaOmHPoI2NEg1g8NDqthOXRFmZNKUYvlqid 3p2EwZtcqNT1yF6W9SwePyaR4si3vYJlr9MPkRRLa8DIP46bHof8CpGK70DtiauC+vAY cxkhOTxV8tZyV/ABjJhA0PKZbOQBslUD5tSk4a8DHOJYjbOhtSe+c7RVlWHS/Djx8yta 36qw== X-Gm-Message-State: AOAM5312Kxio8Cxw81At2Bc61r1latQ2DZwuFq1tB8tFFxdLyxMDmSlF bI9Ra+b4EUVWBj7E5VL6kdU6921xkgsP3JSX X-Received: by 2002:ab0:7619:: with SMTP id o25mr4167968uap.49.1638925685142; Tue, 07 Dec 2021 17:08:05 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.08.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:08:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:45 -0300 Message-Id: <20211208010649.381-30-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 275/279] ffmpeg: convert to new channel layout-API 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: 3kAPYa16GO2g Signed-off-by: James Almer --- fftools/cmdutils.c | 42 +++++++++++++++--------- fftools/cmdutils.h | 8 ----- fftools/ffmpeg.c | 47 ++++++++++++++++---------- fftools/ffmpeg.h | 7 ++-- fftools/ffmpeg_filter.c | 43 +++++++++++++++++------- fftools/ffmpeg_opt.c | 62 ++++++++++++++++++++++++++++++----- tests/fate/aac.mak | 2 +- tests/fate/cover-art.mak | 2 +- tests/fate/lavf-container.mak | 2 +- 9 files changed, 147 insertions(+), 68 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 3c8e5a82cd..223015db8b 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1470,8 +1470,19 @@ static void print_codec(const AVCodec *c) GET_SAMPLE_RATE_NAME); PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats", AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME); - PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts", - 0, GET_CH_LAYOUT_DESC); + + if (c->ch_layouts) { + const AVChannelLayout *p = c->ch_layouts; + + printf(" Supported channel layouts:"); + while (p->nb_channels) { + char name[128]; + av_channel_layout_describe(p, name, sizeof(name)); + printf(" %s", name); + p++; + } + printf("\n"); + } if (c->priv_class) { show_help_children(c->priv_class, @@ -1784,29 +1795,30 @@ int show_pix_fmts(void *optctx, const char *opt, const char *arg) int show_layouts(void *optctx, const char *opt, const char *arg) { + const AVChannelLayout *ch_layout; + void *iter = NULL; + char buf[128], buf2[128]; int i = 0; - uint64_t layout, j; - const char *name, *descr; printf("Individual channels:\n" "NAME DESCRIPTION\n"); for (i = 0; i < 63; i++) { - name = av_get_channel_name((uint64_t)1 << i); - if (!name) + av_channel_name(buf, sizeof(buf), i); + if (!strcmp(buf, "?")) continue; - descr = av_get_channel_description((uint64_t)1 << i); - printf("%-14s %s\n", name, descr); + av_channel_description(buf2, sizeof(buf2), i); + printf("%-14s %s\n", buf, buf2); } printf("\nStandard channel layouts:\n" "NAME DECOMPOSITION\n"); - for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) { - if (name) { - printf("%-14s ", name); - for (j = 1; j; j <<= 1) - if ((layout & j)) - printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j)); + while (ch_layout = av_channel_layout_standard(&iter)) { + av_channel_layout_describe(ch_layout, buf, sizeof(buf)); + av_channel_name(buf2, sizeof(buf2), i); + printf("%-14s ", buf); + for (i = 0; i < 63; i++) + if (av_channel_layout_index_from_channel(ch_layout, i) >= 0) + printf("%s%s", i ? "+" : "", buf2); printf("\n"); - } } return 0; } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 82cda208be..fce2da288b 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -663,14 +663,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); char name[16];\ snprintf(name, sizeof(name), "%d", rate); -#define GET_CH_LAYOUT_NAME(ch_layout)\ - char name[16];\ - snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout); - -#define GET_CH_LAYOUT_DESC(ch_layout)\ - char name[128];\ - av_get_channel_layout_string(name, sizeof(name), 0, ch_layout); - double get_rotation(int32_t *displaymatrix); #endif /* FFTOOLS_CMDUTILS_H */ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0f1834cdbe..6dc5a00356 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -555,6 +555,7 @@ static void ffmpeg_cleanup(int ret) avfilter_inout_free(&ofilter->out_tmp); av_freep(&ofilter->name); + av_channel_layout_uninit(&ofilter->ch_layout); av_freep(&fg->outputs[j]); } av_freep(&fg->outputs); @@ -1537,7 +1538,7 @@ static int reap_filters(int flush) break; case AVMEDIA_TYPE_AUDIO: if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - enc->channels != filtered_frame->channels) { + enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) { av_log(NULL, AV_LOG_ERROR, "Audio filter graph output is not normalized and encoder does not support parameter changes\n"); break; @@ -1883,17 +1884,22 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti print_final_stats(total_size); } -static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) +static int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par) { + int ret; + // We never got any input. Set a fake format, which will // come from libavformat. ifilter->format = par->format; ifilter->sample_rate = par->sample_rate; - ifilter->channels = par->channels; - ifilter->channel_layout = par->channel_layout; ifilter->width = par->width; ifilter->height = par->height; ifilter->sample_aspect_ratio = par->sample_aspect_ratio; + ret = av_channel_layout_copy(&ifilter->ch_layout, &par->ch_layout); + if (ret < 0) + return ret; + + return 0; } static void flush_encoders(void) @@ -1921,8 +1927,11 @@ static void flush_encoders(void) int x; for (x = 0; x < fg->nb_inputs; x++) { InputFilter *ifilter = fg->inputs[x]; - if (ifilter->format < 0) - ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ifilter->format < 0 && + ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error copying paramerets from input stream\n"); + exit_program(1); + } } if (!ifilter_has_all_input_formats(fg)) @@ -2098,16 +2107,15 @@ int guess_input_channel_layout(InputStream *ist) { AVCodecContext *dec = ist->dec_ctx; - if (!dec->channel_layout) { + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { char layout_name[256]; - if (dec->channels > ist->guess_layout_max) + if (dec->ch_layout.nb_channels > ist->guess_layout_max) return 0; - dec->channel_layout = av_get_default_channel_layout(dec->channels); - if (!dec->channel_layout) + av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels); + if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) return 0; - av_get_channel_layout_string(layout_name, sizeof(layout_name), - dec->channels, dec->channel_layout); + av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name)); av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream " "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name); } @@ -2160,8 +2168,7 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_ref switch (ifilter->ist->st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: need_reinit |= ifilter->sample_rate != frame->sample_rate || - ifilter->channels != frame->channels || - ifilter->channel_layout != frame->channel_layout; + av_channel_layout_compare(&ifilter->ch_layout, &frame->ch_layout); break; case AVMEDIA_TYPE_VIDEO: need_reinit |= ifilter->width != frame->width || @@ -2241,8 +2248,11 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts) return ret; } else { // the filtergraph was never configured - if (ifilter->format < 0) - ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ifilter->format < 0) { + ret = ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar); + if (ret < 0) + return ret; + } if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index); return AVERROR_INVALIDDATA; @@ -3318,8 +3328,9 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_AUDIO: enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter); enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter); - enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter); - enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter); + ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout); + if (ret < 0) + return ret; if (ost->bits_per_raw_sample) enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9b200b806a..75f6f9ef72 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -250,8 +250,7 @@ typedef struct InputFilter { AVRational sample_aspect_ratio; int sample_rate; - int channels; - uint64_t channel_layout; + AVChannelLayout ch_layout; AVBufferRef *hw_frames_ctx; int32_t *displaymatrix; @@ -274,12 +273,12 @@ typedef struct OutputFilter { AVRational frame_rate; int format; int sample_rate; - uint64_t channel_layout; + AVChannelLayout ch_layout; // those are only set if no format is specified and the encoder gives us multiple options // They point directly to the relevant lists of the encoder. const int *formats; - const uint64_t *channel_layouts; + const AVChannelLayout *ch_layouts; const int *sample_rates; } OutputFilter; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 501a0acd61..6d52713cd6 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -153,8 +153,23 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats, DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0, "%d", ) -DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0, - "0x%"PRIx64, ) +static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint) +{ + if (av_channel_layout_check(&ofilter->ch_layout) && ofilter->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) { + av_bprintf(bprint, "channel_layouts=0x%"PRIx64, ofilter->ch_layout.u.mask); + } else if (ofilter->ch_layouts) { + const AVChannelLayout *p; + + av_bprintf(bprint, "channel_layouts="); + for (p = ofilter->ch_layouts; p->nb_channels; p++) { + av_bprintf(bprint, "0x%"PRIx64 "|", p->u.mask); + } + if (bprint->len > 0) + bprint->str[--bprint->len] = '\0'; + } else + return; + av_bprint_chars(bprint, ':', 1); +} int init_simple_filtergraph(InputStream *ist, OutputStream *ost) { @@ -541,9 +556,11 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, } while (0) av_bprint_init(&args, 0, AV_BPRINT_SIZE_UNLIMITED); if (ost->audio_channels_mapped) { + AVChannelLayout mapped_layout = { 0 }; int i; - av_bprintf(&args, "0x%"PRIx64, - av_get_default_channel_layout(ost->audio_channels_mapped)); + av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped); + av_bprintf(&args, "0x%"PRIx64, mapped_layout.order == AV_CHANNEL_ORDER_NATIVE ? + mapped_layout.u.mask : 0); for (i = 0; i < ost->audio_channels_mapped; i++) if (ost->audio_channels_map[i] != -1) av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]); @@ -552,8 +569,8 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, av_bprint_clear(&args); } - if (codec->channels && !codec->channel_layout) - codec->channel_layout = av_get_default_channel_layout(codec->channels); + if (codec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&codec->ch_layout, codec->ch_layout.nb_channels); choose_sample_fmts(ofilter, &args); choose_sample_rates(ofilter, &args); @@ -840,11 +857,11 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, 1, ifilter->sample_rate, ifilter->sample_rate, av_get_sample_fmt_name(ifilter->format)); - if (ifilter->channel_layout) + if (av_channel_layout_check(&ifilter->ch_layout) && ifilter->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) av_bprintf(&args, ":channel_layout=0x%"PRIx64, - ifilter->channel_layout); + ifilter->ch_layout.u.mask); else - av_bprintf(&args, ":channels=%d", ifilter->channels); + av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, ist->file_index, ist->st->index); @@ -1092,7 +1109,10 @@ int configure_filtergraph(FilterGraph *fg) ofilter->height = av_buffersink_get_h(sink); ofilter->sample_rate = av_buffersink_get_sample_rate(sink); - ofilter->channel_layout = av_buffersink_get_channel_layout(sink); + av_channel_layout_uninit(&ofilter->ch_layout); + ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout); + if (ret < 0) + goto fail; } fg->reconfiguration = 1; @@ -1166,8 +1186,7 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) ifilter->sample_aspect_ratio = frame->sample_aspect_ratio; ifilter->sample_rate = frame->sample_rate; - ifilter->channels = frame->channels; - ifilter->channel_layout = frame->channel_layout; + ifilter->ch_layout = frame->ch_layout; av_freep(&ifilter->displaymatrix); sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 9c820ab73f..0eb2c779f2 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", @@ -1954,9 +1954,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 && @@ -2378,7 +2383,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) @@ -2651,10 +2656,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; } @@ -3237,6 +3242,41 @@ static int opt_timecode(void *optctx, const char *opt, const char *arg) return ret; } +static int opt_ch_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) { + av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg); + return AVERROR(EINVAL); + } + 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; +} + +#if FF_API_OLD_CHANNEL_LAYOUT static int opt_channel_layout(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; @@ -3272,6 +3312,7 @@ static int opt_channel_layout(void *optctx, const char *opt, const char *arg) return ret; } +#endif static int opt_audio_qscale(void *optctx, const char *opt, const char *arg) { @@ -3818,9 +3859,14 @@ 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" }, + { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE | + OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_ch_layout }, + "set channel layout", "layout" }, +#if FF_API_OLD_CHANNEL_LAYOUT { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout }, - "set channel layout", "layout" }, + "deprecated, use -ch_layout", "layout" }, +#endif { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters }, "set audio filters", "filter_graph" }, { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) }, diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak index 1743428f54..d8750b093a 100644 --- a/tests/fate/aac.mak +++ b/tests/fate/aac.mak @@ -237,7 +237,7 @@ fate-aac-latm_000000001180bc60: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_00000000 fate-aac-latm_000000001180bc60: REF = $(SAMPLES)/aac/latm_000000001180bc60.s16 FATE_AAC_LATM += fate-aac-latm_stereo_to_51 -fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -channel_layout 5.1 +fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -ch_layout 5.1 fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51_ref.s16 fate-aac-autobsf-adtstoasc: CMD = transcode "aac" $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \ diff --git a/tests/fate/cover-art.mak b/tests/fate/cover-art.mak index c2e3b1e7c1..49fe044a7b 100644 --- a/tests/fate/cover-art.mak +++ b/tests/fate/cover-art.mak @@ -55,7 +55,7 @@ FATE_COVER_ART_REMUX-$(call ALLYES, FILE_PROTOCOL MOV_DEMUXER OGG_DEMUXER \ FLAC_MUXER FLAC_DEMUXER FLAC_DECODER \ FRAMECRC_MUXER PIPE_PROTOCOL) \ += fate-cover-art-flac-remux -fate-cover-art-flac-remux: CMD = transcode mov $(TARGET_SAMPLES)/lossless-audio/inside.m4a flac "-map 0 -map 1:v -map 1:v -af channelmap=channel_layout=FL+FC,aresample -c:a flac -multi_dim_quant 1 -c:v:0 copy -metadata:s:v:0 comment=Illustration -metadata:s:v:0 title=OpenMusic -filter:v:1 scale -c:v:1 png -metadata:s:v:1 title=landscape -c:v:2 copy -filter:v:3 scale -metadata:s:v:2 title=portrait -c:v:3 bmp -metadata:s:v:3 comment=Conductor -c:v:4 copy -t 0.4" "-map 0 -map 0:a -c:a:0 copy -c:v copy" "" "-show_entries format_tags:stream_tags:stream_disposition=attached_pic:stream=index,codec_name" "-f ogg -i $(TARGET_SAMPLES)/cover_art/ogg_vorbiscomment_cover.opus" +fate-cover-art-flac-remux: CMD = transcode mov $(TARGET_SAMPLES)/lossless-audio/inside.m4a flac "-map 0 -map 1:v -map 1:v -af channelmap=channel_layout=FL|FC,aresample -c:a flac -multi_dim_quant 1 -c:v:0 copy -metadata:s:v:0 comment=Illustration -metadata:s:v:0 title=OpenMusic -filter:v:1 scale -c:v:1 png -metadata:s:v:1 title=landscape -c:v:2 copy -filter:v:3 scale -metadata:s:v:2 title=portrait -c:v:3 bmp -metadata:s:v:3 comment=Conductor -c:v:4 copy -t 0.4" "-map 0 -map 0:a -c:a:0 copy -c:v copy" "" "-show_entries format_tags:stream_tags:stream_disposition=attached_pic:stream=index,codec_name" "-f ogg -i $(TARGET_SAMPLES)/cover_art/ogg_vorbiscomment_cover.opus" FCA_TEMP-$(call ALLYES, RAWVIDEO_MUXER FILE_PROTOCOL) = $(FATE_COVER_ART-yes) FATE_COVER_ART = $(FCA_TEMP-yes) diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak index 9e0eed4851..446a0cfbe2 100644 --- a/tests/fate/lavf-container.mak +++ b/tests/fate/lavf-container.mak @@ -26,7 +26,7 @@ $(FATE_LAVF_CONTAINER): $(AREF) $(VREF) fate-lavf-asf: CMD = lavf_container "" "-c:a mp2 -ar 44100" "-r 25" fate-lavf-avi fate-lavf-nut: CMD = lavf_container "" "-c:a mp2 -ar 44100 -threads 1" -fate-lavf-dv: CMD = lavf_container "-ar 48000 -channel_layout stereo" "-r 25 -s pal" +fate-lavf-dv: CMD = lavf_container "-ar 48000 -ch_layout stereo" "-r 25 -s pal" fate-lavf-dv_pal: CMD = lavf_container_timecode_nodrop "-ar 48000 -r 25 -s pal -ac 2 -f dv" fate-lavf-dv_ntsc: CMD = lavf_container_timecode_drop "-ar 48000 -pix_fmt yuv411p -s ntsc -ac 2 -f dv" fate-lavf-flv fate-lavf-swf: CMD = lavf_container "" "-an"