Sub topic 2
Building the Transcoding Pipeline
Assume you know HTTP, object storage, message queues, and basic shell or Python. The pipeline converts one uploaded source into several playback-ready renditions.
Transcoding pipeline
A worker consumes a job from a queue, downloads the source from object storage, and runs a media encoder such as FFmpeg. Each rendition has its own resolution, bitrate, codec settings, and segments.
ffmpeg -i input.mp4 \
-vf scale=-2:720 \
-c:v libx264 -preset medium -b:v 2800k -maxrate 3000k -bufsize 6000k \
-g 48 -keyint_min 48 -sc_threshold 0 \
-c:a aac -b:a 128k \
-f hls -hls_time 4 -hls_playlist_type vod \
-hls_segment_filename "720p/seg_%04d.ts" \
720p/index.m3u8The worker writes output to a temporary location, validates it, and then publishes a completion event. Idempotent jobs are important: retrying a failed job must not create conflicting files.
Choosing a bitrate ladder
A bitrate ladder is the set of renditions offered to the player. Higher renditions improve quality but require more storage, encoding time, and network capacity.
| Rendition | Typical video bitrate | Use |
|---|---|---|
| 360p | 800 kbit/s | Slow networks and small screens |
| 720p | 2,800 kbit/s | General HD playback |
| 1080p | 5,500 kbit/s | Fast networks and large screens |
Choose levels from measured device, network, and content data. Keep keyframe intervals aligned across renditions so switching happens cleanly.
Segmenting and packaging
HLS and DASH divide media into short segments and expose a manifest. HLS uses an .m3u8 playlist. DASH commonly uses an .mpd manifest. Four-to-six-second segments balance startup delay, request overhead, and switching speed.
Storage, metadata, and CDN delivery
Store immutable segments and manifests in object storage. Keep metadata in a database:
- Video ID, title, duration, and publication state
- Source and rendition locations
- Codec, resolution, bitrate, and segment duration
- Transcoding status and error details
Put a CDN in front of the object store. Cache manifests for a short period and segments for a long period. Configure cache keys, range requests, CORS, and access control carefully.
Exercise
Why should segments use longer cache lifetimes than manifests?
Show answer
Segments are immutable after publishing, while manifests may change as new renditions or availability information is added.