.m3u8 (HEVC, HLS) video won't play while other will

883 Views Asked by At

I converted my video into HEVC codec with support for HLS using ffmpeg with the following command:

ffmpeg -i originalName.mp4 -c:v libx265 -tag:v hvc1 -g 60 -hls_time 2 -hls_playlist_type vod -hls_segment_type fmp4 originalName-8000-fmp4-1080p.m3u8"

Then I uploaded it onto my server and tried playing it. Navigating to http://memoryprinting.sk/am/videos/test2/1_IMG_1122-8000-fmp4-1080p.m3u8 where it is stored in Safari shows just broken player icon (Safari supports playing these), but opening it from the same path using VLC player works normally.

I thought the issue might be on my server, but I tried uploading a .m3u8 video and segments that I downloaded from a different URL and this works fine even when opening it in Safari. (http://memoryprinting.sk/am/videos/test/v360p_fmp4.m3u8)

I can't figure out where could be the problem. Checking my m3u8 file in VSCode, it has the same structure as the other one which works.

Edit: Tried encoding to h264 instead of hevc in ffmpeg and this works. But HEVC itself can't be a problem since the video that is working is also 'hvc1' (same as my video) based on ffprobe.

1

There are 1 best solutions below

0
user1207524 On

The problem was actually with the init.mp4 that ffmpeg generates. It just doesn't work in Safari or in iOS AVPlayer. Using bento4 for creating HLS resolved the issue although the process was bit more complicated.

First I needed to use ffmpeg to add keyframes to the video as that was something I needed.

ffmpeg -i source.mp4 -c:v libx265 -tag:v hvc1 -g 60 -c:a copy output_keyframed.mp4

Then using Bento4 I created fragmented mp4

mp4fragment --fragment-duration 2000 output_keyframed.mp4 fragmented.mp4

And finally from that the HLS files

mp4dash --hls fragmented.mp4

Despite setting the fragment duration to 2000 I was unable to force same segment durations in HLS and mp4dash doesn't have a setting for segment duration. So as a workaround I ended up using the HLS generated by ffmpeg as it offers more settings, but replaced the init.mp4 file with the one created by Bento4.