axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
1.97k stars 479 forks source link

Safari not able to play HLS playlist which was sourced from a HEVC codec video #625

Open DravitLochan opened 3 years ago

DravitLochan commented 3 years ago

I am trying to generate and play a HLS stream in HEVC codec using bento4's mp4hls command. The issue is that when I upload the stream on S3, it is not playing on Safari (Note: stream is not working/playing from local as well).

Since HEVC has added benefits, I prefer keeping the codec to h265 only.

Another point to note here is that I manually converted the mp4 file from h264 to h265. If there's a way to achieve the above config without generating an intermediate h265 mp4, I'll be happy to use that as well.

Command used:

mp4hls original.mp4 --hls-version=7 --master-playlist=playlist --media-playlist-name=temp

ffprobe of the file is

ffprobe version N-102560-g4718d74c58 Copyright (c) 2007-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --enable-chromaprint --enable-decklink --enable-libvmaf --samples=fate-suite/
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  1.100 / 59.  1.100
  libavformat    59.  2.100 / 59.  2.100
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.101 /  8.  0.101
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'libx265_800k.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.2.100
  Duration: 00:01:57.47, start: 0.000000, bitrate: 1074 kb/s
  Stream #0:0(und): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709, progressive), 1078x1920, 823 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 250 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
      vendor_id       : [0][0][0][0]

EDIT: Question raised on SuperUser while I was trying ffmpeg for the same task: https://superuser.com/questions/1661921/generate-hls-with-h265-codec

BucherTomas commented 3 years ago

mp4hls muxes the content into ts container while for HEVC Apple requires fragmented mp4 container (look for 1.5. The container format for HEVC video MUST be fMP4 at https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices ). This can be achieved by using mp4dash with parameter hls.

There are/were other obstacles in using HEVC with Safari, one of them is preference of hvc1 tag as opossed to hev1, that part you satisfy according to your ffmpeg log output. The second was that even with proper HEVC codec strings in m3u8 the playback did not start, while Safari was happy to play the stream if omitted. Not sure if it is still a problem in recent versions of Safari.