How to create .mpd or .m3u8 video file on the server using FFMPEG for Adaptive Streaming

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 FFMPEG library on your server. To install ffmpeg on server follow 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 command to process mp4 video file and generate .ts files for m3u8 file.
  4. once using commands , all m3u8 files are generated for different different types of resolutions , add them into one main file by reference and create main m3u8 file.
  5. and 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 name of video

step 2. put mp4 video in that folder

step 3. start performing following operation

Note : use 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 playlist manually or by programatically

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 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 above link and just replace .m3u8 link by your own 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