Search code examples
ffmpeghttp-live-streamingmpeg-dashmp4boxbitmovin-player

How to create HLS manifest from MPEG DASH segments?


Since, Apple has announced the support for fragmented MP4, Is it possible to create both DASH manifest (.mpd) and HLS manifest (.m3u8) for the same set of segments ( for separate audio and video). How to do it?


Solution

  • I don't know if it's possible with ffmpeg, but shaka-packager is able to do just this. Following command will output MP4 segments as well as HLS and DASH manifests, reusing MP4 segments for both (not sure if you can use existing MP4 segments though, you might have to mux them back into a single mp4 per video stream first):

    # HLS + DASH
    packager \
        'in=h264_baseline_360p_720.mp4,stream=audio,init_segment=audio_init.mp4,segment_template=audio_$Number$.m4s,playlist_name=audio.m3u8,hls_group_id=audio,hls_name=ENGLISH' \
        'in=h264_baseline_360p_720.mp4,stream=video,init_segment=h264_360p_init.mp4,segment_template=h264_360p_$Number$.m4s,playlist_name=h264_360p.m3u8' \
        'in=h264_main_480p_1400.mp4,stream=video,init_segment=h264_480p_init.mp4,segment_template=h264_480p_$Number$.m4s,playlist_name=h264_480p.m3u8' \
        'in=h264_high_720p_2400.mp4,stream=video,init_segment=h264_720p_init.mp4,segment_template=h264_720p_$Number$.m4s,playlist_name=h264_720p.m3u8' \
        --hls_master_playlist_output h264_master.m3u8 \
        --mpd_output h264.mpd \
        --base_urls https://example.org/ \
        --hls_base_url https://example.org/ \
        --generate_static_mpd
    

    Be aware that, at the time of this writing, you need to use the master branch code (or the google/shaka-packager:latest docker image), as the newest release 1.6.2 will just exit with Cannot output both MPD and HLS.

    Although I never used it so far, Bento4 is another tool which is able to package DASH and HLS in a single run:

    mp4-dash.py  | grep hls
      --hls                 Output HLS playlists in addition to MPEG DASH
      --hls-key-url=<url>   HLS key URL (default: key.bin)
      --hls-master-playlist-name=<filename>
      --hls-media-playlist-name=<filename>
      --hls-iframes-playlist-name=<filename>