Converting MP4 H.264 file to HLS format using FFmpeg
This article provides a detailed guide on converting an MP4 H.264 video file into HLS format using FFmpeg. The process works on Windows 11 computers, Windows 11 VM (local), and Windows Server VM (local & Azure).
Prerequisites
Before you begin, ensure you have the following:
- FFmpeg installed on your system.
- An MP4 H.264 video file to convert.
Step 1: Install FFmpeg
If you haven't installed FFmpeg yet, you can download it from the official website: https://www.ffmpeg.org/download.html
Step 2: Convert MP4 to HLS
Open your command prompt or PowerShell, navigate to the directory containing your MP4 video file, and run the following command:
ffmpeg -i input.mp4 -codec:a aac -ab 128k -b:v 3M -max_delay 0 -flags +global_header -hls_time 10 -hls_playlist_type vod output.m3u8
Replace input.mp4 with the name of your MP4 video file, and output.m3u8 with the desired name for the output HLS playlist file.
Explanation of the command
-i input.mp4: Specifies the input file.-codec:a aac -ab 128k: Sets the audio codec to AAC and the audio bitrate to 128k.-b:v 3M: Sets the video bitrate to 3Mbps.-max_delay 0: Sets the maximum delay to 0.-flags +global_header: Enables the global header.-hls_time 10: Sets the HLS segment duration to 10 seconds.-hls_playlist_type vod: Sets the HLS playlist type to Video on Demand (VOD).output.m3u8: Specifies the output HLS playlist file name.
Step 3: Verify the Output
After running the command, you should see the output HLS playlist file (output.m3u8) in the same directory as your input MP4 file. You can open this file in a text editor to verify its content.
References
- FFmpeg Official Website: https://www.ffmpeg.org/
- FFmpeg HLS Documentation: https://ffmpeg.org/trac/ffmpeg/wiki/HLS
- Convert MP4 to HLS using FFmpeg: https://www.digitalocean.com/community/tutorials/how-to-stream-video-with-hls-using-ffmpeg
Note
This article covers the basic steps to convert an MP4 H.264 video file into HLS format using FFmpeg. For more advanced options, you can refer to the FFmpeg documentation.
This guide works on Windows 11 computers, Windows 11 VM (local), and Windows Server VM (local & Azure).
<ul>
<li>FFmpeg Official Website: <a href="https://www.ffmpeg.org/">https://www.ffmpeg.org/</a></li>
<li>FFmpeg HLS Documentation: <a href="https://ffmpeg.org/trac/ffmpeg/wiki/HLS">https://ffmpeg.org/trac/ffmpeg/wiki/HLS</a></li>
<li>Convert MP4 to HLS using FFmpeg: <a href="https://www.digitalocean.com/community/tutorials/how-to-stream-video-with-hls-using-ffmpeg">https://www.digitalocean.com/community/tutorials/how-to-stream-video-with-hls-using-ffmpeg</a></li>
</ul>