ffmpeg | branch: master | David McElroy <david@mcelroy.online> | Mon Jul 21 
17:01:47 2025 -0400| [4b6f6af384a76b8ca1cbb4fdde734ffaf111a934] | committer: 
Michael Niedermayer

avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback

HEVC fmp4 HLS video produced by ffmpeg is currently unplayable on Apple
software (Safari, QuickTime, AVFoundation).

This is caused by an empty sdtp atom being erroneously written to the
fmp4 init segment. The `has_disposable` flag can be set for a track
with B-frames, but the init segment contains no actual frames
(track->entry == 0). Writing an sdtp atom in this case is incorrect
and causes Apple's parsers to reject the file.

This patch fixes the issue by ensuring the sdtp atom is only written
if track->entry is non-zero.

A similar patch was proposed in November 2023 by Jay Zhang,
but it was never merged.

Link: https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/317173.html
Co-authored-by: Jay Zhang <wangyoucao...@gmail.com>
Signed-off-by: David McElroy <david@mcelroy.online>
Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b6f6af384a76b8ca1cbb4fdde734ffaf111a934
---

 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 8d13ac81cd..bb0af11863 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3273,7 +3273,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContext
          track->par->codec_tag == MKTAG('r','t','p',' ')) &&
         track->has_keyframes && track->has_keyframes < track->entry)
         mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE);
-    if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->has_disposable)
+    if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->has_disposable 
&& track->entry)
         mov_write_sdtp_tag(pb, track);
     if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
         mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to