Installation

This page describes installing needed components on a linux host system. For Docker example see docker-compose.yml.

System requirements

  1. ffmpeg

  2. mediainfo

apt-get install ffmpeg mediainfo

Python requirements

pip install django-video-transcoding

Django integration

Add video_transcoding to project settings

INSTALLED_APPS.append("video_transcoding")

Celery configuration

video_transcoding.celery contains Celery application that can use environment variables for configuration. This application can be used as a starting point for configuring own app.

| env | description | |——————————————-|——————–| | VIDEO_TRANSCODING_CELERY_BROKER_URL | celery broker | | VIDEO_TRANSCODING_CELERY_RESULT_BACKEND | result backend | | VIDEO_TRANSCODING_CELERY_CONCURRENCY | worker concurrency |

Proper shutdown

Processing video files is a very long operation, so waiting for celery task complition while shutting down is inacceptable. On the other hand, if celery worker processes are killed, lost tasks an zombie ffmpeg processes may appear.

For correct soft shutdown, a USR1 signal must be passed to celery child processes. This signal is treated by celery internals as SoftTimeLimitExceeded exception, and django-video-transcoding handles it terminating ffmpeg child processes correctly.

import os, signal
from celery.signals import worker_shutting_down

@worker_shutting_down.connect
def send_term_to_children(**_) -> None:
    os.killpg(os.getpid(), signal.SIGUSR1)

Video origin and edge hosts

Serving video-on-demand content in the Internet requires special segmenting software to make HLS or MPEG/Dash fragments from mp4 files. It may be nginx with Kaltura nginx-vod-module or anything else.

Setting up nginx

There is an example of nginx setup for docker in deploy/storage which can be used as starting point, and that’s all. Streaming protocols are not a part of this project, as this part is very specific for each project.

Getting video sources

django-video-transcoding supports downloading video sources from any link that can be handled with requests library. It’s recommended to use HTTP-enabled storage.

As ffmpeg can use HTTP links directly, there is a flag allowing to skip source download step and start transcoding immediately:

export VIDEO_DOWNLOAD_SOURCE=1

Storing transcoding results

django-video-transcoding stores transcode results by HTTP PUT request, so results storage must support it. nginx with dav module is preferred.

For rendundancy, multiple storage hosts are supported:

export VIDEO_ORIGINS=http://storage-1/writable/,http://storage-2/writable/