0

I have been trying to generate a HLS stream encoded with h265 but with no success. I came across Generate hls stream using h265 codec but the solution given in it doesn't seems to be working.

Another approach that I tried was by running this command:

ffmpeg -hide_banner -y -i original.mp4 -c:v libx265 -tag:v hvc1 -force_key_frames expr:gte(t,n_forced*2) -c:a copy -profile:v main -crf 20 -sc_threshold 0 -g 60 -keyint_min 60 -hls_segment_type fmp4 -hls_time 6 -hls_playlist_type vod -vf scale=w=720:h=720:force_original_aspect_ratio=decrease,pad=ceil(iw/2)*2:ceil(ih/2)*2 processed/720p.m3u8

I also have added below in the master playlist.

CODECS=hvc1.1.6.L120.90,mp4a.40.2

When I put all the contents on S3 and use different players out there hls-js, bitmovin and akamai, they all seem to load the manifest file properly but aren't able to play the video.

Note: that above behaviour is only on Safari. It starts to throw manifestIncompatibleCodecsError on Chrome. I am assuming this is cause of chrome not being able to support H265 and that's fine for me as of now.

My ffmpeg version is N-102560-g4718d74c58

When I run mediastreamvalidator on the master playlist, it throws the error

mediastreamvalidator playlist.m3u8

Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
Error injecting segment data
[720p.m3u8] All media files delivered and have end tag, stopping
Error injecting segment data

--------------------------------------------------------------------------------
720p.m3u8
--------------------------------------------------------------------------------
Processed 0 out of 20 segments
Average segment duration: 5.873333
Total segment bitrates (all discontinuities): average: 1722.41 kb/s, max: 2295.00 kb/s
Playlist max bitrate: 2500.000000 kb/s
Audio Group ID: AUDIO


Discontinuity: sequence: 0, parsed segment count: 0 of 20, duration: 117.467 sec, average: 1722.41 kb/s, max: 2295.00 kb/s

I am not really sure what went wrong here.

Extra Info

Found a few similar tickets with ffmpeg 6888, 7021, 7023 and 7024.

Out of these, while 6888 seems to have been fixed, rest others are still open (CMIIW). The fix for 6888 seems to be three years old. I am assuming by now it is merged into the master as well

dravit
  • 105
  • 6
  • 1
    Output to a regular MP4 and try bento4 to generate HLS. – Gyan Jul 13 '21 at 07:16
  • @Gyan Have tried bento4 but that is also not working. – dravit Jul 13 '21 at 09:31
  • Open an issue at bento4. They will be better informed as to what Apple needs in a HLS HEVC package. – Gyan Jul 13 '21 at 10:12
  • @Gyan Does `ffmpeg` not support generating HLS in H265? – dravit Jul 13 '21 at 10:43
  • It does, but since bento4 output fails as well, it looks like Apple wants something specific. And bento4 has a narrower scope, so they will have encountered the issue more. – Gyan Jul 13 '21 at 12:51
  • Will it be possible to share the corresponding ffmpeg command? Or probably edit my command itself with the right way to do it? – dravit Jul 13 '21 at 15:15
  • I've found that mediastreamvalidator will throw a lot of errors / warnings about things that don't actually prevent the playlist from working on actual devices. I've also been having problems getting ffmpeg to generate hls playlists that will actually play and I ended up switching to bento4 for fragment and playlist generation instead, and just let ffmpeg do the transcode to hevc. – jcaruso Jul 21 '21 at 13:55
  • @jcaruso true.. but the h265 playlist generated by bento4 also is not playing on safari – dravit Jul 21 '21 at 18:34
  • @dravit hmm interesting... how have you modified your ffmpeg command at all when trying to use bento? I did the following for myself when switching from ffmpeg's hls to bento: removed all HLS specific arguments, only left `sc_threshold = 0`, `force_keyframes`, `r` and `g`. Then for bento I use `mp4fragment --fragment-duration 6000` and then used the file from that in `mp4dash --hls` and the results of that worked pretty good for me. – jcaruso Jul 22 '21 at 14:50
  • @jcaruso Oh.. I did not try this approach. I used the mp4hls binary to convert the mp4 hevc (h265) video to hls. Let me try the above approach once. – dravit Jul 23 '21 at 06:43
  • @dravit yeah the mp4hls, according to the doc anyways, generates what they call "legacy" hls stream. Not entirely sure what that means, but they suggest using mp4dash instead for modern stuff. – jcaruso Jul 23 '21 at 14:01
  • Thanks a lot @jcaruso, This worked!! I spent good amount of time to get this to work. Found no working solution until this. – dravit Jul 31 '21 at 09:41
  • Sweet, I'll write up an answer then to make it easier for others to find if they end up here – jcaruso Aug 01 '21 at 14:05

1 Answers1

1

I had trouble too when I switched to bento but all I needed to do was modify my ffmpeg transcode.

  1. For my ffmpeg transcode, I removed all HLS specific arguments, only left sc_threshold = 0, force_keyframes, r and g
  2. I let bento fragment the file mp4fragment --fragment-duration 6000
  3. Then mp4dash --hls should be able to generate a valid, playable playlist
jcaruso
  • 136
  • 3
  • While the solution worked well, how can we make it adaptive bitrate supportive? You got any ideas? – dravit Aug 03 '21 at 10:06
  • 1
    According to the docs in Bento (they're fantastic, worth a read to get familiar with the tool) you can provide multiple video files (each with separate bit rates) and it will generate an appropriate playlist https://www.bento4.com/developers/dash/ (see `Example: multi-bitrate set of MP4 files`) – jcaruso Aug 03 '21 at 15:56