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 0/1] avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback
@ 2025-07-21 21:01 David McElroy
  2025-07-21 21:01 ` [FFmpeg-devel] [PATCH 1/1] " David McElroy
  0 siblings, 1 reply; 3+ messages in thread
From: David McElroy @ 2025-07-21 21:01 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: David McElroy

Hi FFmpeg developers,

This patch fixes a bug that makes HEVC fmp4 HLS streams generated by FFmpeg
unplayable on all Apple platforms (macOS/iOS Safari, QuickTime, etc.).

The issue is a malformed init segment, as detailed in the commit message.

A similar patch was proposed in November 2023 by Jay Zhang,
but it was never merged.
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/317173.html

**To Reproduce the Bug:**

You can generate a problematic HLS init segment using a command like this on
the current master branch:
$ ffmpeg -i ../BigBuckBunny_short.mp4 -c:v libx265 -f hls -hls_segment_type fmp4 playlist.m3u8

**Sample Files:**

To make review easier, I've uploaded two sample streams produced with that
command from that file from latest master (commit 9c9b41b)
with and without the patch applied:

- Source file: https://david.mcelroy.online/ffmpegbug/examples/BigBuckBunny_short.mp4

- Broken stream (from master): https://david.mcelroy.online/ffmpegbug/examples/9c9b41b/playlist.m3u8
- Fixed stream (with this patch): https://david.mcelroy.online/ffmpegbug/examples/patched/playlist.m3u8

These links can be loaded directly in Safari to see the playback issue.

- Broken init segment (from master): https://david.mcelroy.online/ffmpegbug/examples/9c9b41b/init.mp4
- Fixed init segment (with this patch): https://david.mcelroy.online/ffmpegbug/examples/patched/init.mp4

You may also note that when selected in Finder, the broken init segment fails
to be recognized as HEVC video, while the fixed one is recognized correctly.

I also ran `make fate` to ensure no regressions were introduced and all
tests passed.

The commit contains the full technical details of the fix.

Thanks,
David McElroy


David McElroy (1):
  avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback

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

-- 
2.34.1

_______________________________________________
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] 3+ messages in thread

* [FFmpeg-devel] [PATCH 1/1] avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback
  2025-07-21 21:01 [FFmpeg-devel] [PATCH 0/1] avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback David McElroy
@ 2025-07-21 21:01 ` David McElroy
  2025-07-28 15:29   ` Michael Niedermayer
  0 siblings, 1 reply; 3+ messages in thread
From: David McElroy @ 2025-07-21 21:01 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: David McElroy, Jay Zhang

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 <wangyoucao577@gmail.com>
Signed-off-by: David McElroy <david@mcelroy.online>
---
 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 8d13ac8..bb0af11 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);
-- 
2.34.1

_______________________________________________
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] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/1] avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback
  2025-07-21 21:01 ` [FFmpeg-devel] [PATCH 1/1] " David McElroy
@ 2025-07-28 15:29   ` Michael Niedermayer
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Niedermayer @ 2025-07-28 15:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1226 bytes --]

On Mon, Jul 21, 2025 at 05:01:47PM -0400, David McElroy wrote:
> 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 <wangyoucao577@gmail.com>
> Signed-off-by: David McElroy <david@mcelroy.online>
> ---
>  libavformat/movenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What is kyc? Its a tool that makes you give out your real ID, while criminals
give out a forged ID card.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2025-07-28 15:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-21 21:01 [FFmpeg-devel] [PATCH 0/1] avformat/movenc: fix HEVC fmp4 HLS init segment for Apple playback David McElroy
2025-07-21 21:01 ` [FFmpeg-devel] [PATCH 1/1] " David McElroy
2025-07-28 15:29   ` Michael Niedermayer

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