From patchwork Sat Mar 17 02:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Courtland Idstrom X-Patchwork-Id: 8016 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp198068jad; Fri, 16 Mar 2018 19:29:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELtx0UJdlVuHJneZXZAj+8nuiiILqHiBAmokef9Wh4Ev8k2bf92s88wzr2TNGcF21TnGX1IC X-Received: by 10.28.107.9 with SMTP id g9mr3435765wmc.157.1521253790539; Fri, 16 Mar 2018 19:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521253790; cv=none; d=google.com; s=arc-20160816; b=Vt+dHIOGakVBRjehir7wYpTITBtPyPvUNRlMUiJGzdWLEIp96zMPIXHMSkx9g4i8Sz ACQylcjac9k2oUmV2mnQ1DjulRM/d3IKYmoXV5/+NmGV9CkCB1mCM3z6WtJVAvk/TYqz M+t9mbbb5fkpgvZfhkehng/1JI5nA5rc9nxzLEoDSDAjy6amWz8pDgqYnJ3052+/cGIt 2+lv5ja+j1uz+WnFHW6Au7Fl/L7PAIO8vsYLorhBL5fG0oUgUO2G2PLVqmhdgCUkI0t7 iz5jBOoBwKKNJzlcgwRpMTqZiImuZN8QohIx4OgXgbVLbvfwKCGDRJb1ERNF6mVI+KL9 uHRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=5ACHZcEo58EM7+2VWyJYXqKrk+4TbvUXMjtPVW0pWh0=; b=wt6sSarfcbuVeRt25T1Y/V0BxS7tkQqATm2R4tVLjq6/X3B8LBG28KWsuimd43GhGQ DyQGVn4bPZXkBXgFQHqaHAlhlm4zTiPEZdAD3rpjprk+f4eB8Q6KmHAxHI5XceEcdehX pY0tamS0nJzpPm3PPYLwgfyvqdo7TMxkL+IXa9by2DRjSzGMU1IjIJWlltoRVNseTvnT DdBtUSazgrl+PSHDwqbLj4UvXezdddP7I0wrrDaUm0oJhDcazqX/viT5eE8pIFJ+HGJO dHDHYIVulmto6WyvAMZqORgOJB2Dk/QQ/HDGB2GLTbeG0JbjrZbFX3NIRaF0czva0Lpm WeAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@telltalegames.com header.s=google header.b=GURsMjdE; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v61si4683552wrc.456.2018.03.16.19.29.50; Fri, 16 Mar 2018 19:29:50 -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=@telltalegames.com header.s=google header.b=GURsMjdE; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B339689A53; Sat, 17 Mar 2018 04:29:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f46.google.com (mail-pl0-f46.google.com [209.85.160.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90C7F68995A for ; Sat, 17 Mar 2018 04:29:29 +0200 (EET) Received: by mail-pl0-f46.google.com with SMTP id f23-v6so6928555plr.10 for ; Fri, 16 Mar 2018 19:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telltalegames.com; s=google; h=from:to:cc:subject:date:message-id; bh=ot2Te1c5Jb12tvPgsXrRUTkd6Gir7qiHvcA1j1iPXII=; b=GURsMjdEaGj2n/ipAiFXCHCfinzVzV6IEh5zwmlk7YRC8EJrrsfguY48QgsJkRzO5B h/Ikum2iht5txyeUhu9X9n2kx1icRtxca7F0PoLdwvB3Q/7o7N9xCzHzisjQKMA48eN1 QcLVUXN7TWLT42Xo2OqYQkX3Ohb3YId3HpaIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ot2Te1c5Jb12tvPgsXrRUTkd6Gir7qiHvcA1j1iPXII=; b=jT2OABxslsfJl8p3tQ2kwzJSWtVXPBqfDWStmbevPKmWoIoQFFwWIryOa71J3tnbwS lqxhuzOal12d++dcIqHDdCWAzehZsDAV7QyCIJOl3+NZ9e9ABxEV5ACIEfOa8D8SBdm1 Dn2lRW+XQe4d8IVSUxsPygUwVps1QOnXxnsyO4civoDNezLicecOfb7q3FLbYsFvfUhQ iGGCgunqiPx1D9vDq5zKgLD3ZO98OogjNeW6gKuWJQWuN0xFkw6AwMGDnbBIoMWP0nlI DoADJZRvqmhJHMDbJzqMhg0uVvuu16jiN7L88F2TupyOVhRWI+gFdrnvsW98CUWr0VMY Fi5w== X-Gm-Message-State: AElRT7GR25PPWGFcpSkvOp8UGAmvJbx6LyYe0Dx+oNlKGhrBaHYAXdRh oEXrs/nZ0wmolYx1xgwq5IOmkZXD X-Received: by 2002:a17:902:7509:: with SMTP id i9-v6mr4308113pll.220.1521253780516; Fri, 16 Mar 2018 19:29:40 -0700 (PDT) Received: from localhost.localdomain (76-246-10-223.lightspeed.snmtca.sbcglobal.net. [76.246.10.223]) by smtp.gmail.com with ESMTPSA id 132sm59279pgc.25.2018.03.16.19.29.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Mar 2018 19:29:39 -0700 (PDT) From: Courtland Idstrom To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Mar 2018 19:29:34 -0700 Message-Id: <20180317022934.24114-1-cidstrom@telltalegames.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) Subject: [FFmpeg-devel] [PATCH] mov: add channel label support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Courtland Idstrom MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adds the ability to support writing channel labels to mov files if the layout_tag fails, instead of printing a warning and skipping the tag. This fixes channels such as DL/DR, which will now write to LeftTotal/RightTotal instead of omitting the channel tag. --- Changelog | 1 + libavformat/mov_chan.c | 20 ++++++++++++++++++++ libavformat/mov_chan.h | 8 ++++++++ libavformat/movenc.c | 38 +++++++++++++++++++++++++++++++------- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index 32a93d916a..d9b46b6d78 100644 --- a/Changelog +++ b/Changelog @@ -48,6 +48,7 @@ version : - drmeter audio filter - hapqa_extract bitstream filter - movenc option to write track title metadata +- mov: write channel labels if channel layout is not found version 3.4: - deflicker video filter diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 324dd5f913..4eb434a97b 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -478,6 +478,26 @@ uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) return layout_map[i].layout; } +uint32_t ff_mov_get_channel_label_tag(uint64_t channel) +{ + int i; + + if(channel == 0) + return 0; + + for(i=0; i<=17; ++i) + if((1U << i) & channel) + return i+1; + + if(channel == AV_CH_STEREO_LEFT) + return 38; // LeftTotal + + if(channel == AV_CH_STEREO_RIGHT) + return 39; // RightTotal + + return 0; +} + static uint32_t mov_get_channel_label(uint32_t label) { if (label == 0) diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index ca28345aef..81acb73655 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -53,6 +53,14 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id, uint64_t channel_layout, uint32_t *bitmap); +/** + * Get the channel label tag for the specified channel. + * + * @param[in] channel channel identifier + * @return channel label tag + */ +uint32_t ff_mov_get_channel_label_tag(uint64_t channel); + /** * Read 'chan' tag from the input stream. * diff --git a/libavformat/movenc.c b/libavformat/movenc.c index ea48c3293e..2c79462e9f 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -742,30 +742,54 @@ static int mov_write_dops_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } +static void mov_write_channel_layout_label_tags(AVFormatContext *s, AVIOContext *pb, uint64_t channel_layout) +{ + int i, channels; + + channels = av_get_channel_layout_nb_channels(channel_layout); + + for(i=0; ipar->codec_id, track->par->channel_layout, &bitmap); - if (!layout_tag) { - av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to " - "lack of channel information\n"); - return 0; - } if (track->multichannel_as_mono) return 0; + num_channel_desc = layout_tag == 0 ? av_get_channel_layout_nb_channels(track->par->channel_layout) : 0; + avio_wb32(pb, 0); // Size ffio_wfourcc(pb, "chan"); // Type avio_w8(pb, 0); // Version avio_wb24(pb, 0); // Flags avio_wb32(pb, layout_tag); // mChannelLayoutTag avio_wb32(pb, bitmap); // mChannelBitmap - avio_wb32(pb, 0); // mNumberChannelDescriptions + avio_wb32(pb, num_channel_desc); // mNumberChannelDescriptions + + if(!layout_tag) { + mov_write_channel_layout_label_tags(s, pb, track->par->channel_layout); + } return update_size(pb, pos); }