Creating Adaptive Streaming Files (.mpd/.m3u8) for Video on Server Using FFMPEG

Mayur Solanki
3 min readFeb 22, 2019

--

Steps which you should follow to generate the adaptive streaming link. Android Exoplayer supports only .mpd/.m3u8 for adaptive streaming

  1. Install XAMPP/LAMP/WAMP on your local or dedicated server like AWS.
  2. Install the FFMPEG library on your server.
    To install FFMPEG on the server follow the below links.
    https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
    https://www.ffmpeg.org/download.html
    https://linuxize.com/post/how-to-install-ffmpeg-on-ubuntu-18-04/
  3. After installation complete the link here which contains a command to process the mp4 video file and generate .ts files for the m3u8 file.
  4. once using commands, all m3u8 files are generated for different types of resolutions, add them into one main file by reference and create the main m3u8 file.
  5. finally, you have the server path of that one m3u8 file only and Exoplayer should link to that file.
after processing video using ffmpeg

FFMPEG Commands to process mp4 video

240x320

360x640

480x800

540x960

Step 1. Create one folder/directory with the name of the video

step 2. Put the mp4 video in that folder

step 3. Start performing the following operation

Note: use the below command

ffmpeg -i ../sample.mp4 -c:a aac -strict experimental -c:v libx264 -s 854x480 -aspect 16:9 -f hls -hls_list_size 1000000 -hls_time 2 480_out.m3u8
  1. For 240x320
ffmpeg -i big_bunny.mp4 -c:a aac -strict experimental -c:v libx264 -s 240x320 -aspect 16:9 -f hls -hls_list_size 1000000 -hls_time 2 240_out.m3u8

2. For 360x640

ffmpeg -i big_bunny.mp4 -c:a aac -strict experimental -c:v libx264 -s 360x640 -aspect 16:9 -f hls -hls_list_size 1000000 -hls_time 2 360_out.m3u8

3. For 480x800

ffmpeg -i big_bunny.mp4 -c:a aac -strict experimental -c:v libx264 -s 480x800 -aspect 16:9 -f hls -hls_list_size 1000000 -hls_time 2 480_out.m3u8

4. For 540x960

ffmpeg -i big_bunny.mp4 -c:a aac -strict experimental -c:v libx264 -s 480x800 -aspect 16:9 -f hls -hls_list_size 1000000 -hls_time 2 540_out.m3u8

After performing 4 resolution commands four distinct .m3u8 files will be generated.

now create one .m3u8 file with a playlist manually or by programmatically

For example,
i.e {{videoname}}.m3u8

Add below text in that final m3u8 file (playlist.m3u8)

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=700000
240_out.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=1000000
360_out.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=2000000
480_out.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=2000000
540_out.m3u8

Now your final m3u8 file like

after processing video using ffmpeg

And now the final m3u8 file link would be like

http://13.127.14.184/adaptive/bigbunny/playlist.m3u8
Click setting button

Github repository link

https://github.com/MayurSolanki/AdaptiveStreamingExoplayer

Check out the latest code from the above link and just replace the .m3u8 link with your m3u8 link.

video link

If you want to learn how to integrate in Exoplayer then follow the below link

https://medium.com/@mayur_solanki/adaptive-streaming-with-exoplayer-c77b0032acdd

--

--

Mayur Solanki

Android | NestJS | Angular | Spring Boot | MongoDB | Java | Kotlin |Typescript | AWS | Flutter | Javascript | Dart | Swift