Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout
@ 2024-05-15  1:08 James Almer
  2024-05-15  1:08 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes James Almer
  2024-05-23  7:11 ` [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout Anton Khirnov
  0 siblings, 2 replies; 5+ messages in thread
From: James Almer @ 2024-05-15  1:08 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/channel_layout.c | 17 ++++++++---------
 libavutil/channel_layout.h | 10 ++++++++++
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index fd6718e0e7..e213f68666 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout *channel_layout)
     return 0;
 }
 
-/**
- * If the layout is n-th order standard-order ambisonic, with optional
- * extra non-diegetic channels at the end, return the order.
- * Return a negative error code otherwise.
- */
-static int ambisonic_order(const AVChannelLayout *channel_layout)
+int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout)
 {
     int i, highest_ambi, order;
 
+    if (channel_layout->order != AV_CHANNEL_ORDER_AMBISONIC &&
+        channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
+        return AVERROR(EINVAL);
+
     highest_ambi = -1;
     if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC)
         highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1;
@@ -536,7 +535,7 @@ static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout)
     if (masked_description(channel_layout, 0) > 0)
         return AV_CHANNEL_ORDER_NATIVE;
 
-    order = ambisonic_order(channel_layout);
+    order = av_channel_layout_get_ambisonic_order(channel_layout);
     if (order >= 0 && masked_description(channel_layout, (order + 1) * (order + 1)) >= 0)
         return AV_CHANNEL_ORDER_AMBISONIC;
 
@@ -551,7 +550,7 @@ static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout)
 static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout)
 {
     int nb_ambi_channels;
-    int order = ambisonic_order(channel_layout);
+    int order = av_channel_layout_get_ambisonic_order(channel_layout);
     if (order < 0)
         return order;
 
@@ -945,7 +944,7 @@ int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrde
         if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
             int64_t mask;
             int nb_channels = channel_layout->nb_channels;
-            int order = ambisonic_order(channel_layout);
+            int order = av_channel_layout_get_ambisonic_order(channel_layout);
             if (order < 0)
                 return AVERROR(ENOSYS);
             mask = masked_description(channel_layout, (order + 1) * (order + 1));
diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index 8a078d1601..c2ab236488 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -679,6 +679,16 @@ int av_channel_layout_check(const AVChannelLayout *channel_layout);
  */
 int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1);
 
+/**
+ * Return the order if the layout is n-th order standard-order ambisonic.
+ * The presence of optional extra non-diegetic channels at the end is not taken
+ * into account.
+ *
+ * @param channel_layout input channel layout
+ * @return the order of the layout, a negative error code otherwise.
+ */
+int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout);
+
 /**
  * The conversion must be lossless.
  */
-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes
  2024-05-15  1:08 [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout James Almer
@ 2024-05-15  1:08 ` James Almer
  2024-05-23 15:12   ` James Almer
  2024-05-23  7:11 ` [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout Anton Khirnov
  1 sibling, 1 reply; 5+ messages in thread
From: James Almer @ 2024-05-15  1:08 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout
  2024-05-15  1:08 [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout James Almer
  2024-05-15  1:08 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes James Almer
@ 2024-05-23  7:11 ` Anton Khirnov
  2024-05-23 11:55   ` James Almer
  1 sibling, 1 reply; 5+ messages in thread
From: Anton Khirnov @ 2024-05-23  7:11 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2024-05-15 03:08:28)
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavutil/channel_layout.c | 17 ++++++++---------
>  libavutil/channel_layout.h | 10 ++++++++++
>  2 files changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
> index fd6718e0e7..e213f68666 100644
> --- a/libavutil/channel_layout.c
> +++ b/libavutil/channel_layout.c
> @@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout *channel_layout)
>      return 0;
>  }
>  
> -/**
> - * If the layout is n-th order standard-order ambisonic, with optional
> - * extra non-diegetic channels at the end, return the order.
> - * Return a negative error code otherwise.
> - */
> -static int ambisonic_order(const AVChannelLayout *channel_layout)
> +int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout)

IMO the _get_ in the name is just making it unnecessarily longer.

-- 
Anton Khirnov
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout
  2024-05-23  7:11 ` [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout Anton Khirnov
@ 2024-05-23 11:55   ` James Almer
  0 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2024-05-23 11:55 UTC (permalink / raw)
  To: ffmpeg-devel

On 5/23/2024 4:11 AM, Anton Khirnov wrote:
> Quoting James Almer (2024-05-15 03:08:28)
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavutil/channel_layout.c | 17 ++++++++---------
>>   libavutil/channel_layout.h | 10 ++++++++++
>>   2 files changed, 18 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
>> index fd6718e0e7..e213f68666 100644
>> --- a/libavutil/channel_layout.c
>> +++ b/libavutil/channel_layout.c
>> @@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout *channel_layout)
>>       return 0;
>>   }
>>   
>> -/**
>> - * If the layout is n-th order standard-order ambisonic, with optional
>> - * extra non-diegetic channels at the end, return the order.
>> - * Return a negative error code otherwise.
>> - */
>> -static int ambisonic_order(const AVChannelLayout *channel_layout)
>> +int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout)
> 
> IMO the _get_ in the name is just making it unnecessarily longer.

Ok, will remove it.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes
  2024-05-15  1:08 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes James Almer
@ 2024-05-23 15:12   ` James Almer
  0 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2024-05-23 15:12 UTC (permalink / raw)
  To: ffmpeg-devel

On 5/14/2024 10:08 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavformat/movenc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 61 insertions(+)

Will apply the set.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-23 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-15  1:08 [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout James Almer
2024-05-15  1:08 ` [FFmpeg-devel] [PATCH 2/2] avformat/movenc: add support for writing SA3D boxes James Almer
2024-05-23 15:12   ` James Almer
2024-05-23  7:11 ` [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a layout Anton Khirnov
2024-05-23 11:55   ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git