Example of Running FFmpeg for VoD Content Preparation
The sequence of commands for the source HD content transcoding to 5 video bitrates and 3 audio bitrates is given below (the source file contains 2 audio tracks). To demonstrate the switching between bitrates, each output file will be overlaid with text indicating the resolution and bitrate. It is supposed that:
- the target directory path should be defined in OUTDIR variable;
- the source file path should be defined in the INFILE variable.
Bash (Unix Shell) |
mkdir -p $OUTDIR ffmpeg -threads 2 -y -i “$INFILE“ -filter_complex “[0:v]split=5[r1][r2][r3][r4][r5]; [r1]drawtext=fontfile=DroidSansMono.ttf:text=’1920×1080 4500 Kbps’:fontcolor=white:shadowcolor=black:shadowx=2:fontsize=24:x=15:y=1026,scale=1920:1080[v1]; [r2]drawtext=fontfile=DroidSansMono.ttf:text=’1920×1080 3300 Kbps’:fontcolor=white:shadowcolor=black:shadowx=2:fontsize=24:x=15:y=1026,scale=1920:1080[v2]; [r3]drawtext=fontfile=DroidSansMono.ttf:text=’1280×720 2500 Kbps’:fontcolor=white:shadowcolor=black:shadowx=2:fontsize=24:x=15:y=1026,scale=1280:720[v3]; [r4]drawtext=fontfile=DroidSansMono.ttf:text=’720×576 2400 Kbps’:fontcolor=white:shadowcolor=black:shadowx=2:fontsize=24:x=15:y=1026,scale=720:576[v4]; [r5]drawtext=fontfile=DroidSansMono.ttf:text=’720×576 2000 Kbps’:fontcolor=white:shadowcolor=black:shadowx=2:fontsize=24:x=15:y=1026,scale=720:576[v5]; [0:a:0]asplit=3[ar1][ar2][ar3]; [0:a:1]asplit=3[ae1][ae2][ae3]” -map [v1] -an -pix_fmt yuv420p -vcodec libx264 -preset medium -b:v 4500k -minrate 4500k -maxrate 4500k -bufsize 4500k -x264-params keyint=72:min-keyint=72:scenecut=0 $OUTDIR/vid_bw4500000.mp4 -map [v2] -an -pix_fmt yuv420p -vcodec libx264 -preset medium -b:v 3300k -minrate 3300k -maxrate 3300k -bufsize 3300k -x264-params keyint=72:min-keyint=72:scenecut=0 $OUTDIR/vid_bw3300000.mp4 -map [v3] -an -pix_fmt yuv420p -vcodec libx264 -preset medium -b:v 2500k -minrate 2500k -maxrate 2500k -bufsize 2500k -x264-params keyint=72:min-keyint=72:scenecut=0 $OUTDIR/vid_bw2500000.mp4 -map [v4] -an -pix_fmt yuv420p -vcodec libx264 -preset medium -b:v 2400k -minrate 2400k -maxrate 2400k -bufsize 2400k -x264-params keyint=72:min-keyint=72:scenecut=0 $OUTDIR/vid_bw2400000.mp4 -map [v5] -an -pix_fmt yuv420p -vcodec libx264 -preset medium -b:v 2000k -minrate 2000k -maxrate 2000k -bufsize 2000k -x264-params keyint=72:min-keyint=72:scenecut=0 $OUTDIR/vid_bw2000000.mp4 -map [ar1] -vn -strict -2 -acodec aac -ab 192k -ac 2 -ar 48000 $OUTDIR/aud_rus_192.mp4 -map [ar2] -vn -strict -2 -acodec aac -ab 128k -ac 2 -ar 48000 $OUTDIR/aud_rus_128.mp4 -map [ar3] -vn -strict -2 -acodec aac -ab 96k -ac 2 -ar 48000 $OUTDIR/aud_rus_096.mp4 -map [ae1] -vn -strict -2 -acodec aac -ab 192k -ac 2 -ar 48000 $OUTDIR/aud_eng_192.mp4 -map [ae2] -vn -strict -2 -acodec aac -ab 128k -ac 2 -ar 48000 $OUTDIR/aud_eng_128.mp4 -map [ae3] -vn -strict -2 -acodec aac -ab 96k -ac 2 -ar 48000 $OUTDIR/aud_eng_096.mp4 |
the text will be rendered with the DroidSansMono.ttf font. This font file shall be present in the current directory. You can also use any other available TTF font. |
Subtitlings for VoD must be provided in the WebVTT format. Subtitling files should be copied to the output directory manually (also they need to be specified at the content package stage, see below). To convert SRT subtitlings to WebVTT you can also use ffmpeg:
ffmpeg -i Tears of Steel 2012 2160p DM FLAC 5.1 Hi444PP 10-bit x264-DON.mkv -map 0:s:0 -vn -an -scodec webvtt subtitles.vtt
The subtitles.vtt file containing the first (in sequence) subtitling track will be created.