From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E28E44ABE4 for ; Wed, 15 May 2024 01:09:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B22C68D691; Wed, 15 May 2024 04:08:51 +0300 (EEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9CB0A68D670 for ; Wed, 15 May 2024 04:08:43 +0300 (EEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6f44bcbaae7so5594096b3a.2 for ; Tue, 14 May 2024 18:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715735321; x=1716340121; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rmIhzIE95fWoUSftNH5w96W/OYKp/ezAOoEvyXF7Z8M=; b=k0PlgeZHIYZej2dd0U0gxQvvuUglgT9IJcAD9wnGH3Yd4Skmcx8gHacBmbaR2TBzaH VVmv023WmgIvxxpHse5HhhbG4KitzHBHo6EyHWT2uDq3qpSM4ZdBYmFP1MbdmQyv8L4c 0X7iTm24OZfDUu/70logkvHzhMzv5nP4xIzGiqbWQYRt7g+4mCM4aw1TtRaWzx28FsmH mi/mzN5tvCyLyJZ8WDqXOfKCqrjBKMkAh0po+6IPkXvA7pZEGsxeX9VNAn8dl13+cI9J 3N6F9sjx79hlmkM71WZnbHwlqIoUQecD5xlTebO9EP4upHfETnMJlEE6OigXQV70gTjP 06Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715735321; x=1716340121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rmIhzIE95fWoUSftNH5w96W/OYKp/ezAOoEvyXF7Z8M=; b=oVT9Auy5+niszFIZ9YiWhK0p5Yh5p+DX/13Lvvi9E2XoDewjDsamQv5b6WuRVrihct XF/lUio1aL4iYcTxbfIwgNyU1LF0HSZ07dVIGkjyMY0WsUelWE+sK8MV/6P1MN17T5zK uC0icQQ05LEzoO405AAEe7jroSjWDIdLZ0YcAidSFqyEaeM/yc5eIc63oSi+OUiOal0E jyZZAE86J9vLuTUfFGd3BquQWGlD4MoLK0vmG9v+AmcqIxtO8YYCVcvIEY/o3olSHnbD kQb/vC8GhcGow6EwpVb++pva9q1GxfIT5SnhivhcF3zYWq1I0p205p6neiv65dCkyx87 e4Ag== X-Gm-Message-State: AOJu0YyY6GMqd5Pe6GwUjyluQ6sTMJqBYetk5nErorcbCx0qvOrmFmcU DBInY7MQKqNmea1/177oJs6B+DTuB+o3cp6b6tIJZwawcYY4nTgqqCX/eg== X-Google-Smtp-Source: AGHT+IHaQo/pR6LxXuInNiC5xDydpv3RtoxUsryFOn+lAVEnAQlNqxQfe6yZYe0EnnevOorO3Lgyqw== X-Received: by 2002:a05:6a00:2410:b0:6f3:ea67:48c3 with SMTP id d2e1a72fcca58-6f4e01b9368mr16099577b3a.0.1715735320882; Tue, 14 May 2024 18:08:40 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66691sm10135237b3a.16.2024.05.14.18.08.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 18:08:40 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 May 2024 22:08:29 -0300 Message-ID: <20240515010829.2667-2-jamrial@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240515010829.2667-1-jamrial@gmail.com> References: <20240515010829.2667-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- libavformat/movenc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f907f67752..2aec9a8d17 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -916,6 +916,62 @@ static int mov_write_dmlp_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra return update_size(pb, pos); } +static int mov_write_SA3D_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) +{ + AVChannelLayout ch_layout = { 0 }; + const AVDictionaryEntry *str = av_dict_get(track->st->metadata, "SA3D", NULL, 0); + int64_t pos; + int ambisonic_order, ambi_channels, non_diegetic_channels; + int i, ret; + + if (!str) + return 0; + + ret = av_channel_layout_from_string(&ch_layout, str->value); + if (ret < 0) { + if (ret == AVERROR(EINVAL)) { +invalid: + av_log(s, AV_LOG_ERROR, "Invalid SA3D layout: \"%s\"\n", str->value); + ret = 0; + } + av_channel_layout_uninit(&ch_layout); + return ret; + } + + if (track->st->codecpar->ch_layout.nb_channels != ch_layout.nb_channels) + goto invalid; + + ambisonic_order = av_channel_layout_get_ambisonic_order(&ch_layout); + if (ambisonic_order < 0) + goto invalid; + + ambi_channels = (ambisonic_order + 1LL) * (ambisonic_order + 1LL); + non_diegetic_channels = ch_layout.nb_channels - ambi_channels; + if (non_diegetic_channels && non_diegetic_channels != 2) + goto invalid; + + av_log(s, AV_LOG_VERBOSE, "Inserting SA3D box with layout: \"%s\"\n", str->value); + + pos = avio_tell(pb); + + avio_wb32(pb, 0); // Size + ffio_wfourcc(pb, "SA3D"); + avio_w8(pb, 0); // version + avio_w8(pb, (!!non_diegetic_channels) << 7); // head_locked_stereo and ambisonic_type + avio_wb32(pb, ambisonic_order); // ambisonic_order + avio_w8(pb, 0); // ambisonic_channel_ordering + avio_w8(pb, 0); // ambisonic_normalization + avio_wb32(pb, ch_layout.nb_channels); // num_channels + for (i = 0; i < ambi_channels; i++) + avio_wb32(pb, av_channel_layout_channel_from_index(&ch_layout, i) - AV_CHAN_AMBISONIC_BASE); + for (; i < ch_layout.nb_channels; i++) + avio_wb32(pb, i); + + av_channel_layout_uninit(&ch_layout); + + return update_size(pb, pos); +} + static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { uint32_t layout_tag, bitmap, *channel_desc; @@ -1419,6 +1475,11 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex if (ret < 0) return ret; + if (track->mode == MODE_MP4 && track->par->codec_type == AVMEDIA_TYPE_AUDIO + && ((ret = mov_write_SA3D_tag(s, pb, track)) < 0)) { + return ret; + } + if (track->mode == MODE_MOV && track->par->codec_type == AVMEDIA_TYPE_AUDIO && ((ret = mov_write_chan_tag(s, pb, track)) < 0)) { return ret; -- 2.45.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".