How kearcer/ffmpeg_application works
1. This repo is a small FFmpeg learning workspace with two separate execution paths: a minimal command-line transcode wrapper in src/main.cpp, and a more explicit FFmpeg API pipeline demo in src/pipeline_demo.cpp. The first path shells out to third_party/ffmpeg/bin/ffmpeg.exe; the second links directly against FFmpeg libraries.
2. The build boundary is handled by CMakeLists.txt, with a Windows/Visual Studio-oriented setup. The repo vendors the FFmpeg toolchain under third_party/ffmpeg/, including headers, import libraries, and runtime executables, so the project does not depend on a system-installed FFmpeg.
3. The simplest runtime flow is the “external process” transcode example. main.cpp builds an ffmpeg command equivalent to ffmpeg.exe -y -i input.mp4 -c:v mpeg4 -q:v 5 -c:a aac -b:a 128k output.mp4, then executes it. This path is meant to demonstrate basic transcoding without exposing FFmpeg’s C APIs.
4. The deeper architecture is the API-based video transcode pipeline. Its entry point is src/pipeline_demo.cpp, which orchestrates a five-stage media processing chain implemented in include/pipeline/ and src/pipeline/.
5. The pipeline is intentionally split into distinct subsystems that map to FFmpeg concepts:
- Demuxer handles container reading and stream extraction.
- Decoder converts compressed packets into raw frames.
- FramePreprocessor adjusts raw video frames into a form suitable for encoding, typically pixel-format or frame-shape preparation.
- Encoder converts prepared frames back into compressed packets.
- Muxer writes encoded packets into the output container.
6. The data flow in the pipeline is linear and video-centric: input file → demuxed AVPacket → decoded AVFrame → preprocessed AVFrame → encoded AVPacket → output file. The README notes that non-video streams may be present, but this demo explicitly skips them to keep the learning path focused.
7. pipeline_logger.h/.cpp provides observability for the pipeline stages. The log labels like [DEMUX IN], [DECODE OUT], [ENCODE IN], and [MUX OUT] make the internal state transitions visible, which is important because the repo is structured as a teaching aid rather than a production abstraction layer.
8. ffmpeg_helpers.h/.cpp acts as a shared utility boundary around FFmpeg boilerplate and error handling. This kind of helper layer typically centralizes repetitive API calls, format/rational conversions, and status reporting so the stage classes stay focused on their own responsibilities.
9. video_transcode_pipeline.h/.cpp is the top-level coordinator for the API demo. It composes the five stage objects into one orchestrated workflow, so the repo has a clear separation between “pipeline assembly” and “stage implementation.”
10. The media/ directory contains sample inputs and generated outputs. It serves as a local test fixture boundary: one known input video and several output artifacts that show expected results from the starter command-line path and the pipeline demo.
11. From an architecture-diagram perspective, the important external dependency is FFmpeg itself, but there are two forms of integration:
- process-level invocation of ffmpeg.exe for the simplest demo
- library-level linkage to libavformat, libavcodec, libavutil, libswscale, and libswresample for the pipeline demo
12. Overall, this repository is not a general multimedia app; it is a deliberately small learning scaffold. Its main architectural idea is to expose the FFmpeg transcode lifecycle in two layers: a black-box executable call for quick success, and a decomposed C++ pipeline for understanding the media-processing boundaries.
Main entry points: video_transcode_pipeline.cpp Transcode Pipeline · CMakeLists.txt CMake · ffmpeg_helpers.cpp FFmpeg Helpers · main.cpp CLI Transcode
Components 18
Application
Repo-owned build targets and C++ demo flows.
- CMake · Configures the Windows-oriented build and links vendored FFmpeg.
CMakeLists.txt - CLI Transcode · Builds and runs an ffmpeg.exe command for a minimal transcode demo.
src/main.cpp - Pipeline Demo · Entry point for the explicit FFmpeg API pipeline example.
src/pipeline_demo.cpp
API Pipeline
Decomposed FFmpeg-based transcode workflow.
- Transcode Pipeline · Coordinates the stage objects into one linear media-processing flow.
src/pipeline/video_transcode_pipeline.cpp - Demuxer · Reads containers and extracts packets from input streams.
src/pipeline/demuxer.cpp - Decoder · Converts compressed packets into raw frames.
src/pipeline/decoder.cpp - Frame Prep · Normalizes video frames for encoder input.
src/pipeline/frame_preprocessor.cpp - Encoder · Compresses prepared frames into output packets.
src/pipeline/encoder.cpp - Muxer · Writes encoded packets into the destination container.
src/pipeline/muxer.cpp - FFmpeg Helpers · Shared boilerplate for API setup, conversions, and error handling.
src/pipeline/ffmpeg_helpers.cpp - Pipeline Logger · Emits stage markers such as demux, decode, encode, and mux transitions.
src/pipeline/pipeline_logger.cpp
Vendored FFmpeg
Bundled binaries, headers, and import libraries.
- ffmpeg.exe · Bundled command-line transcoder invoked by the simple demo.
third_party/ffmpeg/bin/ffmpeg.exe - FFmpeg Headers · Vendored API headers for libavformat, libavcodec, libavutil, and related libs.
third_party/ffmpeg/include - FFmpeg Libs · Vendored Windows libraries for direct FFmpeg linkage.
third_party/ffmpeg/lib
Media Fixtures
Sample inputs and generated outputs used by the demos.
- Input Video · Sample source media used by both demo paths.
media/input.mp4 - CLI Output · Output produced by the command-line wrapper demo.
media/output_moved_layout.mp4 - Pipeline Output · Output produced by the API pipeline demo.
media/pipeline_output.mp4 - Alt Outputs · Additional generated outputs from pipeline demo variants.
media/pipeline_output_cpp_style.mp4
Connections 25
- CMake → CLI Transcode: builds · Build system compiles the CLI demo target.
- CMake → Pipeline Demo: builds · Build system compiles the API demo entry point.
- CMake → Transcode Pipeline: links · Build system links pipeline implementation with FFmpeg libs.
- CMake → FFmpeg Headers: uses headers · Build configuration points compilation at vendored FFmpeg headers.
- CMake → FFmpeg Libs: links libs · Build configuration links against vendored FFmpeg import libraries.
- CLI Transcode → ffmpeg.exe: executes · CLI demo shells out to the bundled ffmpeg executable.
- CLI Transcode → Input Video: reads · Consumes the sample input video.
- CLI Transcode → CLI Output: writes · Produces a transcoded output file.
- Pipeline Demo → Transcode Pipeline: orchestrates · Demo entry instantiates and runs the pipeline coordinator.
- Transcode Pipeline → Demuxer: assembles · Coordinator wires the demux stage into the workflow.
- Transcode Pipeline → Decoder: assembles · Coordinator wires the decode stage into the workflow.
- Transcode Pipeline → Frame Prep: assembles · Coordinator wires the frame-preprocess stage into the workflow.
- Transcode Pipeline → Encoder: assembles · Coordinator wires the encode stage into the workflow.
- Transcode Pipeline → Muxer: assembles · Coordinator wires the mux stage into the workflow.
- Demuxer → FFmpeg Helpers: uses · Stage relies on shared FFmpeg boilerplate and error handling.
- Decoder → FFmpeg Helpers: uses · Stage relies on shared FFmpeg boilerplate and error handling.
- Frame Prep → FFmpeg Helpers: uses · Stage relies on shared FFmpeg boilerplate and error handling.
- Encoder → FFmpeg Helpers: uses · Stage relies on shared FFmpeg boilerplate and error handling.
- Muxer → FFmpeg Helpers: uses · Stage relies on shared FFmpeg boilerplate and error handling.
- Transcode Pipeline → Pipeline Logger: logs · Coordinator and stages emit observable state transitions.
- Demuxer → Input Video: reads · Demuxer opens the input media file.
- Muxer → Pipeline Output: writes · Pipeline emits the main output artifact.
- Muxer → Alt Outputs: writes · Pipeline variants emit additional output artifacts.
- Transcode Pipeline → FFmpeg Headers: includes · API pipeline compiles against vendored FFmpeg headers.
- Transcode Pipeline → FFmpeg Libs: links · API pipeline links directly to FFmpeg libraries.