From patchwork Mon Mar 28 23:24:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 35039 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp626193pzb; Mon, 28 Mar 2022 16:27:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMAervD4WEON4JZQmonGHoghp0Ij9kS5Pj3SsBB11/ZsH3IhuzJAmEuK90cEC4a5TmQI2r X-Received: by 2002:a17:906:4313:b0:6b8:b3e5:a46 with SMTP id j19-20020a170906431300b006b8b3e50a46mr29990975ejm.417.1648510020850; Mon, 28 Mar 2022 16:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648510020; cv=none; d=google.com; s=arc-20160816; b=gGACNx1Urw9SP8NkVfXjmiiQ7gt/i2saWUsZBgr8y8qGP2iIiGrRPe16GJSYGV2RIm qyEDOIrhlOcDKV1uCBR74YAptdtbtFiyJ0BPtqCAf9gFLV19P59uy+FiSzGrw5tMF166 LfQKDVmh1jrZP0RoaChRP4tNl3+sg7nk/BcA2zirzLF5wW+ea7Oxj5k3brjufGHfju6q yZ6fF2n5fa9K/liufliJr0xDhxlBOE0AD3QFhZHyaqS40GTuPtlq2mjngFpf/GX+G/mm 9BOLyV2xo/p7rANYiFfZfU+zYzqc+77YZ2WEtDVJweHhpLDCkCvGF/rWOSvfyeOn3b6V 6FFA== 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=n7/RD5c0z2Dt8DyJEydQIM/LzAcyi4nZJBDww06ZfCs=; b=q0N5iu+5+YVaHtISHkkjJoD6mhfbd6TS+6JVQWOHNJH3nypTgFpTd57Elhyry9cZvB 8/NwR2Y0KjQ/Yeg0YcfngULPtXcEoK6gSpcNVUcuO3VXEuNT4G5Z2ysgPcFVgUnZK9mx n5/9UuhtiED/StX0zJx5UTHwas/wb8bMy+Ibu30eycco+miqICBmn6kcE6fgj3XV0o5r ZdCscPyOXEtqxsEXgf2leo1d3pSXaV1TXryHJFPjjdIBHIq0nAcgCyh5vuWLfGSt6ZR0 TnRS9W23bxMpRVY/bpAD0CwQ0jaB3ZFz47YpdcyN/oEH0N3UEpTpsBN2y0CCmzxjddci KFJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ZmsbmfZm; 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 a19-20020a50e713000000b0041080b4c683si15945986edn.0.2022.03.28.16.27.00; Mon, 28 Mar 2022 16:27:00 -0700 (PDT) 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=ZmsbmfZm; 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 1127268B2DD; Tue, 29 Mar 2022 02:26:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5121068B2BB for ; Tue, 29 Mar 2022 02:25:52 +0300 (EEST) Received: by mail-oi1-f178.google.com with SMTP id i7so3240183oie.7 for ; Mon, 28 Mar 2022 16:25:52 -0700 (PDT) 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=wVAE86e9eyyIHV1gqH1ubCEcoxas9uY4gziz5wsWq2Y=; b=ZmsbmfZmMnBxTbaKT+KnoSfc3n1e8/mmaMH98/GdRFBT4dd4fZ850k750Bz5FGTGiT 84KGklkfu207isK4HOa83aGvfmXj7JRgEvM31A1S3WJNKIhOClzFON38H77opcrRasyx wR78fbgTQcn6Q/FB5nTs925BFYEFJy6kEMZ4s8oXNnfVlr9zQI4g0fd4lK2KjWUTI4D0 Z3oP3NDvY5Woc+Mqtj40fX+ITRAET/CLolCYslJSp9lXJ7KZmaf9oeeR3j63CsvYsAWm YHeA651+f7n9Xxa7qfCoO2/iWHaHSOeMjRJTfCGCB783/eP9Ojp/waQUjrmuS9nblDeh yF9Q== 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=wVAE86e9eyyIHV1gqH1ubCEcoxas9uY4gziz5wsWq2Y=; b=J0dhANWLv7I8D5wyg8iD8j7JqE9f0N53ULaatiRVW/+QNehqz1oDcxMs5aiuVZhyef eXqcsHZNe1jBbMRvWb9ClhHg/rSKKU4QmlBAlZuUdrEB0YnVq6F+wqpMTmw0NrJtrnxB SINQCEcXo3c35n65dYx+XlZE6HtQVy50IORCv7Q7+eeNZ31RpsAYE3fqbZW0vTa8HYUN Xuvy6dOFilox9Fpz29f/1YW+ivROqUJdVwKBJMMd4nSxbS4S4pn76bY0oentTnE1OSRp /EF/QvH9R5gXg7fvmiKtStDTfomil3EOKZbqgbNSZeUCqp9Hoq7Zd6Mc/VgohCPvzEsy HDag== X-Gm-Message-State: AOAM532BQeirNRKcVngzZV/LqBuEMw1bLDsBUTRomXu0/YaC2iwTdvkq NOT/t4L3tUmTbTo+6WPKcIO0RpWOgrvNcg== X-Received: by 2002:a05:6808:1201:b0:2d9:a01a:48b8 with SMTP id a1-20020a056808120100b002d9a01a48b8mr758191oil.259.1648509950716; Mon, 28 Mar 2022 16:25:50 -0700 (PDT) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id gk6-20020a0568703c0600b000de4880b357sm7198456oab.50.2022.03.28.16.25.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 16:25:50 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 Mar 2022 20:24:52 -0300 Message-Id: <20220328232453.54773-6-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220328232453.54773-1-jamrial@gmail.com> References: <20220328232453.54773-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avformat/movenc: don't use mono layout when a front center label is expected 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: x8dlRSQDMwDt On output streams where a multichannel stream needs to be stored as one track per channel, each track will have a channel layout describing the position of the channel they contain. For the track with front center, the mov muxer was using the mov layout "mono" instead of the label for the front center position. Since our channel layout API considers front center == mono, we need to do some heuristics. To achieve this, we make sure all audio tracks contain streams with a single channel, and only one of them is front center. In that case, we write the front center label instead of signaling mono layout. Fixes the last part of ticket #2865 Signed-off-by: James Almer --- libavformat/movenc.c | 25 +++++++++++++++++++++++++ libavformat/movenc.h | 1 + 2 files changed, 26 insertions(+) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 263649f1da..b9956e699c 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -887,6 +887,17 @@ static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra return ret; } + if (layout_tag == MOV_CH_LAYOUT_MONO && track->mono_as_fc > 0) { + av_assert0(!channel_desc); + channel_desc = av_malloc(sizeof(*channel_desc)); + if (!channel_desc) + return AVERROR(ENOMEM); + + layout_tag = 0; + bitmap = 0; + *channel_desc = 3; // channel label "Center" + } + num_desc = layout_tag ? 0 : track->par->ch_layout.nb_channels; avio_wb32(pb, 0); // Size @@ -6970,6 +6981,20 @@ static int mov_write_header(AVFormatContext *s) if (j == i) continue; + if (stj->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (trackj->par->ch_layout.nb_channels != 1 || + !av_channel_layout_compare(&trackj->par->ch_layout, + &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) + ) + track->mono_as_fc = -1; + + if (stj->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + av_channel_layout_compare(&trackj->par->ch_layout, + &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) && + trackj->par->ch_layout.nb_channels == 1 && track->mono_as_fc >= 0 + ) + track->mono_as_fc++; + if (stj->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || av_channel_layout_compare(&trackj->par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) || diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 2ac84ed070..67d6d4fb66 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -107,6 +107,7 @@ typedef struct MOVTrack { int tag; ///< stsd fourcc AVStream *st; AVCodecParameters *par; + int mono_as_fc; int multichannel_as_mono; int vos_len;