Examples

Pipeline Workflows

The Pipeline API lets you chain multiple media operations in a single workflow. Instead of running jobs separately, compose them using Pipeline for efficient sequential processing.

Why Use Pipelines?

Sequential Execution

Steps execute in order, with each step waiting for the previous to complete

Output Chaining

Output from one step becomes input for the next step automatically

Error Handling

Pipeline stops on first error and provides detailed error information

Promise-Based

Uses modern Promise API for clean async/await syntax

Complete Pipeline Examples

1. Video Conversion + Compression Pipeline

Chain conversion and compression for efficient transcoding workflow

Convert AVI → MP4
Compress to reduce size

Implementation

video-conversion-+-compression-pipeline-pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typescript

How It Works

Pipeline(mediaX) initializes a pipeline bound to a MediaX instance
addStep(command, args[]) queues a job (convert, compress)
.run() executes all steps in order, ensuring outputs feed into subsequent operations
Perfect for transcoding → compressing workflows

2. Extract Audio + Metadata Probe

Extract audio from video and inspect its metadata properties

Extract audio track
Probe audio metadata

Implementation

extract-audio-+-metadata-probe-pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typescript

How It Works

The first step extracts the audio track
The second step probes the audio file for duration, bitrate, codec
Useful for audio post-processing pipelines like transcription or podcast preparation

3. Generate Thumbnails + Compress Video

Create thumbnails and compress video simultaneously for web platforms

Generate 3 thumbnails
Compress video file

Implementation

generate-thumbnails-+-compress-video-pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typescript

How It Works

Step 1 generates 3 evenly spaced thumbnails
Step 2 compresses the movie to a smaller file size
Useful for video platforms that need both thumbnails & optimized video simultaneously

4. Complex Multi-Step Workflow

Comprehensive pipeline with conversion, compression, audio extraction, and metadata inspection

Convert format
Compress video
Extract audio
Probe metadata

Implementation

complex-multi-step-workflow-pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typescript

How It Works

Step 1: Convert .mov into .mp4
Step 2: Compress the MP4 to reduce size
Step 3: Extract audio track into MP3
Step 4: Probe metadata of the extracted MP3
This shows chained multi-step workflows, where each step output is reused

Pipeline Best Practices

Design Patterns

  • Keep pipelines focused on single workflows
  • Use descriptive step names and file paths
  • Plan intermediate file naming carefully

Error Handling

  • Always use .catch() for pipeline error handling
  • Clean up intermediate files on errors
  • Log detailed error information for debugging

Advanced Pipeline Usage

advanced-pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
typescript

Master Advanced Workflows

Now that you understand pipeline workflows, explore progress tracking, error handling, and batch processing to build production-ready media processing applications.