Part 4 of 8 · 2 min read
Transcoding
One upload, many versions.
Transcoding (also called encoding) converts a video into other formats and quality levels. It is needed for four reasons.
- Raw video is huge. An hour of high-definition video at 60 frames a second can take a few hundred GB.
- Many devices and browsers support only some formats.
- Viewers with fast connections can have high resolution, and slow connections need lower.
- Network speed on phones changes, so the player must be able to switch quality as it plays.
Bitrate is the number of bits processed per second. A higher bitrate usually means better quality, and needs more processing and a faster connection.
A video format has two parts. The container is the basket that holds the video, audio and metadata, and is shown by the file ending such as .mp4. The codec is the method that compresses and decompresses, such as H.264, VP9 or HEVC.
A worked example (made up). A creator uploads one 300 MB video. The system makes versions at 360p, 720p and 1080p, each in two formats. That is 6 output files, so one upload leads to 7 files in storage when the original is counted.
Task graphs. Creators have different needs: some want a watermark, some supply their own thumbnail, some upload high definition. To keep this flexible, the book uses a directed acyclic graph (DAG) model, as Facebook's video engine does. A DAG is a set of tasks joined by arrows that show order, with no loops. Tasks without a link can run at the same time.
Possible tasks: inspection (check the file is good and not damaged), encoding to each format, making a thumbnail, and adding a watermark.
Directed acyclic graph (DAG)
A DAG is a set of steps joined by one-way arrows with no cycles, so every step runs after the ones that lead to it, and steps without a link can run in parallel.
Example: video encoding and thumbnail creation both follow "split the file", and neither waits for the other.
Check yourself: 1. What is the difference between a container and a codec? 2. Why does a DAG help here? 3. Why is more than one output version needed?