Creating Adaptive Streaming Files (.mpd/.m3u8) for Video on Server Using FFMPEG
Steps which you should follow to generate the adaptive streaming link. Android Exoplayer supports only .mpd/.m3u8 for adaptive streaming
- Install XAMPP/LAMP/WAMP on your local or dedicated server like AWS.
- 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/ - After installation complete the link here which contains a command to process the mp4 video file and generate .ts files for the m3u8 file.
- 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.
- finally, you have the server path of that one m3u8 file only and Exoplayer should link to that file.
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
- 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
And now the final m3u8 file link would be like
http://13.127.14.184/adaptive/bigbunny/playlist.m3u8
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