COMMON_OPTS="-map 0:0 -an -threads 11 -cpu-used 4 -cmp chroma"
MP4_OPTS="-f mp4 -c:v libx264 -movflags +faststart -strict -2 -x264opts scenecut=0:open_gop=0:bframes=0:min-keyint=89:keyint=89 -flags +loop+cgop -profile:v baseline -level:v 3.0"
WEBM_OPTS="-f webm -c:v vp9 -keyint_min 89 -g 89 -dash 1"
# Encode MP4 in 4 resolutions:
ffmpeg -i sun.mp4 $COMMON_OPTS $MP4_OPTS \
-b:v 1000k -vf scale=640:480 -y output/v-0480p-1000k-libx264.mp4
ffmpeg -i sun.mp4 $COMMON_OPTS $MP4_OPTS \
-b:v 750k -vf scale=480:360 -y output/v-0360p-0750k-libx264.mp4
ffmpeg -i sun.mp4 $COMMON_OPTS $MP4_OPTS \
-b:v 400k -vf scale=320:240 -y output/v-0240p-0400k-libx264.mp4
ffmpeg -i sun.mp4 $COMMON_OPTS $MP4_OPTS \
-b:v 100k -vf scale=192:144 -y output/v-0144p-0100k-libx264.mp4
# Encode WebM in 4 resolutions:
ffmpeg -i sun.mp4 $COMMON_OPTS $WEBM_OPTS \
-b:v 750k -vf scale=640:480 -y output/v-0480p-0750k-vp9.webm
ffmpeg -i sun.mp4 $COMMON_OPTS $WEBM_OPTS \
-b:v 550k -vf scale=480:360 -y output/v-0360p-0550k-vp9.webm
ffmpeg -i sun.mp4 $COMMON_OPTS $WEBM_OPTS \
-b:v 300k -vf scale=320:240 -y output/v-0240p-0300k-vp9.webm
ffmpeg -i sun.mp4 $COMMON_OPTS $WEBM_OPTS \
-b:v 100k -vf scale=192:144 -y output/v-0144p-0100k-vp9.webm
# These outputs are only intermediate. Rename them.
cd output
rename 's/webm/tmp.webm/' *.webm
rename 's/mp4/tmp.mp4/' *.mp4
# Package the content into one manifest.
packager --profile on-demand \
input=v-0480p-1000k-libx264.tmp.mp4,stream=video,output=v-0480p-1000k-libx264.mp4 \
input=v-0360p-0750k-libx264.tmp.mp4,stream=video,output=v-0360p-0750k-libx264.mp4 \
input=v-0240p-0400k-libx264.tmp.mp4,stream=video,output=v-0240p-0400k-libx264.mp4 \
input=v-0144p-0100k-libx264.tmp.mp4,stream=video,output=v-0144p-0100k-libx264.mp4 \
input=v-0480p-0750k-vp9.tmp.webm,stream=video,output=v-0480p-0750k-vp9.webm \
input=v-0360p-0550k-vp9.tmp.webm,stream=video,output=v-0360p-0550k-vp9.webm \
input=v-0240p-0300k-vp9.tmp.webm,stream=video,output=v-0240p-0300k-vp9.webm \
input=v-0144p-0100k-vp9.tmp.webm,stream=video,output=v-0144p-0100k-vp9.webm \
--mpd_output dash.mpd
# Remove the intermediate files.
rm *.tmp.webm *.tmp.mp4