mlt-xml
Version:
A module to construct Media Lovin' Toolkit (MLT) projects and export them in XML.
276 lines (260 loc) • 11.3 kB
TypeScript
declare type AnyAttributes = Partial<Record<string, unknown>>;
interface XmlObj<Name extends string = string, Attributes extends AnyAttributes = AnyAttributes> {
name: Name;
attributes: Attributes;
}
/**
* A blank space
*/
declare type Blank = XmlObj<'blank', {
/** the duration of the blank */
length: string;
}>;
/**
* A filter is a service that may modify the output of a single producer.
*/
declare type Filter = XmlObj<'filter', {
/** Id of the filter */
id: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
mlt_service?: string;
/** The index of the track of a multitrack on which the filter is applied */
track?: string;
/** A reference to the service to which this filter is attached. */
service?: string;
/** Set this to disable the filter while keeping it in the object model. Currently this is not cleared when the filter is detached. */
disable?: boolean;
} & Partial<Record<string, unknown>>>;
declare type AnyProducer<SubProducerName extends string, AdditionalAttributes extends Partial<Record<string, unknown>> = Partial<Record<string, unknown>>> = XmlObj<SubProducerName, {
/** Id of the producer */
id: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
title?: string;
/** The name of the service subclass, e.g. mlt_producer */
mlt_type?: string;
/** The name of a producer subclass */
mlt_service?: string;
/** Sample aspect ratio */
aspect_ratio?: number;
/** The duration of the cut in frames */
length?: string | number;
/** The end-of-file behavior, one of: pause, continue, loop */
eof?: 'pause' | 'continue' | 'loop';
/** The file name, stream address, or the class name in angle brackets */
resource?: string;
/** Stores the data for a "mix" producer */
mlt_mix?: string;
/** Set this to temporarily disable the in and out points. */
ignore_points?: boolean;
/** holds a reference to a clone's producer, as created by mlt_producer_optimise */
use_clone?: string;
} & AdditionalAttributes & Partial<Record<string, unknown>>>;
/**
* A producer is a service that generates audio, video, and metadata.
* Some day it may also generate text (subtitles).
* This is not to say a producer "synthesizes," rather that is an origin of data within the service network - that could be through synthesis or reading a stream.
*/
interface Producer extends AnyProducer<'producer'> {
elements?: Filter[];
}
/**
* The link is a producer object that that can be connected to other link producers in a Chain.
*/
declare type Link = AnyProducer<'link', {
next?: string;
}>;
/**
* The chain is a producer that that can connect multiple link producers in a sequence.
*/
interface Chain extends AnyProducer<'chain'> {
elements?: Array<Link | Filter>;
}
/**
* A consumer is a service that pulls audio and video from the connected producers, filters, and transitions.
* Typically a consumer is used to output audio and/or video to a device, file, or socket.
*/
declare type Consumer = XmlObj<'consumer', {
/** Id of the consumer */
id: string;
/** The name of a consumer subclass */
mlt_service?: string;
/** The scaling algorithm to pass on to all scaling filters, defaults to "bilinear" */
rescale?: string;
/** The number of frames to use in the asynchronous render thread, defaults to 25 */
buffer?: number;
/** The number of frames to render before commencing output when real_time <> 0, defaults to the size of buffer */
prefill?: number;
/** The maximum number of consecutively dropped frames, defaults to 5 */
drop_max?: number;
/** The audio sample rate to use in Hertz, defaults to 48000 */
frequency?: number;
/** The number of audio channels to use, defaults to 2 */
channels?: number;
/** The layout of the audio channels, defaults to auto. other options include: mono, stereo, 5.1, 7.1, etc. */
channel_layout?: string;
/** The asynchronous behavior: 1 (default) for asynchronous with frame dropping, -1 for asynchronous without frame dropping, 0 to disable (synchronous) */
real_time?: -1 | 0 | 1;
/** The name of a resource to use as the test card, defaults to environment variable MLT_TEST_CARD. If undefined, the hard-coded default test card is white silence. A test card is what appears when nothing is produced. */
test_card?: string;
/** The numerator of the video frame rate, overrides mlt_profile_s */
frame_rate_num?: number;
/** The denominator of the video frame rate, overrides mlt_profile_s */
frame_rate_den?: number;
/** The horizontal video resolution, overrides mlt_profile_s */
width?: number;
/** The vertical video resolution, overrides mlt_profile_s */
height?: number;
/** A flag that indicates if the video is interlaced or progressive, overrides mlt_profile_s */
progressive?: boolean;
/** The video sample (pixel) aspect ratio as floating point (read only) */
aspect_ratio?: number;
/** The numerator of the sample aspect ratio, overrides mlt_profile_s */
sample_aspect_num?: number;
/** The denominator of the sample aspect ratio, overrides mlt_profile_s */
sample_aspect_den?: number;
/** The video frame aspect ratio as floating point (read only) */
display_ratio?: number;
/** The numerator of the video frame aspect ratio, overrides mlt_profile_s */
display_aspect_num?: number;
/** The denominator of the video frame aspect ratio, overrides mlt_profile_s */
display_aspect_den?: number;
/** The OS scheduling priority for the render threads when real_time is not 0. */
priority?: string;
/** When not progressive, whether interlace field order is top-field-first, defaults to 0. Set this to -1 if the consumer does not care about the field order. */
top_field_first?: -1 | 0 | 1;
/** The image format to request in rendering threads, defaults to yuv422 */
mlt_image_format?: string;
/** The audio format to request in rendering threads, defaults to S16 */
mlt_audio_format?: string;
/** Whether or not to disable audio processing */
audio_off?: boolean;
/** Whether or not to disable video processing */
video_off?: boolean;
/** The number of video frames not rendered since starting consumer */
drop_count?: number;
/** The color range as tv/mpeg (limited) or pc/jpeg (full); default is unset, which implies tv/mpeg */
color_range?: string;
/** The color transfer characteristic (gamma), default is unset */
color_trc?: string;
/** The deinterlace algorithm to pass to deinterlace filters, defaults to "yadif" */
deinterlacer?: string;
/** video frames per second as floating point (read only) */
fps?: number;
} & Partial<Record<string, unknown>>>;
/**
* A transition may modify the output of a producer based on the output of a second producer.
*/
declare type Transition = XmlObj<'transition', {
id: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
/** The name of a transition subclass */
mlt_service?: string;
/** The track index (0-based) of a multitrack of the first producer */
a_track?: number;
/** The track index (0-based) of a multitrack of the second producer */
b_track?: number;
/** A flag to indicate if the transition should accept blank frames */
accepts_blanks?: boolean;
/** A flag to indicate that the in and out points do not apply */
always_active?: boolean;
/** Set this to disable the transition while keeping it in the object model. */
disable?: boolean;
} & Partial<Record<string, unknown>>>;
interface Track extends XmlObj<'track', {
producer: string;
hide?: 'video' | 'audio' | 'both';
}> {
elements?: Array<Producer | Playlist | Tractor | Multitrack | Filter | Transition | Chain>;
}
/**
* The tractor is a convenience object to manage a multitrack, track filters, and transitions.
*/
interface Tractor extends XmlObj<'tractor', {
id: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
title?: string;
/** Holds a reference to an encapsulated producer */
producer?: string;
} & Partial<Record<string, unknown>>> {
elements: Array<Multitrack | Track | Filter | Transition>;
}
/**
* A playlist is a sequential container of producers and blank spaces.
* The class provides all sorts of playlist assembly and manipulation routines.
* A playlist is also a producer within the framework.
*/
interface Playlist extends XmlObj<'playlist', {
/** Id of the playlist */
id: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
title?: string;
/** Set this true if you are doing sequential processing and want to automatically close producers as they are finished being used to free resources. */
autoclose?: boolean;
/** Set true on a producer to indicate that it is a "fx_cut," which is a way to add filters as a playlist entry - useful only in a multitrack. See FxCut in the docs. */
'meta.fx_cut'?: boolean;
/** Set to 1 to hide the video (make it an audio-only track), 2 to hide the audio (make it a video-only track), or 3 to hide audio and video (hidden track). This property only applies when using a multitrack or transition. */
hide?: 1 | 2 | 3;
mix_in?: string;
mix_out?: string;
}> {
elements?: Array<Entry | Blank | Producer | Playlist | Tractor | Multitrack | Chain>;
}
/**
* A multitrack is a parallel container of producers that acts a single producer.
*/
interface Multitrack extends XmlObj<'multitrack', {
/** Id of the multitrack */
id: string;
}> {
elements: Array<Track | Producer | Playlist | Tractor | Multitrack | Chain>;
}
interface Entry extends XmlObj<'entry', {
/** Producer Id */
producer: string;
/** When to start, what is started is service-specific */
in?: string | number;
/** When to stop */
out?: string | number;
}> {
elements?: Array<Producer | Playlist | Tractor | Multitrack | Filter | Transition | Chain>;
}
declare type Profile = XmlObj<'profile', {
name?: string;
colorspace?: string;
description?: string;
display_aspect_den?: number;
display_aspect_num?: number;
frame_rate_den: number;
frame_rate_num: number;
height: number;
progressive: boolean;
sample_aspect_den: number;
sample_aspect_num: number;
width: number;
}>;
interface MLT {
LC_NUMERIC?: string;
version?: string;
root?: string;
profile?: string;
title?: string;
producer?: string;
elements: Array<Profile | Producer | Playlist | Tractor | Multitrack | Consumer | Chain>;
}
declare function mltToXml(mlt: MLT): string;
export { Blank, Chain, Consumer, Entry, Filter, Link, MLT, Multitrack, Playlist, Producer, Profile, Track, Tractor, Transition, mltToXml };