Skip to content

FFmpeg Integration

tonythethompson edited this page Jul 28, 2026 · 3 revisions

FFmpeg Integration

Section: Media & Audio · Hardware-Starter-Packs · Home · Audio-Quality-Enhancement

FFmpeg backs probing, extraction, normalization, and muxing. Encapsulated in Trackdub.Media as an external binary with process wrappers.

Architecture and Components

The FFmpeg integration is structured around specialized components that interact with the FFmpeg binary via a centralized process runner. This design ensures consistent error handling, logging, and execution across different media tasks.

Core Media Components

Component Responsibility Relevant Project
ProcessRunner Manages the lifecycle of the external FFmpeg process, including arguments and output. Trackdub.Media
FfmpegMediaProbe Extracts metadata, stream information, and technical details from media files. Trackdub.Media
FfmpegMuxer Combines different audio and video streams into a final container format. Trackdub.Media
FfmpegHelpers Contains development-only probes and command experiments. Trackdub.Tools

Process Execution Flow

The following diagram illustrates how the application orchestrates an FFmpeg command through the specialized media classes.

graph TD
    A[Application/Pipeline] --> B[FfmpegMediaProbe / FfmpegMuxer]
    B --> C[ProcessRunner]
    C --> D{FFmpeg Binary}
    D --> E[Standard Output / Error]
    E --> C
    C --> B
    B --> A
Loading

The diagram shows the top-down flow from high-level pipeline orchestration to the execution of the FFmpeg binary.

Implementation Details

Media Probing

The FfmpegMediaProbe is responsible for utilizing ffprobe to inspect media files. It extracts critical information required for the pipeline, such as durations, codecs, and stream indices. This data is essential for the "Media Ingest" and "Audio Preparation" stages of the product spine.

Muxing and Export

The FfmpegMuxer handles the final stages of the dubbing pipeline. It is responsible for combining the synthesized dubbed speech with the original video or ambiance tracks. This component ensures that the final export matches the requested loudness normalization and format options.

Audio Preparation Pipeline

FFmpeg is utilized lazily via EnsureNormalizedAudioAsync to extract and normalize audio artifacts before they are passed to speech separation or ASR (Automatic Speech Recognition) stages.

flowchart TD
    Start[Media Ingest] --> Extract[FFmpeg Extract Audio]
    Extract --> Normalize[FFmpeg Normalize Audio]
    Normalize --> Artifact[ArtifactKind.NormalizedAudio]
    Artifact --> Next[Separation / ASR Preflight]
Loading

This flow represents the lazy audio preparation sequence using FFmpeg as described in the workspace facts.

Key Constraints and Rules

Integration Boundaries

  • No Ad-hoc Commands: The system strictly prohibits spawning ad-hoc FFmpeg commands from UI code. All commands must be routed through Trackdub.Media services.
  • Artifact Preservation: Original media and prior successful artifacts are treated as sacred. FFmpeg operations must not overwrite source files in-place.
  • Resource Management: Process execution is managed with CancellationToken support to ensure that long-running media tasks can be gracefully cancelled by the user.

Conclusion

The FFmpeg Integration provides the technical foundation for Trackdub's media workstation capabilities. By wrapping complex media operations into structured services like FfmpegMediaProbe and FfmpegMuxer, the project ensures reliable, resumable, and cross-platform media processing that adheres to the core principle of not faking readiness.

Clone this wiki locally