Converting MP4 H.264 file to HLS format using FFmpeg
Works on Windows 11, 10 computers, works on Windows 11 VM (local) as well as on Windows Server VM (local) in Azure.
Introduction
HLS (HTTP Live Streaming) is an adaptive bitrate streaming communication protocol developed by Apple Inc. It is designed to stream and deliver media over the internet. This protocol is used to deliver video and audio over HTTP, and it is particularly useful for mobile devices.
In this article, we will learn how to convert an MP4 H.264 file to HLS format using FFmpeg, a free and open-source software project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams.
Prerequisites
Before we begin, ensure that you have the following prerequisites:
- A Windows 11, 10 computer or a Windows 11 VM (local) or Windows Server VM (local) in Azure.
- FFmpeg installed. You can download the latest version from the official FFmpeg website.
Converting MP4 H.264 file to HLS format
-
Open the Command Prompt (cmd) or PowerShell on your Windows machine.
-
Navigate to the directory where your MP4 file is located using the
cdcommand. -
Run the following command to convert the MP4 file to HLS format:
ffmpeg -i input.mp4 -c:v libx264 -profile:v main -level 3.1 -s 1280x720 -f hls -hls_time 10 -hls_flags dynamic -hls_playlist_type vod -strftime 1 "%Y-%m-%dT%H:%M:%SZ" output/index.m3u8 output/0000.ts
Replace input.mp4 with the name of your MP4 file, and output with the directory where you want to save the HLS files.
This command does the following:
-i input.mp4specifies the input file.-c:v libx264sets the video codec to H.264.-profile:v mainsets the video profile to main.-level 3.1sets the video level to 3.1.-s 1280x720sets the video resolution to 1280x720.-f hlssets the output format to HLS.-hls_time 10sets the segment duration to 10 seconds.-hls_flags dynamicenables dynamic segment naming.-hls_playlist_type vodsets the playlist type to VOD (Video on Demand).-strftime 1 "%Y-%m-%dT%H:%M:%SZ"sets the timestamp format.
Summary
In this article, we learned how to convert an MP4 H.264 file to HLS format using FFmpeg on Windows 11, 10 computers, Windows 11 VM (local), and Windows Server VM (local) in Azure. This process can be useful for streaming video content over the internet, particularly for mobile devices.