Things Required

  • Bento4 tool
  • Fragmented Mp4 file(s)

Packaging Instructions

First thing you need to do is get bento4 from here. The tool we are going to use for this is called mp4hls and its comes with Bento4. mp4hls creates a multi-bitrate HLS master playlist from one or more MP4 files, including support for encryption and I-frame-only playlists. This can be used as a replacement for Apple’s variantplaylistcreator tool.

You need fragmented mp4 files for hls packaging. In short you need to encode your original content into different renditions and then fragment each rendition with a specific fragment-duration. For encoding you can use ffmpeg and for fragmentation you can use mp4fragment which is again a part of Bento4. I will write a detailed article on encoding with ffmpeg and mp4fragment.

Syntax

bento4/bin/mp4hls <list of file paths separated with space>

Example

Suppose you have a video content Sample.mp4  with maximum resolution 1080p.
We have encoded it into following:
Sample_1080.mp4 : 1080p
Sample_720p.mp4 : 720p
Sample_480.mp4  : 480p
Sample_320.mp4  : 320p

Further these files are fragmented info following:
Sample_1080.mf4
Sample_720p.mf4
Sample_480.mf4
Sample_320.mf4

So, now we have a list of fragmented renditions to package with mp4hls tool. Hence, our final command will be,

bento4/bin/mp4hls Sample_1080.mf4 Sample_720p.mf4 Sample_480.mf4 Sample_320.mf4

Output

The above command will generate a output directory.

  • output (directory)
    • media-1 (directory)
    • media-2 (directory)
    • media-3 (directory)
    • media-4 (directory)
    • master.m3u8 (playlist file)

Note: media directories refers to each renditions where master.m3u8 refers the master playlist.

Bonus Information

  • You can change the name of master playlist with this attribute: –master-playlist-name=<filename>
  • By default the tool will generate a directory called “output”. You can override this and change output path with this attribute: -o <output-dir> or –output-dir=<output-dir>
  • To learn on mp4hls attribute you can refer to this page.

Thanks for reading! If you have any doubt regarding this feel free to add in the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *