Core Concepts

MediaX Class

The MediaX class is the primary entry point of the MediaX SDK. It provides high-level methods to perform media transformations, manage pipelines, and retrieve metadata.

Class Overview

basic-import.ts
1
2
3
typescript

Auto-Configuration

Handles initialization of FFmpeg and FFprobe binaries

Rich Methods

Exposes methods for conversion, compression, audio extraction, and more

Event-Driven

Provides event-driven job objects for progress tracking

Pipeline Integration

Integrates with pipelines and queues for batch management

Constructor

constructor.ts
1
typescript

On Instantiation:

  • Auto-configures ffmpeg and ffprobe paths using installers
  • Prepares internal registries for jobs and pipelines
  • No arguments required - zero configuration setup

Events

Every job returned by a MediaX method is an EventEmitter. Available events:

startemitted when FFmpeg command begins execution
progressemitted with a ProgressInfo object
doneemitted when job finishes successfully
erroremitted if job fails
events-example.ts
1
2
3
4
5
6
typescript

Methods

1. convert

conversion

convert(input, output, format, options?)

Convert a file from one format to another

mediaX.convert("input.mp4", "output.mkv", "mkv");

2. compress

optimization

compress(input, output, bitrate)

Reduce file size by re-encoding at a specified bitrate

mediaX.compress("input.mp4", "compressed.mp4", "800k");

3. extractAudio

audio

extractAudio(input, output, format)

Extract audio track in given format

mediaX.extractAudio("input.mp4", "output.mp3", "mp3");

4. replaceAudio

audio

replaceAudio(videoFile, audioFile, output)

Replace video's existing audio track with a new one

mediaX.replaceAudio("video.mp4", "voiceover.mp3", "final.mp4");

5. thumbnail

image

thumbnail(input, output, timestamp)

Capture a single frame as an image

mediaX.thumbnail("video.mp4", "thumb.png", "00:00:10");

6. clip

editing

clip(input, output, { start, duration })

Extract a short segment

mediaX.clip("movie.mp4", "scene.mp4", { start: 30, duration: 10 });

Additional Methods

toGif()Convert to GIF
concat()Concatenate files
addWatermark()Add watermarks
extractFrames()Extract frames
metadata()Get metadata
getStatus()Check status

Pipeline Method

Chain multiple transformations using the pipeline method:

pipeline-example.ts
1
2
3
4
5
6
typescript

Error Handling

Custom Error Types

MediaXErrorBase error class
MediaXValidationErrorInvalid input/parameters
MediaXFFmpegErrorExecution failure
error-handling.ts
1
2
3
4
5
6
7
typescript

Properties

jobs

list of active jobs

Job[]
pipelines

list of active pipelines

Pipeline[]
ffmpegPath

resolved path to FFmpeg binary

string
ffprobePath

resolved path to FFprobe binary

string

Status Monitoring

status-example.ts
1
2
3
4
5
6
7
8
9
typescript

Next: Learn Pipelines

Now that you understand the MediaX class, learn how to create powerful pipeline workflows for complex media processing operations.