Operations 11 min read

Design and Implementation of a Self‑Developed Video Transcoding Core Based on FFmpeg

This article describes the motivations, architecture, and key techniques of a custom video transcoding core built on FFmpeg, covering modular pipeline design, controllable serial/parallel execution, dynamic resolution and frame‑rate adaptation, SEI handling, and performance improvements for both live and on‑demand streaming.

Architect
Architect
Architect
Design and Implementation of a Self‑Developed Video Transcoding Core Based on FFmpeg

Video transcoding converts uploaded video files into multiple resolutions with lower bitrates to improve network smoothness and device compatibility; FFmpeg is the most widely used server‑side framework, offering command‑line tools and core libraries for demuxing, decoding, filtering, encoding, and muxing.

However, the native FFmpeg command‑line tool exhibits several limitations for large‑scale transcoding: serial pipelines cannot fully utilize multi‑core CPUs for multi‑resolution jobs, live streams cannot update parameters dynamically, the codebase is monolithic and hard to maintain, and version upgrades involve costly migrations. Therefore, a self‑developed transcoding core was created to replace the FFmpeg command‑line tool.

The custom core uses FFmpeg's foundational libraries for low‑level media processing while abstracting pipeline modules. A Controller module handles frame scheduling and distinguishes between live and on‑demand workflows. Live streaming requires complex scheduling (timed frame fetching, dynamic input/output changes), whereas VOD follows a simpler input‑output mapping.

Each Task class inherits from a common PipelineWorker base and can run either serially or in parallel; parallel Workers spawn dedicated threads for frame handling. The choice of execution mode depends on business requirements and the internal parallelism of the Task.

For live transcoding, parallel execution mitigates blocking risks in high‑concurrency scenarios, and Task queues trigger frame dropping when thresholds are exceeded to maintain stream stability.

For VOD transcoding, the decision between serial and parallel modes balances CPU utilization against thread‑switch overhead, selecting the optimal strategy based on each Task's characteristics.

The core also supports dynamic adaptation of resolution and frame rate. In live streams using FLV + RTMP, input resolution may change at any time; the system detects such changes and updates filter, encoder, and muxer parameters accordingly. Scale filters use a zoom‑preserving algorithm, and filter parameters are expressed via FFmpeg's expression language to handle diverse filter types.

Frame‑rate adaptation employs VFR sampling, with a special VFR‑HALF mode that halves the target frame rate when the source exceeds the target, ensuring uniform sampling and reducing visual stutter.

SEI (Supplemental Enhancement Information) handling is enhanced: the custom core inserts SEI data after encoding via a BSF filter, supports merging or discarding SEI based on configuration, and records SEI throughout the live transcoding lifecycle for downstream analytics.

In summary, the self‑developed transcoding core addresses FFmpeg command‑line shortcomings, supports live and VOD scenarios, and continues to evolve with AI‑driven features, finer‑grained pipeline optimizations, and broader application coverage.

Live StreamingFFmpegParallel Processingvideo transcodingPipeline Architecturedynamic adaptation
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.