Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 3/4] avformat/iamf_writer: fix coded audio_roll_distance values
Date: Tue, 16 Jul 2024 22:49:24 -0300
Message-ID: <20240717014925.16517-3-jamrial@gmail.com> (raw)
In-Reply-To: <20240717014925.16517-1-jamrial@gmail.com>

From: Felicia Lim <flim@google.com>

'seek_preroll' corresponds to 'audio_roll_distance' in IAMF[]1

[1]https://aomediacodec.github.io/iamf/v1.0.0-errata.html#audio_roll_distance
---
 libavformat/iamf_parse.c  |  2 +-
 libavformat/iamf_writer.c | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index a69d4a2f3a..2674a5186d 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -683,7 +683,7 @@ static int audio_element_obu(void *s, IAMFContext *c, AVIOContext *pb, int len)
         substream->codecpar->codec_id   = codec_config->codec_id;
         substream->codecpar->frame_size = codec_config->nb_samples;
         substream->codecpar->sample_rate = codec_config->sample_rate;
-        substream->codecpar->seek_preroll = codec_config->seek_preroll;
+        substream->codecpar->seek_preroll = -codec_config->seek_preroll * codec_config->nb_samples;
 
         switch(substream->codecpar->codec_id) {
         case AV_CODEC_ID_AAC:
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 35db078147..af837ccb1f 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -72,6 +72,34 @@ static int update_extradata(IAMFCodecConfig *codec_config)
     return 0;
 }
 
+static int populate_default_seek_preroll(IAMFCodecConfig *codec_config)
+{
+    switch (codec_config->codec_id) {
+    case AV_CODEC_ID_OPUS:
+        if (!codec_config->nb_samples)
+            return AVERROR(EINVAL);
+        // ceil(3840 / nb_samples)
+        codec_config->seek_preroll = -(1 + ((3840 - 1) / codec_config->nb_samples));
+        break;
+    case AV_CODEC_ID_AAC:
+        codec_config->seek_preroll = -1;
+        break;
+    case AV_CODEC_ID_FLAC:
+    case AV_CODEC_ID_PCM_S16BE:
+    case AV_CODEC_ID_PCM_S24BE:
+    case AV_CODEC_ID_PCM_S32BE:
+    case AV_CODEC_ID_PCM_S16LE:
+    case AV_CODEC_ID_PCM_S24LE:
+    case AV_CODEC_ID_PCM_S32LE:
+        codec_config->seek_preroll = 0;
+        break;
+    default:
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
 static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg,
                              IAMFCodecConfig *codec_config)
 {
@@ -83,7 +111,7 @@ static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg,
     codec_config->sample_rate = st->codecpar->sample_rate;
     codec_config->codec_tag = st->codecpar->codec_tag;
     codec_config->nb_samples = st->codecpar->frame_size;
-    codec_config->seek_preroll = st->codecpar->seek_preroll;
+    populate_default_seek_preroll(codec_config);
     if (st->codecpar->extradata_size) {
         codec_config->extradata = av_memdup(st->codecpar->extradata, st->codecpar->extradata_size);
         if (!codec_config->extradata)
-- 
2.45.2

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

  parent reply	other threads:[~2024-07-17  1:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17  1:49 [FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix channel count and samplerate fields for IAMF tracks James Almer
2024-07-17  1:49 ` [FFmpeg-devel] [PATCH 2/4] avformat/iamf_writer: fix PCM endian-ness flag James Almer
2024-07-17  1:49 ` James Almer [this message]
2024-07-17  1:49 ` [FFmpeg-devel] [PATCH 4/4] avformat/iamf: byteswap values in OpusHeader James Almer
2024-07-17  6:18 ` [FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix channel count and samplerate fields for IAMF tracks Anton Khirnov
2024-07-17 11:29   ` James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240717014925.16517-3-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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