Principle:0xsline OpenChatCut Media Import Pipeline
| Knowledge Sources | |
|---|---|
| Domains | Media_Import, Pipeline, Media_Processing |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Pipeline principle that ingests local media files through a multi-stage process: receipt, probing, format normalization, content-hash deduplication, and reference registration, producing a stable, deduplicated media asset.
Description
Media Import Pipeline is the ordered sequence of stages a media file passes through when entering the system. Each stage has a single responsibility and the output of one feeds the next:
- Receipt: Accept the file (via HTTP upload or local path), assign a UUID-based stored name, and verify it is a regular file.
- Probing: Use FFprobe to extract metadata (duration, dimensions, FPS, codecs, audio/video track presence, quality risks).
- Format Normalization: Transcode to a canonical format (H.264/AAC MP4, ≤1920px, CFR) using FFmpeg with hardware acceleration, or stream-copy if already compatible.
- Content-Hash Deduplication: Compute SHA-256 of the file content for deduplication (skipped for files > 1.5 GB to avoid excessive I/O).
- Reference Registration: Record a manifest file mapping the stored name to the canonical source path, enabling in-place media resolution without copying.
The pipeline is designed so that:
- Each stage can fail independently with a clear error.
- The file is never copied until reference registration (in-place dedup).
- Large files are handled efficiently (hash skip, stream-copy when compatible).
- The pipeline is idempotent — re-importing the same file produces the same reference.
Usage
Use this principle when:
- Building a media import system that needs deduplication and normalization.
- Designing a pipeline where each stage can be tested independently.
- Ensuring media is in a canonical format before editing or rendering.
Theoretical Basis
The pipeline is a staged data transformation with fail-fast semantics:
# Abstract algorithm (NOT real implementation)
def import_media(source_path, original_name):
# Stage 1: Receipt
info = stat(source_path)
assert info.is_file()
stored_name = uuid() + ext(original_name)
# Stage 2: Probing
probe = ffprobe(source_path)
# Stage 3: Normalization
if needs_normalization(probe):
normalized = encode_h264(source_path, probe)
else:
normalized = stream_copy(source_path)
# Stage 4: Deduplication
if info.size < LARGE_THRESHOLD:
content_hash = sha256(source_path)
else:
content_hash = ""
# Stage 5: Reference Registration
register_reference(upload_dir, stored_name, source_path)
return { src: f"/media/uploads/{stored_name}", content_hash }