How to Convert MP4 to HLS

HTTP Live Streaming, or HLS, is a popular live-streaming and on-demand video technology developed by Apple. HLS uses the HTTP protocol which allows users to stream from a regular web server as opposed to specialized streaming servers. KeyCDN helps accelerate HLS live streams by offering an Optimize for HLS option within all Pull Zones.

For those who have MP4 files and want to convert them to HLS, this article covers how to do so using FFmpeg as well as with an alternative software.

What is FFmpeg?

FFmpeg is a multimedia framework able to “decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created”. Installing FFmpeg onto your machine will give you all of the aforementioned capabilities, however this article will focus on FFmpeg’s Muxers. Muxers allow you to write multimedia streams to a particular file type, in this case MP4 to HLS.

Converting MP4 to HLS With FFmpeg

The following example will show how to install and get start using FFmpeg on OS X.

  1. Open up your terminal and install Homebrew (a package manager for OS X) if you don’t already have it. This can be done by running the following command.
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Once Homebrew has been downloaded and installed, run the command below to download FFmpeg and all of it’s dependencies.

    brew install ffmpeg

FFmpeg is now running on your machine and you can begin converting files. Using FFmpeg’s HLS muxer works by creating a playlist as well as one or more segment files. The name specified for the output file will be the name of the playlist (or .m3u8 file) while the .ts files will also be named after the playlist followed by a sequential number. The following example takes an MP4 file (input.mp4), defines several HLS options and specifies the output playlist file as “index”.

ffmpeg -i input.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index.m3u8

Upon running the above command you will see the MP4 video being processed in the terminal which will look similar to the following.

ffmpeg-mp4-to-hls-conversion

The options in the above command to convert MP4 to HLS can be modified to your liking. Use the FFmpeg HLS options guide to define a more granular configuration.

Alternative to Convert MP4 to HLS

For Windows users there is an alternative available to convert MP4 to HLS without using FFmpeg. This involves using a piece of software called Pavtube Video Converter. The conversion process using this method is quite straightforward in that you simply add your video to the program, and choose your output file format. For a more comprehensive tutorial on how to convert to HLS using Pavtube, read their article How to Convert Any Video to M3U8 for Streaming to Apple TV.

One Comment

Leave A Comment?