@imput/libav.js-encode-cli
Version:
A compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil and libswresample—for WebAssembly and asm.js, and thus the web. This package includes only one variant.
1,373 lines (1,308 loc) • 205 kB
TypeScript
/*
* Copyright (C) 2021-2024 Yahweasel and contributors
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
declare namespace LibAV {
/**
* Things in libav.js with Worker transfer characteristics.
*/
export interface LibAVTransferable {
/**
* The elements to pass as transfers when passing this object to/from
* workers.
*/
libavjsTransfer?: Transferable[];
}
/**
* Frames, as taken/given by libav.js.
*/
export interface Frame extends LibAVTransferable {
/**
* The actual frame data. For non-planar audio data, this is a typed array.
* For planar audio data, this is an array of typed arrays, one per plane.
* For video data, this is a single Uint8Array, and its layout is described
* by the layout field.
*/
data: any;
/**
* Sample format or pixel format.
*/
format: number;
/**
* Video only. Layout of each plane within the data array. `offset` is the
* base offset of the plane, and `stride` is what libav calls `linesize`.
* This layout format is from WebCodecs.
*/
layout?: {offset: number, stride: number}[];
/**
* Presentation timestamp for this frame. Units depends on surrounding
* context. Will always be set by libav.js, but libav.js will accept frames
* from outside that do not have this set.
*/
pts?: number, ptshi?: number;
/**
* Base for timestamps of this frame.
*/
time_base_num?: number, time_base_den?: number;
/**
* Audio only. Channel layout. It is possible for only one of this and
* channels to be set.
*/
channel_layout?: number;
/**
* Audio only. Number of channels. It is possible for only one of this and
* channel_layout to be set.
*/
channels?: number;
/**
* Audio only. Number of samples in the frame.
*/
nb_samples?: number;
/**
* Audio only. Sample rate.
*/
sample_rate?: number;
/**
* Video only. Width of frame.
*/
width?: number;
/**
* Video only. Height of frame.
*/
height?: number;
/**
* Video only. Cropping rectangle of the frame.
*/
crop?: {top: number, bottom: number, left: number, right: number};
/**
* Video only. Sample aspect ratio (pixel aspect ratio), as a numerator and
* denominator. 0 is interpreted as 1 (square pixels).
*/
sample_aspect_ratio?: [number, number];
/**
* Is this a keyframe? (1=yes, 0=maybe)
*/
key_frame?: number;
/**
* Picture type (libav-specific value)
*/
pict_type?: number;
}
/**
* Packets, as taken/given by libav.js.
*/
export interface Packet extends LibAVTransferable {
/**
* The actual data represented by this packet.
*/
data: Uint8Array;
/**
* Presentation timestamp.
*/
pts?: number, ptshi?: number;
/**
* Decoding timestamp.
*/
dts?: number, dtshi?: number;
/**
* Base for timestamps of this packet.
*/
time_base_num?: number, time_base_den?: number;
/**
* Index of this stream within a surrounding muxer/demuxer.
*/
stream_index?: number;
/**
* Packet flags, as defined by ffmpeg.
*/
flags?: number;
/**
* Duration of this packet. Rarely used.
*/
duration?: number, durationhi?: number;
/**
* Side data. Codec-specific.
*/
side_data?: any;
}
/**
* Stream information, as returned by ff_init_demuxer_file.
*/
export interface Stream {
/**
* Pointer to the underlying AVStream.
*/
ptr: number;
/**
* Index of this stream.
*/
index: number;
/**
* Codec parameters.
*/
codecpar: number;
/**
* Type of codec (audio or video, typically)
*/
codec_type: number;
/**
* Codec identifier.
*/
codec_id: number;
/**
* Base for timestamps of packets in this stream.
*/
time_base_num: number, time_base_den: number;
/**
* Duration of this stream in time_base units.
*/
duration_time_base: number;
/**
* Duration of this stream in seconds.
*/
duration: number;
}
/**
* Codec parameters, if copied out.
*/
export interface CodecParameters {
/**
* General type of the encoded data.
*/
codec_type: number;
/**
* Specific type of the encoded data (the codec used).
*/
codec_id: number;
/**
* Additional information about the codec (corresponds to the AVI FOURCC).
*/
codec_tag?: number;
/**
* Extra binary data needed for initializing the decoder, codec-dependent.
*
* Must be allocated with av_malloc() and will be freed by
* avcodec_parameters_free(). The allocated size of extradata must be at
* least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
* bytes zeroed.
*/
extradata?: Uint8Array;
/**
* - video: the pixel format, the value corresponds to enum AVPixelFormat.
* - audio: the sample format, the value corresponds to enum AVSampleFormat.
*/
format: number;
/**
* Bitrate. Not always set.
*/
bit_rate?: number;
bit_ratehi?: number;
/**
* Codec-specific bitstream restrictions that the stream conforms to.
*/
profile?: number;
level?: number;
/**
* Video only. The dimensions of the video frame in pixels.
*/
width?: number;
height?: number;
/**
* Video only. Additional colorspace characteristics.
*/
color_range?: number;
color_primaries?: number;
color_trc?: number;
color_space?: number;
chroma_location?: number;
/**
* Audio only. The number of audio samples per second.
*/
sample_rate?: number;
/**
* Audio only. The channel layout and number of channels.
*/
channel_layoutmask?: number;
channels?: number;
}
/**
* Settings used to set up a filter.
*/
export interface FilterIOSettings {
/**
* Type of filterchain, as an AVMEDIA_TYPE_*. If unset, defaults to
* AVMEDIA_TYPE_AUDIO.
*/
type?: number;
/**
* The timebase for this filterchain. If unset, [1, frame_rate] or [1,
* sample_rate] will be used.
*/
time_base?: [number, number];
/**
* Video only. Framerate of the input.
*/
frame_rate?: number;
/**
* Audio only. Sample rate of the input.
*/
sample_rate?: number;
/**
* Video only. Pixel format of the input.
*/
pix_fmt?: number;
/**
* Audio only. Sample format of the input.
*/
sample_fmt?: number;
/**
* Video only. Width of the input.
*/
width?: number;
/**
* Video only. Height of the input.
*/
height?: number;
/**
* Audio only. Channel layout of the input. Note that there is no
* "channels"; you must describe a layout.
*/
channel_layout?: number;
/**
* Audio only, output only, optional. Size of an audio frame.
*/
frame_size?: number;
}
/**
* Supported properties of an AVCodecContext, used by ff_init_encoder.
*/
export interface AVCodecContextProps {
bit_rate?: number;
bit_ratehi?: number;
channel_layout?: number;
channel_layouthi?: number;
channels?: number;
frame_size?: number;
framerate_num?: number;
framerate_den?: number;
gop_size?: number;
height?: number;
keyint_min?: number;
level?: number;
pix_fmt?: number;
profile?: number;
rc_max_rate?: number;
rc_max_ratehi?: number;
rc_min_rate?: number;
rc_min_ratehi?: number;
sample_aspect_ratio_num?: number;
sample_aspect_ratio_den?: number;
sample_fmt?: number;
sample_rate?: number;
qmax?: number;
qmin?: number;
width?: number;
}
/**
* Static properties that are accessible both on the LibAV wrapper and on each
* libav instance.
*/
export interface LibAVStatic {
/**
* Convert a pair of 32-bit integers representing a single 64-bit integer
* into a 64-bit float. 64-bit floats are only sufficient for 53 bits of
* precision, so for very large values, this is lossy.
* @param lo Low bits of the pair
* @param hi High bits of the pair
*/
i64tof64(lo: number, hi: number): number;
/**
* Convert a 64-bit floating-point number into a pair of 32-bit integers
* representing a single 64-bit integer. The 64-bit float must actually
* contain an integer value for this result to be accurate.
* @param val Floating-point value to convert
* @returns [low bits, high bits]
*/
f64toi64(val: number): [number, number];
/**
* Convert a pair of 32-bit integers representing a single 64-bit integer
* into a BigInt. Requires BigInt support, of course.
* @param lo Low bits of the pair
* @param hi High bits of the pair
*/
i64ToBigInt(lo: number, hi: number): BigInt;
/**
* Convert a (64-bit) BigInt into a pair of 32-bit integers. Requires BigInt
* support, of course.
* @param val BigInt value to convert
* @returns [low bits, high bits]
*/
bigIntToi64(val: BigInt): [number, number];
/**
* Extract the channel layout from a frame (or any other source of
* channel layout). Unifies the various ways that channel layouts may
* be stored.
*/
ff_channel_layout(frame: {
channel_layout?: number,
channels?: number
}): number;
/**
* Extract the channel count from a frame (or any other source of
* channel layout). Unifies the various ways that channel layouts may be
* stored.
*/
ff_channels(frame: {
channel_layout?: number,
channels?: number
}): number;
// Constants:
AV_TIME_BASE: number;
AV_OPT_SEARCH_CHILDREN: number;
// Enumerations:
AVMEDIA_TYPE_UNKNOWN: number;
AVMEDIA_TYPE_VIDEO: number;
AVMEDIA_TYPE_AUDIO: number;
AVMEDIA_TYPE_DATA: number;
AVMEDIA_TYPE_SUBTITLE: number;
AVMEDIA_TYPE_ATTACHMENT: number;
AV_SAMPLE_FMT_NONE: number;
AV_SAMPLE_FMT_U8: number;
AV_SAMPLE_FMT_S16: number;
AV_SAMPLE_FMT_S32: number;
AV_SAMPLE_FMT_FLT: number;
AV_SAMPLE_FMT_DBL: number;
AV_SAMPLE_FMT_U8P: number;
AV_SAMPLE_FMT_S16P: number;
AV_SAMPLE_FMT_S32P: number;
AV_SAMPLE_FMT_FLTP: number;
AV_SAMPLE_FMT_DBLP: number;
AV_SAMPLE_FMT_S64: number;
AV_SAMPLE_FMT_S64P: number;
AV_SAMPLE_FMT_NB: number;
AV_PIX_FMT_NONE: number;
AV_PIX_FMT_YUV420P: number;
AV_PIX_FMT_YUYV422: number;
AV_PIX_FMT_RGB24: number;
AV_PIX_FMT_BGR24: number;
AV_PIX_FMT_YUV422P: number;
AV_PIX_FMT_YUV444P: number;
AV_PIX_FMT_YUV410P: number;
AV_PIX_FMT_YUV411P: number;
AV_PIX_FMT_GRAY8: number;
AV_PIX_FMT_MONOWHITE: number;
AV_PIX_FMT_MONOBLACK: number;
AV_PIX_FMT_PAL8: number;
AV_PIX_FMT_YUVJ420P: number;
AV_PIX_FMT_YUVJ422P: number;
AV_PIX_FMT_YUVJ444P: number;
AV_PIX_FMT_UYVY422: number;
AV_PIX_FMT_UYYVYY411: number;
AV_PIX_FMT_BGR8: number;
AV_PIX_FMT_BGR4: number;
AV_PIX_FMT_BGR4_BYTE: number;
AV_PIX_FMT_RGB8: number;
AV_PIX_FMT_RGB4: number;
AV_PIX_FMT_RGB4_BYTE: number;
AV_PIX_FMT_NV12: number;
AV_PIX_FMT_NV21: number;
AV_PIX_FMT_ARGB: number;
AV_PIX_FMT_RGBA: number;
AV_PIX_FMT_ABGR: number;
AV_PIX_FMT_BGRA: number;
AV_PIX_FMT_GRAY16BE: number;
AV_PIX_FMT_GRAY16LE: number;
AV_PIX_FMT_YUV440P: number;
AV_PIX_FMT_YUVJ440P: number;
AV_PIX_FMT_YUVA420P: number;
AV_PIX_FMT_RGB48BE: number;
AV_PIX_FMT_RGB48LE: number;
AV_PIX_FMT_RGB565BE: number;
AV_PIX_FMT_RGB565LE: number;
AV_PIX_FMT_RGB555BE: number;
AV_PIX_FMT_RGB555LE: number;
AV_PIX_FMT_BGR565BE: number;
AV_PIX_FMT_BGR565LE: number;
AV_PIX_FMT_BGR555BE: number;
AV_PIX_FMT_BGR555LE: number;
AVIO_FLAG_READ: number;
AVIO_FLAG_WRITE: number;
AVIO_FLAG_READ_WRITE: number;
AVIO_FLAG_NONBLOCK: number;
AVIO_FLAG_DIRECT: number;
AVSEEK_FLAG_BACKWARD: number;
AVSEEK_FLAG_BYTE: number;
AVSEEK_FLAG_ANY: number;
AVSEEK_FLAG_FRAME: number;
AVDISCARD_NONE: number;
AVDISCARD_DEFAULT: number;
AVDISCARD_NONREF: number;
AVDISCARD_BIDIR: number;
AVDISCARD_NONINTRA: number;
AVDISCARD_NONKEY: number;
AVDISCARD_ALL: number;
AV_LOG_QUIET: number;
AV_LOG_PANIC: number;
AV_LOG_FATAL: number;
AV_LOG_ERROR: number;
AV_LOG_WARNING: number;
AV_LOG_INFO: number;
AV_LOG_VERBOSE: number;
AV_LOG_DEBUG: number;
AV_LOG_TRACE: number;
AV_PKT_FLAG_KEY: number;
AV_PKT_FLAG_CORRUPT: number;
AV_PKT_FLAG_DISCARD: number;
AV_PKT_FLAG_TRUSTED: number;
AV_PKT_FLAG_DISPOSABLE: number;
E2BIG: number;
EPERM: number;
EADDRINUSE: number;
EADDRNOTAVAIL: number;
EAFNOSUPPORT: number;
EAGAIN: number;
EALREADY: number;
EBADF: number;
EBADMSG: number;
EBUSY: number;
ECANCELED: number;
ECHILD: number;
ECONNABORTED: number;
ECONNREFUSED: number;
ECONNRESET: number;
EDEADLOCK: number;
EDESTADDRREQ: number;
EDOM: number;
EDQUOT: number;
EEXIST: number;
EFAULT: number;
EFBIG: number;
EHOSTUNREACH: number;
EIDRM: number;
EILSEQ: number;
EINPROGRESS: number;
EINTR: number;
EINVAL: number;
EIO: number;
EISCONN: number;
EISDIR: number;
ELOOP: number;
EMFILE: number;
EMLINK: number;
EMSGSIZE: number;
EMULTIHOP: number;
ENAMETOOLONG: number;
ENETDOWN: number;
ENETRESET: number;
ENETUNREACH: number;
ENFILE: number;
ENOBUFS: number;
ENODEV: number;
ENOENT: number;
AVERROR_EOF: number;
}
/**
* A LibAV instance, created by LibAV.LibAV (*not* the LibAV wrapper itself)
*/
export interface LibAV extends LibAVStatic {
/**
* The operating mode of this libav.js instance. Each operating mode has
* different constraints.
*/
libavjsMode: "direct" | "worker" | "threads";
/**
* If the operating mode is "worker", the worker itself.
*/
worker?: Worker;
/**
* Return number of bytes per sample.
*
* @param sample_fmt the sample format
* @return number of bytes per sample or zero if unknown for the given
* sample format
*/
av_get_bytes_per_sample(sample_fmt: number): Promise<number>;
/**
* Compare two timestamps each in its own time base.
*
* @return One of the following values:
* - -1 if `ts_a` is before `ts_b`
* - 1 if `ts_a` is after `ts_b`
* - 0 if they represent the same position
*
* @warning
* The result of the function is undefined if one of the timestamps is outside
* the `int64_t` range when represented in the other's timebase.
*/
av_compare_ts_js(ts_a: number,tb_a: number,ts_b: number,tb_b: number,a4: number,a5: number,a6: number,a7: number): Promise<number>;
/**
* @defgroup opt_set_funcs Option setting functions
* @{
* Those functions set the field of obj with the given name to value.
*
* @param[in] obj A struct whose first element is a pointer to an AVClass.
* @param[in] name the name of the field to set
* @param[in] val The value to set. In case of av_opt_set() if the field is not
* of a string type, then the given string is parsed.
* SI postfixes and some named scalars are supported.
* If the field is of a numeric type, it has to be a numeric or named
* scalar. Behavior with more than one scalar and +- infix operators
* is undefined.
* If the field is of a flags type, it has to be a sequence of numeric
* scalars or named flags separated by '+' or '-'. Prefixing a flag
* with '+' causes it to be set without affecting the other flags;
* similarly, '-' unsets a flag.
* If the field is of a dictionary type, it has to be a ':' separated list of
* key=value parameters. Values containing ':' special characters must be
* escaped.
* @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
* is passed here, then the option may be set on a child of obj.
*
* @return 0 if the value has been set, or an AVERROR code in case of
* error:
* AVERROR_OPTION_NOT_FOUND if no matching option exists
* AVERROR(ERANGE) if the value is out of range
* AVERROR(EINVAL) if the value is not valid
*/
av_opt_set(obj: number,name: string,val: string,search_flags: number): Promise<number>;
av_opt_set_int_list_js(a0: number,a1: string,a2: number,a3: number,a4: number,a5: number): Promise<number>;
/**
* Allocate an AVFrame and set its fields to default values. The resulting
* struct must be freed using av_frame_free().
*
* @return An AVFrame filled with default values or NULL on failure.
*
* @note this only allocates the AVFrame itself, not the data buffers. Those
* must be allocated through other means, e.g. with av_frame_get_buffer() or
* manually.
*/
av_frame_alloc(): Promise<number>;
/**
* Create a new frame that references the same data as src.
*
* This is a shortcut for av_frame_alloc()+av_frame_ref().
*
* @return newly created AVFrame on success, NULL on error.
*/
av_frame_clone(src: number,a1: number): Promise<number>;
/**
* Free the frame and any dynamically allocated objects in it,
* e.g. extended_data. If the frame is reference counted, it will be
* unreferenced first.
*
* @param frame frame to be freed. The pointer will be set to NULL.
*/
av_frame_free(frame: number): Promise<void>;
/**
* Allocate new buffer(s) for audio or video data.
*
* The following fields must be set on frame before calling this function:
* - format (pixel format for video, sample format for audio)
* - width and height for video
* - nb_samples and ch_layout for audio
*
* This function will fill AVFrame.data and AVFrame.buf arrays and, if
* necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
* For planar formats, one buffer will be allocated for each plane.
*
* @warning: if frame already has been allocated, calling this function will
* leak memory. In addition, undefined behavior can occur in certain
* cases.
*
* @param frame frame in which to store the new buffers.
* @param align Required buffer size alignment. If equal to 0, alignment will be
* chosen automatically for the current CPU. It is highly
* recommended to pass 0 here unless you know what you are doing.
*
* @return 0 on success, a negative AVERROR on error.
*/
av_frame_get_buffer(frame: number,align: number): Promise<number>;
/**
* Ensure that the frame data is writable, avoiding data copy if possible.
*
* Do nothing if the frame is writable, allocate new buffers and copy the data
* if it is not. Non-refcounted frames behave as non-writable, i.e. a copy
* is always made.
*
* @return 0 on success, a negative AVERROR on error.
*
* @see av_frame_is_writable(), av_buffer_is_writable(),
* av_buffer_make_writable()
*/
av_frame_make_writable(frame: number): Promise<number>;
/**
* Set up a new reference to the data described by the source frame.
*
* Copy frame properties from src to dst and create a new reference for each
* AVBufferRef from src.
*
* If src is not reference counted, new buffers are allocated and the data is
* copied.
*
* @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
* or newly allocated with av_frame_alloc() before calling this
* function, or undefined behavior will occur.
*
* @return 0 on success, a negative AVERROR on error
*/
av_frame_ref(dst: number,src: number): Promise<number>;
/**
* Unreference all the buffers referenced by frame and reset the frame fields.
*/
av_frame_unref(frame: number): Promise<void>;
ff_frame_rescale_ts_js(a0: number,a1: number,a2: number,a3: number,a4: number): Promise<void>;
/**
* Get the current log level
*
* @see lavu_log_constants
*
* @return Current log level
*/
av_log_get_level(): Promise<number>;
/**
* Set the log level
*
* @see lavu_log_constants
*
* @param level Logging level
*/
av_log_set_level(level: number): Promise<void>;
/**
* Allocate an AVPacket and set its fields to default values. The resulting
* struct must be freed using av_packet_free().
*
* @return An AVPacket filled with default values or NULL on failure.
*
* @note this only allocates the AVPacket itself, not the data buffers. Those
* must be allocated through other means such as av_new_packet.
*
* @see av_new_packet
*/
av_packet_alloc(): Promise<number>;
/**
* Create a new packet that references the same data as src.
*
* This is a shortcut for av_packet_alloc()+av_packet_ref().
*
* @return newly created AVPacket on success, NULL on error.
*
* @see av_packet_alloc
* @see av_packet_ref
*/
av_packet_clone(src: number): Promise<number>;
/**
* Free the packet, if the packet is reference counted, it will be
* unreferenced first.
*
* @param pkt packet to be freed. The pointer will be set to NULL.
* @note passing NULL is a no-op.
*/
av_packet_free(pkt: number): Promise<void>;
/**
* Allocate new information of a packet.
*
* @param pkt packet
* @param type side information type
* @param size side information size
* @return pointer to fresh allocated data or NULL otherwise
*/
av_packet_new_side_data(pkt: number,type: number,size: number): Promise<number>;
/**
* Setup a new reference to the data described by a given packet
*
* If src is reference-counted, setup dst as a new reference to the
* buffer in src. Otherwise allocate a new buffer in dst and copy the
* data from src into it.
*
* All the other fields are copied from src.
*
* @see av_packet_unref
*
* @param dst Destination packet. Will be completely overwritten.
* @param src Source packet
*
* @return 0 on success, a negative AVERROR on error. On error, dst
* will be blank (as if returned by av_packet_alloc()).
*/
av_packet_ref(dst: number,src: number): Promise<number>;
/**
* Convert valid timing fields (timestamps / durations) in a packet from one
* timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
* ignored.
*
* @param pkt packet on which the conversion will be performed
* @param tb_src source timebase, in which the timing fields in pkt are
* expressed
* @param tb_dst destination timebase, to which the timing fields will be
* converted
*/
av_packet_rescale_ts_js(pkt: number,tb_src: number,tb_dst: number,a3: number,a4: number): Promise<void>;
/**
* Wipe the packet.
*
* Unreference the buffer referenced by the packet and reset the
* remaining packet fields to their default values.
*
* @param pkt The packet to be unreferenced.
*/
av_packet_unref(pkt: number): Promise<void>;
/**
* Duplicate a string.
*
* @param s String to be duplicated
* @return Pointer to a newly-allocated string containing a
* copy of `s` or `NULL` if the string cannot be allocated
* @see av_strndup()
*/
av_strdup(s: string): Promise<number>;
/**
* Get a frame with filtered data from sink and put it in frame.
*
* @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
* @param frame pointer to an allocated frame that will be filled with data.
* The data must be freed using av_frame_unref() / av_frame_free()
*
* @return
* - >= 0 if a frame was successfully returned.
* - AVERROR(EAGAIN) if no frames are available at this point; more
* input frames must be added to the filtergraph to get more output.
* - AVERROR_EOF if there will be no more output frames on this sink.
* - A different negative AVERROR code in other failure cases.
*/
av_buffersink_get_frame(ctx: number,frame: number): Promise<number>;
av_buffersink_get_time_base_num(a0: number): Promise<number>;
av_buffersink_get_time_base_den(a0: number): Promise<number>;
/**
* Set the frame size for an audio buffer sink.
*
* All calls to av_buffersink_get_buffer_ref will return a buffer with
* exactly the specified number of samples, or AVERROR(EAGAIN) if there is
* not enough. The last buffer at EOF will be padded with 0.
*/
av_buffersink_set_frame_size(ctx: number,frame_size: number): Promise<void>;
ff_buffersink_set_ch_layout(a0: number,a1: number,a2: number): Promise<number>;
/**
* Add a frame to the buffer source.
*
* By default, if the frame is reference-counted, this function will take
* ownership of the reference(s) and reset the frame. This can be controlled
* using the flags.
*
* If this function returns an error, the input frame is not touched.
*
* @param buffer_src pointer to a buffer source context
* @param frame a frame, or NULL to mark EOF
* @param flags a combination of AV_BUFFERSRC_FLAG_*
* @return >= 0 in case of success, a negative AVERROR code
* in case of failure
*/
av_buffersrc_add_frame_flags(buffer_src: number,frame: number,flags: number): Promise<number>;
/**
* Free a filter context. This will also remove the filter from its
* filtergraph's list of filters.
*
* @param filter the filter to free
*/
avfilter_free(filter: number): Promise<void>;
/**
* Get a filter definition matching the given name.
*
* @param name the filter name to find
* @return the filter definition, if any matching one is registered.
* NULL if none found.
*/
avfilter_get_by_name(name: string): Promise<number>;
/**
* Allocate a filter graph.
*
* @return the allocated filter graph on success or NULL.
*/
avfilter_graph_alloc(): Promise<number>;
/**
* Check validity and configure all the links and formats in the graph.
*
* @param graphctx the filter graph
* @param log_ctx context used for logging
* @return >= 0 in case of success, a negative AVERROR code otherwise
*/
avfilter_graph_config(graphctx: number,log_ctx: number): Promise<number>;
/**
* Create and add a filter instance into an existing graph.
* The filter instance is created from the filter filt and inited
* with the parameter args. opaque is currently ignored.
*
* In case of success put in *filt_ctx the pointer to the created
* filter instance, otherwise set *filt_ctx to NULL.
*
* @param name the instance name to give to the created filter instance
* @param graph_ctx the filter graph
* @return a negative AVERROR error code in case of failure, a non
* negative value otherwise
*/
avfilter_graph_create_filter_js(filt_ctx: number,filt: string,name: string,args: number,opaque: number): Promise<number>;
/**
* Free a graph, destroy its links, and set *graph to NULL.
* If *graph is NULL, do nothing.
*/
avfilter_graph_free(graph: number): Promise<void>;
/**
* Add a graph described by a string to a graph.
*
* @note The caller must provide the lists of inputs and outputs,
* which therefore must be known before calling the function.
*
* @note The inputs parameter describes inputs of the already existing
* part of the graph; i.e. from the point of view of the newly created
* part, they are outputs. Similarly the outputs parameter describes
* outputs of the already existing filters, which are provided as
* inputs to the parsed filters.
*
* @param graph the filter graph where to link the parsed graph context
* @param filters string to be parsed
* @param inputs linked list to the inputs of the graph
* @param outputs linked list to the outputs of the graph
* @return zero on success, a negative AVERROR code on error
*/
avfilter_graph_parse(graph: number,filters: string,inputs: number,outputs: number,log_ctx: number): Promise<number>;
/**
* Allocate a single AVFilterInOut entry.
* Must be freed with avfilter_inout_free().
* @return allocated AVFilterInOut on success, NULL on failure.
*/
avfilter_inout_alloc(): Promise<number>;
/**
* Free the supplied list of AVFilterInOut and set *inout to NULL.
* If *inout is NULL, do nothing.
*/
avfilter_inout_free(inout: number): Promise<void>;
/**
* Link two filters together.
*
* @param src the source filter
* @param srcpad index of the output pad on the source filter
* @param dst the destination filter
* @param dstpad index of the input pad on the destination filter
* @return zero on success
*/
avfilter_link(src: number,srcpad: number,dst: number,dstpad: number): Promise<number>;
/**
* Allocate an AVCodecContext and set its fields to default values. The
* resulting struct should be freed with avcodec_free_context().
*
* @param codec if non-NULL, allocate private data and initialize defaults
* for the given codec. It is illegal to then call avcodec_open2()
* with a different codec.
* If NULL, then the codec-specific defaults won't be initialized,
* which may result in suboptimal default settings (this is
* important mainly for encoders, e.g. libx264).
*
* @return An AVCodecContext filled with default values or NULL on failure.
*/
avcodec_alloc_context3(codec: number): Promise<number>;
/**
* Close a given AVCodecContext and free all the data associated with it
* (but not the AVCodecContext itself).
*
* Calling this function on an AVCodecContext that hasn't been opened will free
* the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
* codec. Subsequent calls will do nothing.
*
* @deprecated Do not use this function. Use avcodec_free_context() to destroy a
* codec context (either open or closed). Opening and closing a codec context
* multiple times is not supported anymore -- use multiple codec contexts
* instead.
*/
avcodec_close(avctx: number): Promise<number>;
/**
* @return descriptor for given codec ID or NULL if no descriptor exists.
*/
avcodec_descriptor_get(id: number): Promise<number>;
/**
* @return codec descriptor with the given name or NULL if no such descriptor
* exists.
*/
avcodec_descriptor_get_by_name(name: string): Promise<number>;
/**
* Iterate over all codec descriptors known to libavcodec.
*
* @param prev previous descriptor. NULL to get the first descriptor.
*
* @return next descriptor or NULL after the last descriptor
*/
avcodec_descriptor_next(prev: number): Promise<number>;
/**
* Find a registered decoder with a matching codec ID.
*
* @param id AVCodecID of the requested decoder
* @return A decoder if one was found, NULL otherwise.
*/
avcodec_find_decoder(id: number): Promise<number>;
/**
* Find a registered decoder with the specified name.
*
* @param name name of the requested decoder
* @return A decoder if one was found, NULL otherwise.
*/
avcodec_find_decoder_by_name(name: string): Promise<number>;
/**
* Find a registered encoder with a matching codec ID.
*
* @param id AVCodecID of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
avcodec_find_encoder(id: number): Promise<number>;
/**
* Find a registered encoder with the specified name.
*
* @param name name of the requested encoder
* @return An encoder if one was found, NULL otherwise.
*/
avcodec_find_encoder_by_name(name: string): Promise<number>;
/**
* Reset the internal codec state / flush internal buffers. Should be called
* e.g. when seeking or when switching to a different stream.
*
* @note for decoders, this function just releases any references the decoder
* might keep internally, but the caller's references remain valid.
*
* @note for encoders, this function will only do something if the encoder
* declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder
* will drain any remaining packets, and can then be re-used for a different
* stream (as opposed to sending a null frame which will leave the encoder
* in a permanent EOF state after draining). This can be desirable if the
* cost of tearing down and replacing the encoder instance is high.
*/
avcodec_flush_buffers(avctx: number): Promise<void>;
/**
* Free the codec context and everything associated with it and write NULL to
* the provided pointer.
*/
avcodec_free_context(avctx: number): Promise<void>;
/**
* Get the name of a codec.
* @return a static string identifying the codec; never NULL
*/
avcodec_get_name(id: number): Promise<string>;
/**
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this
* function the context has to be allocated with avcodec_alloc_context3().
*
* The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
* avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
* retrieving a codec.
*
* Depending on the codec, you might need to set options in the codec context
* also for decoding (e.g. width, height, or the pixel or audio sample format in
* the case the information is not available in the bitstream, as when decoding
* raw audio or video).
*
* Options in the codec context can be set either by setting them in the options
* AVDictionary, or by setting the values in the context itself, directly or by
* using the av_opt_set() API before calling this function.
*
* Example:
* @code
* av_dict_set(&opts, "b", "2.5M", 0);
* codec = avcodec_find_decoder(AV_CODEC_ID_H264);
* if (!codec)
* exit(1);
*
* context = avcodec_alloc_context3(codec);
*
* if (avcodec_open2(context, codec, opts) < 0)
* exit(1);
* @endcode
*
* In the case AVCodecParameters are available (e.g. when demuxing a stream
* using libavformat, and accessing the AVStream contained in the demuxer), the
* codec parameters can be copied to the codec context using
* avcodec_parameters_to_context(), as in the following example:
*
* @code
* AVStream *stream = ...;
* context = avcodec_alloc_context3(codec);
* if (avcodec_parameters_to_context(context, stream->codecpar) < 0)
* exit(1);
* if (avcodec_open2(context, codec, NULL) < 0)
* exit(1);
* @endcode
*
* @note Always call this function before using decoding routines (such as
* @ref avcodec_receive_frame()).
*
* @param avctx The context to initialize.
* @param codec The codec to open this context for. If a non-NULL codec has been
* previously passed to avcodec_alloc_context3() or
* for this context, then this parameter MUST be either NULL or
* equal to the previously passed codec.
* @param options A dictionary filled with AVCodecContext and codec-private
* options, which are set on top of the options already set in
* avctx, can be NULL. On return this object will be filled with
* options that were not found in the avctx codec context.
*
* @return zero on success, a negative value on error
* @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
* av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context()
*/
avcodec_open2(avctx: number,codec: number,options: number): Promise<number>;
/**
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this
* function the context has to be allocated with avcodec_alloc_context3().
*
* The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
* avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
* retrieving a codec.
*
* Depending on the codec, you might need to set options in the codec context
* also for decoding (e.g. width, height, or the pixel or audio sample format in
* the case the information is not available in the bitstream, as when decoding
* raw audio or video).
*
* Options in the codec context can be set either by setting them in the options
* AVDictionary, or by setting the values in the context itself, directly or by
* using the av_opt_set() API before calling this function.
*
* Example:
* @code
* av_dict_set(&opts, "b", "2.5M", 0);
* codec = avcodec_find_decoder(AV_CODEC_ID_H264);
* if (!codec)
* exit(1);
*
* context = avcodec_alloc_context3(codec);
*
* if (avcodec_open2(context, codec, opts) < 0)
* exit(1);
* @endcode
*
* In the case AVCodecParameters are available (e.g. when demuxing a stream
* using libavformat, and accessing the AVStream contained in the demuxer), the
* codec parameters can be copied to the codec context using
* avcodec_parameters_to_context(), as in the following example:
*
* @code
* AVStream *stream = ...;
* context = avcodec_alloc_context3(codec);
* if (avcodec_parameters_to_context(context, stream->codecpar) < 0)
* exit(1);
* if (avcodec_open2(context, codec, NULL) < 0)
* exit(1);
* @endcode
*
* @note Always call this function before using decoding routines (such as
* @ref avcodec_receive_frame()).
*
* @param avctx The context to initialize.
* @param codec The codec to open this context for. If a non-NULL codec has been
* previously passed to avcodec_alloc_context3() or
* for this context, then this parameter MUST be either NULL or
* equal to the previously passed codec.
* @param options A dictionary filled with AVCodecContext and codec-private
* options, which are set on top of the options already set in
* avctx, can be NULL. On return this object will be filled with
* options that were not found in the avctx codec context.
*
* @return zero on success, a negative value on error
* @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
* av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context()
*/
avcodec_open2_js(avctx: number,codec: number,options: number): Promise<number>;
/**
* Allocate a new AVCodecParameters and set its fields to default values
* (unknown/invalid/0). The returned struct must be freed with
* avcodec_parameters_free().
*/
avcodec_parameters_alloc(): Promise<number>;
/**
* Copy the contents of src to dst. Any allocated fields in dst are freed and
* replaced with newly allocated duplicates of the corresponding fields in src.
*
* @return >= 0 on success, a negative AVERROR code on failure.
*/
avcodec_parameters_copy(dst: number,src: number): Promise<number>;
/**
* Free an AVCodecParameters instance and everything associated with it and
* write NULL to the supplied pointer.
*/
avcodec_parameters_free(par: number): Promise<void>;
/**
* Fill the parameters struct based on the values from the supplied codec
* context. Any allocated fields in par are freed and replaced with duplicates
* of the corresponding fields in codec.
*
* @return >= 0 on success, a negative AVERROR code on failure
*/
avcodec_parameters_from_context(par: number,codec: number): Promise<number>;
/**
* Fill the codec context based on the values from the supplied codec
* parameters. Any allocated fields in codec that have a corresponding field in
* par are freed and replaced with duplicates of the corresponding field in par.
* Fields in codec that do not have a counterpart in par are not touched.
*
* @return >= 0 on success, a negative AVERROR code on failure.
*/
avcodec_parameters_to_context(codec: number,par: number): Promise<number>;
/**
* Return decoded output data from a decoder or encoder (when the
* @ref AV_CODEC_FLAG_RECON_FRAME flag is used).
*
* @param avctx codec context
* @param frame This will be set to a reference-counted video or audio
* frame (depending on the decoder type) allocated by the
* codec. Note that the function will always call
* av_frame_unref(frame) before doing anything else.
*
* @retval 0 success, a frame was returned
* @retval AVERROR(EAGAIN) output is not available in this state - user must
* try to send new input
* @retval AVERROR_EOF the codec has been fully flushed, and there will be
* no more output frames
* @retval AVERROR(EINVAL) codec not opened, or it is an encoder without the
* @ref AV_CODEC_FLAG_RECON_FRAME flag enabled
* @retval "other negative error code" legitimate decoding errors
*/
avcodec_receive_frame(avctx: number,frame: number): Promise<number>;
/**
* Read encoded data from the encoder.
*
* @param avctx codec context
* @param avpkt This will be set to a reference-counted packet allocated by the
* encoder. Note that the function will always call
* av_packet_unref(avpkt) before doing anything else.
* @retval 0 success
* @retval AVERROR(EAGAIN) output is not available in the current state - user must
* try to send input
* @retval AVERROR_EOF the encoder has been fully flushed, and there will be no
* more output packets
* @retval AVERROR(EINVAL) codec not opened, or it is a decoder
* @retval "another negative error code" legitimate encoding errors
*/
avcodec_receive_packet(avctx: number,avpkt: number): Promise<number>;
/**
* Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
* to retrieve buffered output packets.
*
* @param avctx codec context
* @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
* Ownership of the frame remains with the caller, and the
* encoder will not write to the frame. The encoder may create
* a reference to the frame data (or copy it if the frame is
* not reference-counted).
* It can be NULL, in which case it is considered a flush
* packet. This signals the end of the stream. If the encoder
* still has packets buffered, it will return them after this
* call. Once flushing mode has been entered, additional flush
* packets are ignored, and sending frames will return
* AVERROR_EOF.
*
* For audio:
* If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
* can have any number of samples.
* If it is not set, frame->nb_samples must be equal to
* avctx->frame_size for all frames except the last.
* The final frame may be smaller than avctx->frame_size.
* @retval 0 success
* @retval AVERROR(EAGAIN) input is not accepted in the current state - user must
* read output with avcodec_receive_packet() (once all
* output is read, the packet should be resent, and the
* call will not fail with EAGAIN).
* @retval AVERROR_EOF the encoder has been flushed, and no new frames can
* be sent to it
* @retval AVERROR(EINVAL) codec not opened, it is a decoder, or requires flush
* @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar
* @retval "another negative error code" legitimate encoding errors
*/
avcodec_send_frame(avctx: number,frame: number): Promise<number>;
/**
* Supply raw packet data as input to a decoder.
*
* Internally, this call will copy relevant AVCodecContext fields, which can
* influence decoding per-packet, and apply them when the packet is actually
* decoded. (For example AVCodecContext.skip_frame, which might direct the
* decoder to drop the frame contained by the packet sent with this function.)
*
* @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
* larger than the actual read bytes because some optimized bitstream
* readers read 32 or 64 bits at once and could read over the end.
*
* @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
* before packets may be fed to the decoder.
*
* @param avctx codec context
* @param[in] avpkt The input AVPacket. Usually, this will be a single video
* frame, or several complete audio frames.
* Ownership of the packet remains with the caller, and the
* decoder will not write to the packet. The decoder may create
* a reference to the packet data (or copy it if the packet is
* not reference-counted).
* Unlike with older APIs, the packet is always fully consumed,
* and if it contains multiple frames (e.g. some audio codecs),
* will require you to call avcodec_receive_frame() multiple
* times afterwards before you can send a new packet.
* It can be NULL (or an AVPacket with data set to NULL and
* size set to 0); in this case, it is considered a flush
* packet, which signals the end of the stream. Sending the
* first flush packet will return success. Subsequent ones are
* unnecessary and will return AVERROR_EOF. If the decoder
* still has frames buffered, it will return them after sending
* a flush packet.
*
* @retval 0 success
* @retval AVERROR(EAGAIN) input is not accepted in the current state - user
* must read output with avcodec_receive_frame() (once
* all output is read, the packet should be resent,
* and the call will not fail with EAGAIN).
* @retval AVERROR_EOF the decoder has been flushed, and no new packets can be
* sent to it (also returned if more than 1 flush
* packet is sent)
* @retval AVERROR(EINVAL) codec not opened, it is an encoder, or requires flush
* @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar
* @retval "another negative error code" legitimate decoding errors
*/
avcodec_send_packet(avctx: number,avpkt: number): Promise<number>;
/**
* Find AVInputFormat based on the short name of the input format.
*/
av_find_input_format(short_name: string): Promise<number>;
/**
* Allocate an AVFormatContext.
* avformat_free_context() can be used to free the context and everything
* allocated by the framework within it.
*/
avformat_alloc_context(): Promise<number>;
/**
* Allocate an AVFormatContext for an output format.
* avformat_free_context() can be used to free the context and
* everything allocated by the framework within it.
*
* @param ctx pointee is set to the created format context,
* or to NULL in case of failure
* @param oformat format to use for allocating the context, if NULL
* format_name and filename are used instead
* @param format_name the name of output format to use for allocating the
* context, if NULL filename is used instead
* @param filename the name of the filename to use for allocating the
* context, may be NULL
*
* @return >= 0 in case of success, a negative AVERROR code in case of
* failure
*/
avformat_alloc_output_context2_js(ctx: number,oformat: string,format_name: string): Promise<number>;
/**
* Close an opened input AVFormatContext. Free it and all its contents
* and set *s to NULL.
*/
avformat_close_input(s: number): Promise<void>;
/**
* Read packets of a media file to get stream information. This
* is useful for file