HLS & MPEG-DASH
First, you'll need a media transcoding tool. In this example, we'll use ffmpeg
, a popular command line library for media transcoding
to create an adaptive bitrate HLS and MPEG-DASH stream and use it with MovieServer.
HLS
ffmpeg -i input.mp4 \
-filter_complex "\
[0:v]split=4[1080p][720p][480p][360p];\
[1080p]scale=-2:1080[v1080p];\
[720p]scale=-2:720[v720p];\
[480p]scale=-2:480[v480p];\
[360p]scale=-2:360[v360p]" \
-map "[v1080p]" -c:v:0 libx264 -b:v:0 5000k -maxrate 5350k -bufsize 7500k -c:a aac -b:a 128k -ac 2 -y -hls_time 6 -hls_playlist_type vod -hls_segment_filename "hls/1080p/segment_%03d.ts" hls/1080p.m3u8 \
-map "[v720p]" -c:v:1 libx264 -b:v:1 3500k -maxrate 3850k -bufsize 5250k -c:a aac -b:a 128k -ac 2 -y -hls_time 6 -hls_playlist_type vod -hls_segment_filename "hls/720p/segment_%03d.ts" hls/720p.m3u8 \
-map "[v480p]" -c:v:2 libx264 -b:v:2 2000k -maxrate 2200k -bufsize 3000k -c:a aac -b:a 128k -ac 2 -y -hls_time 6 -hls_playlist_type vod -hls_segment_filename "hls/480p/segment_%03d.ts" hls/480p.m3u8 \
-map "[v360p]" -c:v:3 libx264 -b:v:3 1000k -maxrate 1100k -bufsize 1500k -c:a aac -b:a 128k -ac 2 -y -hls_time 6 -hls_playlist_type vod -hls_segment_filename "hls/360p/segment_%03d.ts" hls/360p.m3u8 \
# Create HLS Master Playlist
-f hls -y hls/master.m3u8
This command uses a filter to split the MP4 (in this case, input.mp4
) into 4 MP4 files with different resolutions, then maps them all
to segment files using the libx264
encoder (generates an H.264 output using fragmented MP4 segment formatting) along with the AAC audio codec, a 128kbps audio bitrate, a buffer size, and all for 6 seconds per segment.
Then at the end it creates a master playlist, telling our video player where each segment group per resolution is so it can utilize them to adapt to network conditions, etc, along with some extra information about the stream.
MPEG-DASH
ffmpeg -i input.mp4 \
-filter_complex "\
[0:v]split=4[1080p][720p][480p][360p];\
[1080p]scale=-2:1080[v1080p];\
[720p]scale=-2:720[v720p];\
[480p]scale=-2:480[v480p];\
[360p]scale=-2:360[v360p]" \
-map "[v1080p]" -c:v:0 libx264 -b:v:0 5000k -maxrate 5350k -bufsize 7500k -c:a aac -b:a 128k -ac 2 -y -f dash -dash_segment_filename "dash/1080p/segment_%03d.m4s" dash/1080p.mpd \
-map "[v720p]" -c:v:1 libx264 -b:v:1 3500k -maxrate 3850k -bufsize 5250k -c:a aac -b:a 128k -ac 2 -y -f dash -dash_segment_filename "dash/720p/segment_%03d.m4s" dash/720p.mpd \
-map "[v480p]" -c:v:2 libx264 -b:v:2 2000k -maxrate 2200k -bufsize 3000k -c:a aac -b:a 128k -ac 2 -y -f dash -dash_segment_filename "dash/480p/segment_%03d.m4s" dash/480p.mpd \
-map "[v360p]" -c:v:3 libx264 -b:v:3 1000k -maxrate 1100k -bufsize 1500k -c:a aac -b:a 128k -ac 2 -y -f dash -dash_segment_filename "dash/360p/segment_%03d.m4s" dash/360p.mpd
This command uses a filter to split the MP4 (in this case, input.mp4
) into 4 MP4 files with different resolutions, then maps them all
to segment files using the libx264
encoder (generates an H.264 output using fragmented MP4 segment formatting) along with the AAC audio codec, a 128kbps audio bitrate, a buffer size, and all for 6 seconds per segment.
Then at the end it creates a master manifest (created by default here), telling our video player where each segment group per resolution is so it can utilize them to adapt to network conditions, etc, along with some extra information about the stream.'
The two commands above satisfy our requirements, but if you want more you can look some up online.
An example of the finished output playing an example stream is below: