DEV Community


Posted on

Producing dash streming using ffmpeg and bento4

Dash is the open-source equivalent of Apple's HLS technology, used for the same purpose: to deliver live videos or on-demand videos over the web, dynamically changing the quality based on the internet connection of the final user.

Following formula will produce a multi-bit-rate version of our master with h264 constrained encoding

ffmpeg -i input.mp4 -c:v h264 -crf 22 -tune film -profile:v main -level:v 4.0 -maxrate 5000k -bufsize 10000k -r 25 -keyint_min 25 -g 50 -sc_threshold 0 -c:a aac -ar 44100 -b:a 128k -ac 2 -pix_fmt yuv420p -movflags +faststart 1080.mp4 -s 1280x720 -c:v h264 -crf 24 -tune film -profile:v main -level:v 4.0 -maxrate 2500k -bufsize 5000k -r 25 -keyint_min 25 -g 50 -sc_threshold 0 -c:a aac -ar 44100 -b:a 128k -ac 2 -pix_fmt yuv420p -movflags +faststart 720.mp4 -s 854x480 -c:v h264 -crf 30 -tune film -profile:v main -level:v 4.0 -maxrate 1250k -bufsize 2500k -r 25 -keyint_min 25 -g 50 -sc_threshold 0 -c:a aac -ar 44100 -b:a 96k -ac 2 -pix_fmt yuv420p -movflags +faststart 480.mp4 -s 640x360 -c:v h264 -crf 33 -tune film -profile:v main -level:v 4.0 -maxrate 900k -bufsize 1800k -r 25 -keyint_min 25 -g 50 -sc_threshold 0 -c:a aac -ar 44100 -b:a 96k -ac 2 -pix_fmt yuv420p -movflags +faststart 360.mp4 -s 320x24 -c:v h264 -crf 36 -tune film -profile:v main -level:v 4.0 -maxrate 625k -bufsize 1250k -r 25 -keyint_min 25 -g 50 -sc_threshold 0 -c:a aac -ar 22050 -b:a 64k -ac 1 -pix_fmt yuv420p -movflags +faststart 240.mp4
Enter fullscreen mode Exit fullscreen mode

All tags described in my previous blog

Create multi-bitrate DASH playlist with Bento4

In order to create a multi-bitrate DASH playlist with Bent04, we need to perform 2 separate action.

  • First one dedicated at the fragmentation of each file(version) of our master video, mp4fragment command will responsible for this task

Sample command:

mp4fragment 1080.mp4 1080-f.mp4

mp4fragment: this will launch Bento4's Mp4 Fragment tool
1080.mp4: this is the input file to be fragmented
1080-f.mp4: this is an example output's filename

Now we have to repeat this command for each version of our master video

mp4fragment 1080.mp4 1080-f.mp4&&mp4fragment 720.mp4 720-f.mp4&&mp4fragment 480.mp4 480-f-.mp4&&mp4fragment 360.mp4 360-f.mp4&&mp4fragment 240.mp4 240-f.mp4
Enter fullscreen mode Exit fullscreen mode

Generate DASH playlist

In order to generate a DASH playlist with our segmented mp4s, we will use another tool from Bento4 called mp4dash using following command:

mp4dash 240-f.mp4 360-f.mp4 480-f.mp4 720-f.mp4 1080-f.mp4
Enter fullscreen mode Exit fullscreen mode

This will generate a folder titled "output" which will
contain 2 separate folders: one called "audio" dedicated for the audio streaming and another called "video" containing the segments of each of the 5 variations of our master video. And finally we will find the "stream.mpd" file which is the DASH playlist itself.

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.