API Reference

Video Operations

Video operations are the core transformation commands of MediaX. They are exposed as pipeline steps and direct job methods, each strongly typed, validated, and mapped to FFmpeg commands.

Overview

Core transformation commands for video processing
Available as pipeline steps and direct job methods
Strongly typed with comprehensive validation
Mapped to optimized underlying FFmpeg commands

Available Operations

1. Convert

Transcodes video from one format/container to another

Example Usage
const job = mediaX.convert("input.mp4", "output.mkv");

Parameters

inputstringPath to input file
outputstringTarget file path (extension defines format)
options?ConvertOptionsOptional conversion settings

Options

codec?stringCustom codec (default: auto-detected)
crf?numberQuality (H.264/HEVC, lower = higher quality)
preset?stringFFmpeg preset (ultrafast → veryslow)

Common Errors

FILE_NOT_FOUNDCODEC_NOT_SUPPORTEDCONVERSION_FAILED

2. Compress

Reduces video file size by re-encoding with lower bitrate/quality

Example Usage
const job = mediaX.compress("input.mp4", "output.mp4", "1000k");

Parameters

inputstringSource video file path
outputstringOutput compressed file path
bitratestringTarget bitrate (e.g., "800k", "2M")

Common Errors

INVALID_PARAMSJOB_TIMEOUTFFMPEG_ERROR

3. Thumbnail

Extracts a still frame as an image at a specific timestamp

Example Usage
const job = mediaX.thumbnail("input.mp4", "thumbnail.png", "00:00:05");

Parameters

inputstringSource video file
outputstringOutput image file (usually .png/.jpg)
timestampstringExtraction timestamp (HH:MM:SS)

Common Errors

INVALID_PARAMSNO_STREAMS

4. To GIF

Converts a segment of video into an animated GIF

Example Usage
const job = mediaX.toGif("input.mp4", "output.gif", { start: 10, duration: 5, fps: 12 });

Parameters

inputstringSource video file
outputstringOutput GIF file path
optionsGifOptionsGIF conversion options

Options

startnumberStart time in seconds
durationnumberLength of clip in seconds
fps?numberFrame rate (default: 10)
scale?stringScaling options (e.g., "320:-1")

Common Errors

INVALID_MEDIACONVERSION_FAILEDJOB_TIMEOUT

5. Trim

Cuts a video between two timestamps

Example Usage
const job = mediaX.trim("input.mp4", "output.mp4", { start: "00:00:10", duration: "00:00:30" });

Parameters

inputstringSource video file
outputstringOutput trimmed video
optionsTrimOptionsTrimming options

Options

startstringStart timestamp (HH:MM:SS)
duration?stringOptional duration to cut

Common Errors

INVALID_PARAMSPIPELINE_ERROR

Pipeline Usage Example

Chain multiple operations in one execution for complex video processing workflows:

video-pipeline-example.ts
1
2
3
4
5
6
7
8
9
10
typescript

Pipeline Benefits:

Automatic file chaining
Unified progress tracking
Error handling across steps
Resource optimization

Common Job Options

These options are available across all video operations:

OptionTypeDescription
timeoutnumberMax execution time (ms)
onProgress(p: ProgressInfo) => voidProgress callback
overwritebooleanWhether to overwrite existing files
metadataRecord<string, any>Custom job metadata
job-options-example.ts
1
2
3
4
5
6
7
8
9
10
11
12
typescript

Advanced Usage

advanced-video-operations.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
typescript

Explore More Operations

Video operations are just the beginning. Explore batch operations.