Media processing services
Media processing services turn imported media into usable editor data and preview assets. They keep costly work such as media inspection, decoding, speech recognition, video conversion, and model-based frame work away from the main user interface while preserving a path from each result back to the media library or composition runtime.
Processing model
Browser and worker boundary
The processing layer uses browser APIs and Web Workers as a local media pipeline. A service starts a job, sends media or a stored media path to a worker, then receives progress, completion, cancellation, or error events. The main thread keeps ownership of editor state and user feedback while workers handle decode, conversion, and inference.
GPU-heavy jobs use one active job at a time where parallel work would compete for the same device. Shared workers and model sessions stay warm for reuse, but idle local models can be evicted so they do not keep large amounts of memory forever. src/…/transcription-worker-pool.ts and src/…/background-media-work.ts define these lifetime and priority rules.
The common job shape is:
- Resolve the source from a file, a loader, or browser storage.
- Prepare a decoder, model, or encoder that the current browser can use.
- Stream progress while the worker processes the media.
- Store the result in browser storage or import it as a new media item.
- Remove temporary data when the job completes, fails, or is cancelled.
This diagram shows how media work moves from an editor request to a usable preview or library result.
flowchart LR
Request[Editor request] --> Service[Media service]
Service --> Worker[Web Worker]
Worker --> Decode[Decode or inspect]
Decode --> Transform[Convert, infer, or analyze]
Transform --> Scratch[Browser storage or scratch output]
Scratch --> Service
Service --> Result[Preview state or new media item]
References: src/…/transcription-worker-pool.ts• L3-10 src/…/background-media-work.ts• L1-21 src/…/render-support.ts• L1-7
Media inspection and preview assets
The media processor gives imports a common description of video, audio, and image files. It extracts dimensions, duration, frame rate, codecs, and browser decode support. It can also create a small thumbnail, while the filmstrip worker extracts time-based video frames for timeline browsing. src/…/media-processor-service.ts• L3-6 and src/…/media-processor.worker.ts• L1-9 define this import-facing role.
The inspection result helps later services choose the right path. A video that a native video element cannot play can use a proxy or a custom decoder. A video with unsupported audio can use a separate audio preparation path. Keyframe information can improve seeking without changing the source media.
References: src/…/media-processor.worker.ts• L120-151 src/…/media-processor.worker.ts• L408-481 src/…/filmstrip-extraction-worker.ts• L1-7
Speech transcription
Transcription pipeline
The transcription system creates local speech text from audio or video. It decodes the source to mono 16 kHz audio, sends bounded chunks to a speech model, and returns time-marked words and segments. The service stores the transcript by media identity so later caption work can reuse it without running recognition again. Requests with the same media and settings share one job, while other requests wait in a queue and can report or cancel their state.
Sources that need a custom audio decoder first use a conformed preview-audio source. This gives the speech path a readable audio input without changing the original media item. src/…/media-transcription-service.ts• L544-600 and src/…/media-transcription-service.ts• L670-697 define this preparation and save boundary.
Whisper is the broad-coverage default. Parakeet is available for supported European languages when WebGPU is present. If Parakeet cannot run because of language or device limits, the system selects a Whisper fallback. src/…/transcription-engine.ts• L4-12 and src/…/transcription-engine.ts• L48-87 define that choice.
The model and audio decoder run as separate workers. This lets model loading and audio preparation progress at the same time. The bridge also pauses both sides during active playback or scrubbing so transcription does not compete with interactive preview. src/…/bridge.ts• L30-100 and src/…/browser-transcriber.ts• L109-165 define this coordination.
This diagram shows the main transcription path and its device fallback.
sequenceDiagram
participant App as Media service
participant Decode as Audio decoder worker
participant Model as Speech worker
participant Store as Transcript storage
App->>Decode: Prepare audio chunks
App->>Model: Load selected engine
Decode-->>Model: Stream normalized chunks
Model-->>App: Word-timed segments and progress
App->>Store: Save transcript
Model-->>App: WebGPU or WASM runtime status
References: src/…/media-transcription-service.ts• L376-434 src/…/media-transcription-service.ts• L544-609 src/…/media-transcription-service.ts• L670-697 src/…/bridge.ts• L68-100 src/…/decoder.worker.ts• L61-95 src/…/whisper.worker.ts• L248-347
Transcript captions
A stored transcript can become captions on timeline clips that use the same media. The service groups word timings into readable phrases, keeps the source timing on each cue, and updates existing transcript-driven captions when the stored transcript changes. It refreshes the active timeline, registered compositions, and navigation snapshots, so nested or reused compositions do not keep older transcript timing. Caption visibility and style remain clip-owned, so transcript refresh does not replace an editor’s local presentation choices. src/…/media-transcription-service.ts• L221-293 and src/…/media-transcription-service.ts• L615-667 describe this relationship.
The service can also insert transcript captions as regular subtitle items. It selects a matching clip and a compatible caption track, or creates a track above the source clip when needed. This gives users both a live transcript-backed view and an editable caption result.
References: src/…/media-transcription-service.ts• L700-817 src/…/media-transcription-service.ts• L820-907 src/…/timeline.ts• L171-185
Video derivatives
Proxy media
A proxy is a lower-size video used for responsive preview while the original remains the source for export. Proxy generation accepts video only, scales it within a 960-by-540 bound, and creates a video-only file to keep preview work small. The service reports per-media status and progress and can share one physical proxy when several media identities point to the same source.
Ready proxies are kept in browser storage and mirrored to the workspace cache. On a later session the service reloads valid proxies, hydrates missing local entries from the workspace cache, and removes stale or incomplete entries. If the saved codec is not playable on the current machine, the service keeps the proxy for compatible machines and uses the original for preview. User requests take priority over background proxy work, and only one proxy render runs at a time. src/…/proxy-generation-worker.ts• L1-15 and src/…/proxy-service.ts• L446-645 define this lifecycle.
References: src/…/proxy-service.ts• L276-339 src/…/proxy-service.ts• L446-645 src/…/proxy-service.ts• L944-1019 src/…/proxy-generation-worker.ts• L181-243 src/…/proxy-generation-worker.ts• L384-399
Frame interpolation
Frame interpolation creates a new video with more frames while keeping the source duration. RIFE estimates the frames between each pair of source frames. The worker places those frames at positions derived from the decoded timestamps, so variable-frame-rate media keeps its timing. It can skip model inference for static or near-static gaps while still producing the required output frames. The worker copies source audio when the output container can carry its codec, writes the video to temporary browser storage, and the service imports the completed file as a new tagged media item.
Interpolation runs one job at a time because it saturates the GPU. It reports model loading and render progress, supports cancellation, and removes partial output before the next job can use the scratch area. The output frame rate is measured from decoded timestamps, which keeps variable-frame-rate sources aligned with their actual timing. src/…/frame-interpolation-service.ts• L1-9 and src/…/frame-interpolation-worker.ts• L1-15 define the user-visible contract.
References: src/…/frame-interpolation-service.ts• L121-156 src/…/frame-interpolation-service.ts• L247-325 src/…/frame-interpolation-worker.ts• L168-191 src/…/frame-interpolation-worker.ts• L228-343 src/…/interpolate-gap.test.ts• L20-149 src/…/rife-interpolator.ts• L48-56
Video upscaling
Video upscaling creates a new video at twice the source width and height. Anime4K supplies variants for live action, animation, and three-dimensional footage. The worker reconstructs each frame through the selected model, keeps the source frame rate and duration, and imports the result as a new tagged media item.
The service checks the output size before starting a long render. The model can use WebGPU and falls back to WASM when needed. Like interpolation, upscaling uses temporary browser storage, preserves audio when the output format supports direct copy, and cleans up after completion or cancellation. src/…/upscale-service.ts• L116-153 and src/…/upscale-worker.ts• L156-178 define this path.
References: src/…/upscale-service.ts• L108-160 src/…/upscale-service.ts• L245-329 src/…/upscale-worker.ts• L110-131 src/…/upscale-variant.ts• L1-14 src/…/anime4k-upscaler.ts• L38-91
Audio processing
Audio decode and playback
The audio path supports media that native elements cannot decode or seek well. A worker decodes audio, converts it to stereo, reduces its sample rate for preview, and streams compact bins back to the runtime. The bins can be saved and later assembled into an AudioBuffer, which gives long files a bounded and reusable preview path. src/…/audio-decode-worker.ts• L1-10 and src/…/audio-decode-dsp.ts• L63-79 define the data path.
Playback chooses the lightest path that preserves the requested behavior. Normal playback can use buffered decoded audio. Reverse playback, pitch changes, transport shuttling, or a custom codec use the decoded audio and a SoundTouch worklet when available. If that worklet path cannot start, the runtime falls back to a simpler decoded source. src/…/custom-decoder-audio.tsx• L477-515 and src/…/audio-playback-routing.ts• L1-17 define the routing rule.
References: src/…/audio-decode-worker.ts• L84-196 src/…/audio-decode-worker.ts• L214-390 src/…/custom-decoder-audio.tsx• L263-376 src/…/soundtouch-worklet-audio.tsx• L274-324
Audio shaping and analysis
Audio utilities provide small, reusable operations that keep sound behavior consistent across preview and editor actions. They cover silence range detection, pitch shifts, fade curves, and multi-band equalization. The timeline can use silence ranges for edit assistance. Playback can apply pitch and equal-power or shaped fades. Equalization can be represented as ordered stages and applied to a live audio graph.
These utilities separate user-facing audio intent from the runtime that plays it. Values are normalized before use, and the same resolved settings can support preview response curves, live filters, or sample processing. src/…/audio-silence.ts• L1-22, src/…/audio-pitch.ts• L18-62, src/…/audio-fade-curve.ts• L146-246, and src/…/audio-eq.ts• L630-695 define those shared contracts.
References: src/…/silence-detection-worker.ts• L16-57 src/…/audio-silence.ts• L224-288 src/…/audio-pitch.ts• L40-62 src/…/audio-fade-curve.ts• L248-273 src/…/preview-audio-graph.ts• L486-565
Audio export support
Audio export checks the requested codec against the browser before a render begins. PCM needs no extra encoder. AAC can use a local WASM encoder when the browser has no native AAC support, while unsupported codec choices fail the capability check instead of failing late in the export. src/…/audio-encoder-support.ts• L1-45 defines this boundary.
References: src/…/audio-encoder-support.ts• L20-45
GPU media support
GPU media composition
The media GPU layer moves common source-to-texture work onto WebGPU. It can place a video, image, canvas, or decoded frame into an output texture with crop, transform, opacity, flip, feather, rounded corners, corner pinning, masking, and optional blend behavior. A separate blend pass combines a base texture and a layer texture using the selected blend mode. src/…/media-render-pipeline.ts• L3-48 and src/…/media-blend-pipeline.ts• L36-80 define these media-focused operations.
This layer is a building block for interactive composition rendering. It accepts already decoded media and returns a GPU texture result, so it does not decide how media is stored or how a timeline is authored. Its value is a shared, device-side path for repeated visual transforms.
References: src/…/media-render-pipeline.ts• L230-299 src/…/media-render-pipeline.ts• L336-417 src/…/media-blend-pipeline.ts• L74-119
GPU capability and fallback
WebGPU is an acceleration option rather than a hard requirement for local media features. Speech, interpolation, and upscaling select WebGPU when the device can use it and fall back to WASM when model setup or graph creation fails. ProRes uses a local decoder registration for worker and browser decode paths, while the import metadata still distinguishes custom decode from native video-element playback. src/…/register-prores-decoder.ts• L1-23 defines this distinction.
The result is graceful degradation: a feature may take longer or use a different decoder, but the service can still report a clear capability failure when no safe path exists. This is especially important for large model loads, unsupported video encoders, and custom audio codecs.
References: src/…/whisper.worker.ts• L192-225 src/…/parakeet.worker.ts• L232-300 src/…/rife-interpolator.ts• L158-169 src/…/anime4k-upscaler.ts• L113-124 src/…/register-prores-decoder.ts• L25-40
Change checklist
When these files or sections are changed, remember to consider these:
- Keep worker message types and service status handling aligned for every terminal state: ready, idle, cancelled, and error.
- When a codec or output container changes, review native playback checks, custom decoder routing, proxy reuse checks, and audio passthrough together.
- When a model or backend choice changes, update the engine resolver, runtime reporting, model cache metadata, and fallback behavior as one contract.
- When a generated video result changes its frame rate, dimensions, or tags, review the media-library import metadata and the UI status key that still points to the source item.
- When temporary browser-storage paths change, keep completion, cancellation, failure cleanup, and session recovery in agreement.
- When transcript timing or queue behavior changes, keep shared-job keys, cancellation handling, transcript storage, and all timeline composition snapshots aligned.
- When proxy priority or shared proxy identity changes, keep status updates, alias mappings, workspace hydration, and background filmstrip prewarming consistent.
- When interpolation scheduling changes, keep supported factors, timestamp spacing, static-gap behavior, and frame-count metadata consistent.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| WebGPU model setup fails | Transcription, interpolation, or upscaling cannot use the fast path | Resolve to WASM where the feature supports it and report the active backend. |
| A proxy uses a codec that the current machine cannot play | Preview playback breaks even though the proxy file exists | Check codec playability and use the original source when the check fails. |
| A video codec or audio codec has no usable browser path | Import, preview, or transcription cannot read the needed track | Use metadata capability flags, custom decoder preparation, or a clear unsupported-media error. |
| Custom audio conformance fails before transcription | Recognition cannot read a source that needs a custom decoder | Prepare and validate a preview-audio source before sending it to the speech model. |
| Upscaling produces an encoder-size limit violation | A long GPU render fails at output setup or encode time | Reject the request before rendering and select a codec that can accept the target frame size. |
| A derivative render is cancelled or errors after creating scratch data | Partial output remains locked or can be mistaken for a valid result | Cancel the encoder, remove the job scratch file, and import only a non-empty completed result. |
| An output container cannot carry the source audio codec | Interpolation or upscaling returns silent video | Treat audio copy as optional and report or accept the deliberate audio drop rather than corrupting the video. |
| An unsupported interpolation factor reaches gap scheduling | The render could create the wrong number or timing of frames | Reject the factor before inference and keep the supported-factor contract aligned with output metadata. |
Key files
| File | Why to read it |
|---|---|
| src/…/media-processor-service.ts | Shows the import-facing contract for off-main-thread media inspection and thumbnail work. |
| src/…/media-processor.worker.ts | Shows the common metadata and thumbnail outcomes for video, audio, and image media. |
| src/…/media-transcription-service.ts | Connects local recognition to queued jobs, stored transcripts, custom audio preparation, and timeline captions. |
| src/…/bridge.ts | Shows how audio decoding and persistent speech workers exchange chunks and events. |
| src/…/proxy-generation-worker.ts | Shows why proxies exist and how preview derivatives are created and stored. |
| src/…/proxy-service.ts | Shows proxy identity sharing, priority, cache recovery, playback fallback, and preview prewarming. |
| src/…/frame-interpolation-service.ts | Shows how a GPU render becomes a new media-library item. |
| src/…/frame-interpolation-worker.ts | Shows timestamp-aware frame creation, audio copy, progress, and scratch cleanup. |
| src/…/interpolate-gap.test.ts | Shows the contract for frame count, time order, static gaps, supported factors, and inference failures. |
| src/…/upscale-service.ts | Shows the derivative lifecycle for model-based resolution changes. |
| src/…/render-support.ts | Shows the shared contract for video decode, encode, audio copy, cancellation, and scratch output. |
| src/…/audio-decode-worker.ts | Shows the worker path for bounded decoded audio preview data. |
| src/…/custom-decoder-audio.tsx | Shows how custom codecs and non-normal playback use decoded audio. |
| src/…/audio-eq.ts | Shows the shared audio shaping model used by preview and processing paths. |
| src/…/media-render-pipeline.ts | Shows the media-focused WebGPU operations used for texture composition. |
| src/…/register-prores-decoder.ts | Shows the boundary between custom browser decoding and native video playback capability. |