Skip to content

openrv-web / MediaAPI

Class: MediaAPI

Defined in: api/MediaAPI.ts:27

Extends

  • DisposableAPI

Constructors

Constructor

new MediaAPI(session, persistenceManager?): MediaAPI

Defined in: api/MediaAPI.ts:31

Parameters

session

Session

persistenceManager?

AppPersistenceManager | null

Returns

MediaAPI

Overrides

DisposableAPI.constructor

Methods

addSourceFromPattern()

addSourceFromPattern(pattern, startFrame?, endFrame?, fps?): Promise<void>

Defined in: api/MediaAPI.ts:271

Load an image sequence from a pattern string.

Accepts #### (hash), %04d (printf), or @@@@ (at-sign) notation to specify the frame-number placeholder. The pattern is expanded across the given frame range and each resulting URL is loaded as a sequence frame.

Parameters

pattern

string

URL/path with a frame placeholder, e.g. /path/shot.####.exr

startFrame?

number

First frame number (inclusive, default: 1)

endFrame?

number

Last frame number (inclusive, default: 100)

fps?

number

Frame rate (default: session fps)

Returns

Promise<void>

Example

ts
await openrv.media.addSourceFromPattern('/renders/shot.####.exr', 1001, 1100);
await openrv.media.addSourceFromPattern('frame.%04d.png', 1, 48, 30);

addSourceFromURL()

addSourceFromURL(url): Promise<void>

Defined in: api/MediaAPI.ts:248

Load a media source from a URL into the session.

Validates the URL scheme (only http: and https: are allowed) and auto-detects the media type (image vs. video) from the file extension.

Parameters

url

string

The HTTP/HTTPS URL to load.

Returns

Promise<void>

Example

ts
await openrv.media.addSourceFromURL('https://example.com/clip.mp4');

clearSources()

clearSources(): void

Defined in: api/MediaAPI.ts:286

Clear all loaded media sources, releasing associated resources. Creates an auto-checkpoint before clearing when sources exist and a persistence manager is available.

Returns

void

Example

ts
openrv.media.clearSources();

dispose()

dispose(): void

Defined in: api/Disposable.ts:19

Mark this sub-API as disposed. After this call, assertNotDisposed() will throw on every subsequent invocation.

Returns

void

Inherited from

DisposableAPI.dispose


getActiveRepresentation()

getActiveRepresentation(sourceIndex?): RepresentationInfo | null

Defined in: api/MediaAPI.ts:316

Get the currently active representation for a source.

Parameters

sourceIndex?

number

Index of the source (defaults to the current source)

Returns

RepresentationInfo | null

The active representation info, or null


getCurrentSource()

getCurrentSource(): SourceInfo | null

Defined in: api/MediaAPI.ts:49

Get information about the currently loaded source.

Returns

SourceInfo | null

A SourceInfo object with name, type, dimensions, duration, and fps, or null if no media is loaded.

Example

ts
const src = openrv.media.getCurrentSource();
if (src) console.log(`${src.name}: ${src.width}x${src.height}`);

getDuration()

getDuration(): number

Defined in: api/MediaAPI.ts:75

Get total duration in frames.

Returns

number

The total number of frames in the current source, or 0 if no source is loaded.

Example

ts
const frames = openrv.media.getDuration();

getFPS()

getFPS(): number

Defined in: api/MediaAPI.ts:90

Get the frames per second of the current source.

Returns

number

The FPS of the current source, or the session playback FPS if no source is loaded.

Example

ts
const fps = openrv.media.getFPS(); // e.g. 24

getPlaybackFPS()

getPlaybackFPS(): number

Defined in: api/MediaAPI.ts:105

Get the session playback FPS (which may differ from the source FPS if overridden).

Returns

number

The current session playback rate in frames per second.

Example

ts
const playbackFps = openrv.media.getPlaybackFPS(); // e.g. 48

getRepresentations()

getRepresentations(sourceIndex?): RepresentationInfo[]

Defined in: api/MediaAPI.ts:302

Get all representations for a source.

Parameters

sourceIndex?

number

Index of the source (defaults to the current source)

Returns

RepresentationInfo[]

Array of representation info objects, or an empty array


getResolution()

getResolution(): object

Defined in: api/MediaAPI.ts:139

Get the resolution of the current source.

Returns

object

An object with width and height in pixels, or { width: 0, height: 0 } if no source is loaded.

height

height: number

width

width: number

Example

ts
const { width, height } = openrv.media.getResolution();

getSourceCount()

getSourceCount(): number

Defined in: api/MediaAPI.ts:197

Get the number of loaded sources.

Returns

number

The count of media sources currently loaded in the session.

Example

ts
const count = openrv.media.getSourceCount();

getStartFrame()

getStartFrame(): number

Defined in: api/MediaAPI.ts:177

Get the start frame number of the current source.

For image sequences this is the first frame number in the sequence (e.g. 1001 for a VFX sequence starting at frame 1001). For single images or when no source is loaded, returns 1.

Returns

number

The start frame number (1-based).

Example

ts
const start = openrv.media.getStartFrame(); // e.g. 1001

hasMedia()

hasMedia(): boolean

Defined in: api/MediaAPI.ts:158

Check if any media source is currently loaded.

Returns

boolean

true if a source is loaded, false otherwise.

Example

ts
if (openrv.media.hasMedia()) { openrv.playback.play(); }

loadMovieProc()

loadMovieProc(url): void

Defined in: api/MediaAPI.ts:230

Load a procedural source from a .movieproc URL string.

Parameters

url

string

The movieproc URL (e.g., 'smpte_bars,width=1920,height=1080.movieproc')

Returns

void

Example

ts
openrv.media.loadMovieProc('checkerboard,cellSize=32.movieproc');

loadProceduralSource()

loadProceduralSource(pattern, options?): void

Defined in: api/MediaAPI.ts:215

Load a procedural test pattern as a source.

Parameters

pattern

PatternName

The pattern type to generate (e.g., 'smpte_bars', 'checkerboard')

options?

ProceduralSourceOptions

Optional configuration for resolution, color, and other parameters

Returns

void

Example

ts
openrv.media.loadProceduralSource('smpte_bars');
openrv.media.loadProceduralSource('solid', { color: [1, 0, 0, 1] });
openrv.media.loadProceduralSource('checkerboard', { width: 3840, height: 2160, cellSize: 32 });

setPlaybackFPS()

setPlaybackFPS(fps): void

Defined in: api/MediaAPI.ts:120

Set the session playback FPS (overrides the source FPS for playback timing).

Parameters

fps

number

The desired playback rate in frames per second. Must be a positive number.

Returns

void

Example

ts
openrv.media.setPlaybackFPS(48); // play back at 48 fps

switchRepresentation()

switchRepresentation(repId, sourceIndex?): Promise<boolean>

Defined in: api/MediaAPI.ts:330

Switch the active representation for a source.

Parameters

repId

string

ID of the representation to switch to

sourceIndex?

number

Index of the source (defaults to the current source)

Returns

Promise<boolean>

Promise that resolves to true if the switch succeeded

Released under the MIT License.