From patchwork Thu Jan 13 02:09:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33537 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp47294iog; Wed, 12 Jan 2022 18:53:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTRq7K1EO9Ylgt86H79kqJBVL5eXu+je2bprv7xZZfD+L7xOklIvajLBBmAZBk6VgXvMSe X-Received: by 2002:a05:6402:2552:: with SMTP id l18mr2353595edb.124.1642042394218; Wed, 12 Jan 2022 18:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042394; cv=none; d=google.com; s=arc-20160816; b=MIPFD/2cwK2r0FBsHzksm9a38ZcC70QKL4RwenND792UjFgXX12j/pql0RRNoVV5t4 TVSaCXlRiK+gP1YzekKCczQDRZIyOf9MNOgFoU2ifLhJxZ/iUtpNv6rqKgH7o9zcOYqy 62DQ+1K46YyJaZ1RNCS2q8HsDA3SEnt/mFljFx4yieJJybGybenuUEdq7bO6u20lmCWU Jm2SG0FLOynTMa9g5Ja5fdWoito7w8n8FClNhmxC1FXvnABL1ZRzFKeUE77ow4L7pJ9f nonzbl9u4xn+71RNnCJ7dBANlkEpp2Q3pCvHx3WXe4/iOVyL5HCiJzMd0ySpgHeiMkmr QlNA== 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=kPaFb2J9AeMDeYfOniCqvCKllLEfb99oBXyMCY5gJQQ=; b=VoYD/rVgIeyMR5Mw2CNkpLGDGC6UT/o0ZPZCbagxPP0VCzeqQZvfemRikJ0m82utUh bnWueOvBB9SFTRJ8lPKM7PjS70wRjK4h8gu5Cf9ZBNcVgF9uia4js1rLyFxUrgVBBRfq s6y4pqQ+UQ9JvRDQWl9ZCjC8YeJCwFnYyTNGI7uJAv3492UBrfI8zkisYpiLrNtUjQDi uB7OjmNbeEE5wUJkTsR7JRhpx7esnrapDQmFzK5n4elDxTrCgAwTGEU8dE6yIclLJfwN R6jN7CNQWWAPpj70m1Ie9VOld58LzXK2iHg13X6gSwinlIfRg84DKZKAH7K7lqhPUABx L/FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=htTRd66B; 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 w11si998815edd.387.2022.01.12.18.53.13; Wed, 12 Jan 2022 18:53:14 -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=htTRd66B; 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 7C93268BAB1; Thu, 13 Jan 2022 04:09:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74D4668BA88 for ; Thu, 13 Jan 2022 04:09:39 +0200 (EET) Received: by mail-qv1-f51.google.com with SMTP id iw1so5183488qvb.1 for ; Wed, 12 Jan 2022 18:09:39 -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=Q3QgIM1lxU2xQ9U6po77XNDjH0RlDmpeirh+RD+874k=; b=htTRd66BDfJaOGVacZUwoTWf6g6WxaphgsF3KCTiUzlZaI4uAh37eYdcSuDR1oWz0y NKE8o83/V2HLh61mdKvnNTFq1uBwB96S4yvXlYKkPT/YhnDKm4s7JroMeLRMFrGQY4Gi M2ctpzUXPCihH2DPiDN+qqkp3rFuvMlC967AS/5U97TQJnTrER20tJbMgZa2ZQecRiit I9gaN+Kv5b9i5gtvh9qgrQJInPfVSevZC7i1crw8Qo/pHyqBpS7hTVam57j+5GgNkmo9 L0Xp/fIpkzIcaODWXgFN/qVw/7NABCubPx0Tnm6TujVe1vfKL0I+7rojekiuFErrdSS4 qYVA== 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=Q3QgIM1lxU2xQ9U6po77XNDjH0RlDmpeirh+RD+874k=; b=mHWOi+VH9SIUhhijU7woaaBAbVYgQa+gHT8eBW57MCPjATcnTaTF9wKj8WpDS6QKhb Ze9wtIGgdrzJIfEOd8Ll4VRvt+x/90EicWYrZgMS3A3qLmTFs+Iu4CVVEEpsuyDfGZ2F JegxkqNheSgIL1DMy+wG4YmZluVbbqzjWZdPhruRnpBIz8Hiravl1194sJHcD2ZlZxaV B5XhfL2/cRIOege+owBdBNIhCDFPVKYOISVW2qtcvuWTXnUkQCwJWe48D4Z9dHth6VB0 9cwJga0ORiLUquKg1AjGkeXe2UOZPQJ8xOVN04mC/4A703IsP9365lOWcFGPGWyFBQpI EHvw== X-Gm-Message-State: AOAM533W0iY3gRA66Jzghcs2Xd+hiaBKakv4ScHl1fuxBWfYP/cgqvQv 20meKeaXMQQHbVZNy11LX8krNGVjQlA= X-Received: by 2002:ad4:4ee6:: with SMTP id dv6mr2066970qvb.77.1642039777767; Wed, 12 Jan 2022 18:09:37 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id u6sm1068031qko.83.2022.01.12.18.09.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:09:37 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:09:09 -0300 Message-Id: <20220113020913.870-8-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 277/281] 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: VW+SxPzhWWRD 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 | 52 ++++++++++++++++++++++------- fftools/ffmpeg_opt.c | 62 ++++++++++++++++++++++++++++++----- tests/fate/aac.mak | 2 +- tests/fate/lavf-container.mak | 2 +- 8 files changed, 155 insertions(+), 67 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4b50e15eef..55cdbfb7a7 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 50eed9b13a..274d2e5b14 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 5d134b025f..22d6309f2a 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; @@ -3316,8 +3326,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 1f6cba2c04..b096196135 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -153,8 +153,29 @@ 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) +{ + AVBPrint bp; + + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); + if (av_channel_layout_check(&ofilter->ch_layout)) { + av_channel_layout_describe_bprint(&ofilter->ch_layout, &bp); + av_bprintf(bprint, "channel_layouts=%s", bp.str); + } else if (ofilter->ch_layouts) { + const AVChannelLayout *p; + + av_bprintf(bprint, "channel_layouts="); + for (p = ofilter->ch_layouts; p->nb_channels; p++) { + av_channel_layout_describe_bprint(p, &bp); + av_bprintf(bprint, "%s|", bp.str); + } + if (bprint->len > 0) + bprint->str[--bprint->len] = '\0'; + } else + return; + av_bprint_finalize(&bp, NULL); + av_bprint_chars(bprint, ':', 1); +} int init_simple_filtergraph(InputStream *ist, OutputStream *ost) { @@ -541,9 +562,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 +575,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); @@ -832,11 +855,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); @@ -1084,7 +1107,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; @@ -1148,6 +1174,7 @@ fail: int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) { AVFrameSideData *sd; + int ret; av_buffer_unref(&ifilter->hw_frames_ctx); @@ -1158,8 +1185,9 @@ 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; + ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout); + if (ret < 0) + return ret; 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/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"