Transforming MP4 File to HTTP Live Stream File

As the name sounds http live streaming (HLS) means streaming of files using http protocol. Apple introduced this in iOS 3.0. where video, audio and streaming files can be streamed over http. Though there are lot of technicalities involved in HLS, the simple thing is the file or stream is converted into small chunks and passed over http for http live streaming.

HTTP Live Streaming (HLS) sends media files (audio/video) as a sequential group of small files about 10 seconds duration known as media segment files (.ts extension). An index file (.m3u extension) which holds the URL of media segment files. This index file (.m3u extension) can be used in the web page for HTTP live streaming.

HTTP-Live-Streaming

Where I am going to explain how to convert MP4 file for http live streaming using in windows environment with FFMPEG:
1.Download the FFMPEG:
Download the FFMPEG file from the FFMPEG download page. If you are on Windows then download the windows version. In case of Linux download the Linux version.

2.Download the HLS Segmenter for Windows:
You can search on Google to find list of sites where you can download the HLS segmenter file. You can use the Apple’s developer ID and password to download the HLS segmenter from their site. There is one more Windows version of httpsegmenter from Google that you can download from the link here. You can use any other http segmenter from web for the same purpose. If you don’t file the segmenter file don’t worry. The latest FFMPEG can convert the file to segments using the FFMPEG command.

3.Convert the MP4 file to HLS format:
Now run the command prompt using cmd. Go to bin directory of the FFMPEG from the command prompt. Type ffmpeg –h to find various option of the ffmpeg. Use the correct option convert the file into desired format. Here is one example how you can convert the mp4 file to .ts file.

ffmpeg -i myvideo.mp4  -acodec libfaac -ar 48000 -ab 64k -s 320×320 -vcodec libx264 -vbsf h264_mp4toannexb -f mpegts myvideo.ts
Above command will convert your MP4 file to .ts format. Check the FFMPEG manual for various options for audio/video codec. Now use the segmenter to segment the file to desired seconds as shown below. For detail command option just run the segmenter from command prompt.

segmenter -i myvideo.ts -d 20 -o la -x test/myvideo.m3u8
This command will convert your .ts file into smaller segments (20 second here) and will generate one index file having .m3u8 extension. If you don’t have segmenter file, then use the following command to convert the file to HLS format using FFMPEG.

ffmpeg -i myvideo.mp4  -c:a libmp3lame -ar 48000 -ab 64k  -c:v libx264   -b:v 96k -flags -global_header -map 0 -f segment  -segment_list myvideo.m3u8 -segment_format mpegts str%05d.ts
This will generate an index file with m3u8 and a list of .ts file. Next is how to host in the Web Server to play the file over http.

4.Host the application on web server.
Now you can use your local web server(IIS, Apache). Before that you need to configure the web server for the mime type. In IIS server add two new mime type in the http header property. In case if apache add the property to the .htaccess file.
.M3U8
application/x-mpegURL
.ts   video/MP2T
Now create a web page to test the application. Put the following text in the application.

hls

Now open the web page on a browser that supports http live streaming.

If you are not a professional technical guy, I have another method for converting MP4 file to HLS file easier than FFMPEG on Windows operating system. The method we mentioned above is a little difficult for our green hands. Having tested so much, I found a top-ranked HLS Converter for Windows is highly recommended- Pavtube Video Converter (version 4.8.6.2).

How to convert MP4 file to HLS file?

Step 1: Download and install the program. Click “Add video” on the main interface to load your MP4 files to the program. You can also drag the files to the program’s window list directly. This program can also support the batch video clips.



Step 2: Click the “Format” bar to get the drop-down menu and you can get “HLS Streaming (m3u8)”. Choose “ipad m3u8 streaming” or “iphone m3u8 streaming” as best output format. Any media player supporting TS format are all available for playing M3U8 format files.



Step 3: Click “Settings” button to customize the output video and audio settings by yourself. Video codec is the default H.264 and audio codec is the default AAC. You can change the resolution, bit rate, frame rate as you need. But if you are not good at it, you’d better use the default parameters, they will ensure you a good balance between file size and image quality basically.

Step 4: When everything is done, you can take a preview by hitting “Play” button. If you are satisfied with the final result, you can click “Convert” button to finish the conversion work.

Conclusion: From the two measures we mentioned above, I don’t know which one you will like as the best. But frankly speaking, if you are not familiar with video to HLS conversion, I suggest you to choose the easiest one. Pavtube Video Converter can do you a big favor. Such an easy operation that all of us can do well.

Further Reading:

Leave a Reply

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

What You May be Interested

Pavtube iMedia Converter

The most advanced yet easy-to-use tool for converting Blu-ray, DVD, ISO, Video to various video/audio formats for backup, editing, playing, sharing, etc.

Pavtube Video Converter

Converting common, HD, 3D, 4K videos to compatible with FCP, iMovie, FCE, Avid, Adobe, VR, Game, TV, Youtube, Media Player, TV Box, Storages, etc.