Pipeline Class
The Pipeline class allows chained media transformations that execute in sequence, providing atomic execution, reduced boilerplate, and automatic dependency handling.
Class Overview
1234
Input Acceptance
Accepts an input file on creation for processing
Method Chaining
Supports method chaining - each transformation queues up a step
Deferred Execution
Execution deferred until .run() is called
Event Emission
Emits progress and error events across the entire pipeline
Constructor
1
Parameters:
Internally creates a job queue where each step is appended for sequential execution.
Methods
Pipeline methods are wrappers around core MediaX methods. Each appends a step to the pipeline:
1. convert
conversionconvert(output, format, options?)
Queue a format conversion
pipeline.convert("converted.mkv", "mkv");
2. compress
optimizationcompress(output, bitrate)
Queue a compression step
pipeline.compress("compressed.mp4", "800k");
3. extractAudio
audioextractAudio(output, format)
Queue audio extraction
pipeline.extractAudio("track.mp3", "mp3");
4. replaceAudio
audioreplaceAudio(audioFile, output)
Queue audio replacement
pipeline.replaceAudio("voiceover.mp3", "dubbed.mp4");
5. thumbnail
imagethumbnail(output, timestamp)
Queue thumbnail capture
pipeline.thumbnail("thumb.png", "00:00:05");
6. clip
editingclip(output, { start, duration })
Queue video clipping
pipeline.clip("scene.mp4", { start: 20, duration: 8 });
Additional Pipeline Methods
Events
Pipeline extends TypedEmitter, exposing unified events for all steps:
triggered when pipeline execution begins
emitted when a transformation begins
emitted with cumulative ProgressInfo across steps
emitted when a step completes
emitted when entire pipeline finishes
emitted if any step fails
1234567891011
Execution Model
How Pipeline Execution Works:
- Sequential Steps: Steps execute in the order they were added
- Output Chaining: Each step consumes output from the previous step
- Auto Management: Intermediate files are managed automatically
- Failure Handling: Failures abort pipeline by default (with cleanup)
Pipeline Flow Example:
Error Handling
Pipeline Error Types
12345
Properties
array of queued steps
initial input file
active step while running
boolean execution flag
Complete Usage Example
123456789
This Pipeline Will:
- 1Extract the first 60 seconds as "intro.mp4"
- 2Add a logo watermark at position (15, 15)
- 3Compress the video to 700k bitrate
- 4Create a 5-second GIF animation
Ready for More Advanced Features?
Now that you understand pipelines, explore advanced topics like progress tracking, error handling, or dive into the complete API reference.