How to Convert MP4 to HLS Playlist Using FFmpeg

Converting an MP4 video into an HTTP Live Streaming (HLS) playlist using FFmpeg on Linux allows you to deliver adaptive bitrate streaming to your viewers, optimizing playback for various internet speeds. This guide provides a straightforward, step-by-step terminal command to split your video into standard .ts segments and generate the necessary .m3u8 index file. By the end of this article, you will have a web-ready streaming setup deployed directly from your Linux command line.

Prerequisite: Install FFmpeg

Before running the conversion command, ensure you have FFmpeg installed on your Linux system. You can verify your installation or install it using your package manager.

The Core FFmpeg Command

To convert a standard input.mp4 file into an HLS playlist, navigate to the directory containing your video and run the following command:

ffmpeg -i input.mp4 -codec:v libx264 -codec:a aac -map 0 -f hls -hls_time 10 -hls_playlist_type vod -hls_segment_filename "stream_%03d.ts" playlist.m3u8

Breakdown of the Command Options

Understanding what each flag does will help you customize the output to match your specific streaming requirements:

Verifying the Output Files

Once the processing completes, check your target directory. You will see a collection of files generated by the command:

To serve these files to the public, you simply upload the entire batch of .ts files alongside the .m3u8 file to your web server or cloud storage bucket, ensuring the directory structure remains intact.