Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] libavformat/mov && movenc: fix sidx earliest_presentation_time (PR #20623)
Date: Sun, 28 Sep 2025 10:04:43 -0000
Message-ID: <175905388408.25.1238122908664940952@bf249f23a2c8> (raw)

PR #20623 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20623
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20623.patch

sidx earliest_presentation_time as the name says, is in presentation timeline.
I made a mistake in 301141b, which intended to create presentation time, but finally created media time.
There is a bug in mp4 demuxer, which did the reverse: it minus sidx_pts by sc->time_offset to get presentation time, while sidx_pts is already in presentation timeline.

This patchset fix mp4 demuxer and revert the bug in mp4 muxer.

Muxer test:
```
./ffmpeg -f lavfi -i testsrc2 -f lavfi -i sine=sample_rate=48000 -af [1:a]asetpts=expr=PTS+2*SR -c:v libx264 -bf 0 -c:a aac -movflags cmaf+global_sidx+delay_moov -global_sidx 1 -t 10 out.mp4
```

Check editlist and sidx.

Demuxer test:
```
./ffprobe -show_packets -use_tfdt 0 out.mp4
./ffprobe -show_packets -use_tfdt 1 out.mp4
```

Check the first audio packet timestamp.


>From 9f115aa8b1c043a0af15887babef7b31ac183117 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
Date: Sun, 28 Sep 2025 17:23:05 +0800
Subject: [PATCH 1/2] avformat/mov: don't shift sidx_pts

sidx_pts is already in presentation time, so it shouldn't be shift
by sc->time_offset again.
---
 libavformat/mov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7fe4678234..9ce066a9a2 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5839,7 +5839,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
             } else if (has_sidx && !c->use_tfdt || fallback_sidx) {
                 // FIXME: sidx earliest_presentation_time is *PTS*, s.b.
                 // pts = frag_stream_info->sidx_pts;
-                dts = frag_stream_info->sidx_pts - sc->time_offset;
+                dts = frag_stream_info->sidx_pts;
                 av_log(c->fc, AV_LOG_DEBUG, "found sidx time %"PRId64
                         ", using it for dts\n", frag_stream_info->sidx_pts);
             } else {
-- 
2.49.1


>From 7d3ae113fec5597e8a7b7365d2cc402fc7f39d36 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
Date: Sun, 28 Sep 2025 17:35:41 +0800
Subject: [PATCH 2/2] Revert "avformat/movenc: sidx earliest_presentation_time
 is applied after editlist"

This reverts commit 301141b57636c4430e7440e8ff4956daf9cb0fb3.

cluster[0].dts, pts and frag_info[0].time are already in presentation
timeline, so they shouldn't be shift by start_pts.
---
 libavformat/movenc.c  |  6 +-----
 tests/ref/fate/movenc | 10 +++++-----
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 067d38b14b..b76d56dac4 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5690,8 +5690,7 @@ static int mov_write_sidx_tag(AVIOContext *pb,
 
     if (track->entry) {
         entries = 1;
-        presentation_time = track->cluster[0].dts + track->cluster[0].cts -
-                            track->start_dts - track->start_cts;
+        presentation_time = track->cluster[0].dts + track->cluster[0].cts;
         duration = track->end_pts -
                    (track->cluster[0].dts + track->cluster[0].cts);
         starts_with_SAP = track->cluster[0].flags & MOV_SYNC_SAMPLE;
@@ -5706,9 +5705,6 @@ static int mov_write_sidx_tag(AVIOContext *pb,
         if (entries <= 0)
             return 0;
         presentation_time = track->frag_info[0].time;
-        /* presentation_time <= 0 is handled by mov_add_tfra_entries() */
-        if (presentation_time > 0)
-            presentation_time -= track->start_dts + track->start_cts;
     }
 
     avio_wb32(pb, 0); /* size */
diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
index 5c12aeb29f..f2b95ea957 100644
--- a/tests/ref/fate/movenc
+++ b/tests/ref/fate/movenc
@@ -101,28 +101,28 @@ write_data len 1223, time nopts, type header atom ftyp
 041ac8efc35a0d023c26d05eedb20403 1223 delay-moov-elst-signal-init
 write_data len 1004, time -33333, type sync atom sidx
 write_data len 996, time 966667, type sync atom sidx
-69c9025ffb10302c7b5c2ed9fde86c44 996 delay-moov-elst-signal-second-frag
+5a583d89318827d2569eecbeaa18c238 996 delay-moov-elst-signal-second-frag
 write_data len 148, time nopts, type trailer atom -
 write_data len 1223, time nopts, type header atom ftyp
 041ac8efc35a0d023c26d05eedb20403 1223 delay-moov-elst-signal-init-discont
 write_data len 996, time 966667, type sync atom sidx
-69c9025ffb10302c7b5c2ed9fde86c44 996 delay-moov-elst-signal-second-frag-discont
+5a583d89318827d2569eecbeaa18c238 996 delay-moov-elst-signal-second-frag-discont
 write_data len 110, time nopts, type trailer atom -
 write_data len 1247, time nopts, type header atom ftyp
 80511a51d1ac9cde62337eed7176ae03 1247 delay-moov-elst-signal-init-discont-largets
 write_data len 996, time 279621233333, type sync atom sidx
-471fc64644a6bf4065c489fe4e04be7d 996 delay-moov-elst-signal-second-frag-discont-largets
+dc695d65e8a0cdafee28acd8a5ccf81a 996 delay-moov-elst-signal-second-frag-discont-largets
 write_data len 110, time nopts, type trailer atom -
 write_data len 1223, time nopts, type header atom ftyp
 write_data len 2572, time -333333, type sync atom sidx
 write_data len 996, time 5166667, type sync atom sidx
 write_data len 148, time nopts, type trailer atom -
-5c873f6e37d5af09e3c6329cf94cd6ca 4939 vfr
+d37a7eda807912b9ed05ccfe003a9e4f 4939 vfr
 write_data len 1223, time nopts, type header atom ftyp
 write_data len 2572, time -333333, type sync atom sidx
 write_data len 996, time 5166667, type sync atom sidx
 write_data len 148, time nopts, type trailer atom -
-5c873f6e37d5af09e3c6329cf94cd6ca 4939 vfr-noduration
+d37a7eda807912b9ed05ccfe003a9e4f 4939 vfr-noduration
 write_data len 1231, time nopts, type header atom ftyp
 write_data len 1500, time -333333, type sync atom moof
 write_data len 1500, time nopts, type unknown atom -
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-09-28 10:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=175905388408.25.1238122908664940952@bf249f23a2c8 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@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 http://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/ http://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