Skip to content

Transcoding command

Andrea Araldo edited this page Jun 11, 2020 · 8 revisions

The transcoding command uses the ffmpeg executable which documentation can be found here.

The command is called via the subprocess.call method in the main.py file. It is constructed beforehand by the GetABRCommand method defined in abr_hls_dash.py.

These files, as well as messaging.py and zkstate.py, are copied from /xcode-server/software (or /xcode-server/hardware, depending on the deployment configuration) to the /home directory of the container. main.py is executed with the container, ie. the Dockerfile ends with something like RUN bash -c /home/main.py.

What it does

The command transcodes the video file in all the following representations.

RENDITIONS_SAMPLE = (
    # resolution  bitrate(kbps)  audio-rate(kbps)
    [3840, 2160, 14000000, 192000],
    [2560, 1440, 10000000, 192000],
    [1920, 1080, 5000000, 192000],
    [1280, 720, 2800000, 192000],
    [842, 480, 1400000, 128000],
    [640, 360, 800000, 128000]
)

For instance, the included video file bbb_sunflower_1080p_30fps_normal.mp4, which is in 1080p, will be transcoded simultaneously into 4 streams: 1080p, 720p, 480p, 360p.

TODO: Go further into the explanation of the ffmpeg command construction

Result

The command for transcoding this file is quite long. It is executed from the Docker container which name starts with k8s_vod0-service_vod0-service-... (use sudo docker ps --no-trunc --filter name=k8s_vod0-service_vod0-service- to get its full name and ID).

To get the entire command, we print it from the python code before it is executed. This is how it looks like:

/usr/bin/ffmpeg -hide_banner -y -i /var/www/archive//bbb_sunflower_1080p_30fps_normal.mp4 -c:v libx264 -profile:v main -sc_threshold 0 -strict -2 -g 30 -keyint_min 30 -map 0:v -b:v:0 5000k -s:v:0 1920x1080 -maxrate:0 5350k -bufsize:0 7500k -an -map 0:v -b:v:1 2800k -s:v:1 1280x720 -maxrate:1 2996k -bufsize:1 4200k -an -map 0:v -b:v:2 1400k -s:v:2 842x480 -maxrate:2 1498k -bufsize:2 2100k -an -map 0:v -b:v:3 800k -s:v:3 640x360 -maxrate:3 856k -bufsize:3 1200k -an -f dash -use_timeline 1 -use_template 1 -seg_duration 2 -y /var/www/dash/bbb_sunflower_1080p_30fps_normal.mp4/index.mpd

- written on March 19, 2020

Clone this wiki locally