@lumen5/beamcoder 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +41 -0
- package/.circleci/images/testbeam10-4.1/Dockerfile +12 -0
- package/.circleci/test_image/Dockerfile +14 -0
- package/.circleci/test_image/build.md +13 -0
- package/.eslintrc.js +27 -0
- package/.github/workflows/publish-npm.yml +33 -0
- package/LICENSE +674 -0
- package/README.md +1221 -0
- package/beamstreams.js +692 -0
- package/binding.gyp +103 -0
- package/examples/encode_h264.js +92 -0
- package/examples/jpeg_app.js +55 -0
- package/examples/jpeg_filter_app.js +101 -0
- package/examples/make_mp4.js +123 -0
- package/images/beamcoder_small.jpg +0 -0
- package/index.d.ts +83 -0
- package/index.js +44 -0
- package/install_ffmpeg.js +240 -0
- package/package.json +45 -0
- package/scratch/decode_aac.js +38 -0
- package/scratch/decode_avci.js +50 -0
- package/scratch/decode_hevc.js +38 -0
- package/scratch/decode_pcm.js +39 -0
- package/scratch/make_a_mux.js +68 -0
- package/scratch/muxer.js +74 -0
- package/scratch/read_wav.js +35 -0
- package/scratch/simple_mux.js +39 -0
- package/scratch/stream_avci.js +127 -0
- package/scratch/stream_mp4.js +78 -0
- package/scratch/stream_mux.js +47 -0
- package/scratch/stream_pcm.js +82 -0
- package/scratch/stream_wav.js +62 -0
- package/scripts/install_beamcoder_dependencies.sh +25 -0
- package/src/adaptor.h +202 -0
- package/src/beamcoder.cc +937 -0
- package/src/beamcoder_util.cc +1129 -0
- package/src/beamcoder_util.h +206 -0
- package/src/codec.cc +7386 -0
- package/src/codec.h +44 -0
- package/src/codec_par.cc +1818 -0
- package/src/codec_par.h +40 -0
- package/src/decode.cc +569 -0
- package/src/decode.h +75 -0
- package/src/demux.cc +584 -0
- package/src/demux.h +88 -0
- package/src/encode.cc +496 -0
- package/src/encode.h +72 -0
- package/src/filter.cc +1888 -0
- package/src/filter.h +30 -0
- package/src/format.cc +5287 -0
- package/src/format.h +77 -0
- package/src/frame.cc +2681 -0
- package/src/frame.h +52 -0
- package/src/governor.cc +286 -0
- package/src/governor.h +30 -0
- package/src/hwcontext.cc +378 -0
- package/src/hwcontext.h +35 -0
- package/src/log.cc +186 -0
- package/src/log.h +20 -0
- package/src/mux.cc +834 -0
- package/src/mux.h +106 -0
- package/src/packet.cc +762 -0
- package/src/packet.h +49 -0
- package/test/codecParamsSpec.js +148 -0
- package/test/decoderSpec.js +56 -0
- package/test/demuxerSpec.js +41 -0
- package/test/encoderSpec.js +69 -0
- package/test/filtererSpec.js +47 -0
- package/test/formatSpec.js +343 -0
- package/test/frameSpec.js +145 -0
- package/test/introspectionSpec.js +73 -0
- package/test/muxerSpec.js +34 -0
- package/test/packetSpec.js +122 -0
- package/types/Beamstreams.d.ts +98 -0
- package/types/Codec.d.ts +123 -0
- package/types/CodecContext.d.ts +555 -0
- package/types/CodecPar.d.ts +108 -0
- package/types/Decoder.d.ts +137 -0
- package/types/Demuxer.d.ts +113 -0
- package/types/Encoder.d.ts +94 -0
- package/types/Filter.d.ts +324 -0
- package/types/FormatContext.d.ts +380 -0
- package/types/Frame.d.ts +295 -0
- package/types/HWContext.d.ts +62 -0
- package/types/Muxer.d.ts +121 -0
- package/types/Packet.d.ts +82 -0
- package/types/PrivClass.d.ts +25 -0
- package/types/Stream.d.ts +165 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { Stream } from "./Stream"
|
|
2
|
+
import { PrivClass } from "./PrivClass"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Describes a supported input format
|
|
6
|
+
*/
|
|
7
|
+
export interface InputFormat {
|
|
8
|
+
/** Object name. */
|
|
9
|
+
readonly type: 'InputFormat'
|
|
10
|
+
/** A comma separated list of short names for the format. */
|
|
11
|
+
readonly name: string
|
|
12
|
+
/** Descriptive name for the format, meant to be more human-readable */
|
|
13
|
+
readonly long_name: string
|
|
14
|
+
readonly flags: {
|
|
15
|
+
NOFILE: boolean
|
|
16
|
+
/** Needs '%d' in filename. */
|
|
17
|
+
NEEDNUMBER: boolean
|
|
18
|
+
/** Show format stream IDs numbers. */
|
|
19
|
+
SHOW_IDS: boolean
|
|
20
|
+
/** Use generic index building code. */
|
|
21
|
+
GENERIC_INDEX: boolean
|
|
22
|
+
/** Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
|
|
23
|
+
TS_DISCONT: boolean
|
|
24
|
+
/** Format does not allow to fall back on binary search via read_timestamp */
|
|
25
|
+
NOBINSEARCH: boolean
|
|
26
|
+
/** Format does not allow to fall back on generic search */
|
|
27
|
+
NOGENSEARCH: boolean
|
|
28
|
+
/** Format does not allow seeking by bytes */
|
|
29
|
+
NO_BYTE_SEEK: boolean
|
|
30
|
+
/** Seeking is based on PTS */
|
|
31
|
+
SEEK_TO_PTS: boolean
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* If extensions are defined, then no probe is done. You should
|
|
35
|
+
* usually not use extension format guessing because it is not
|
|
36
|
+
* reliable enough
|
|
37
|
+
*/
|
|
38
|
+
readonly extensions: string
|
|
39
|
+
/**
|
|
40
|
+
* List of supported codec_id-codec_tag pairs, ordered by "better
|
|
41
|
+
* choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
|
|
42
|
+
*/
|
|
43
|
+
readonly codec_tag: ReadonlyArray<{
|
|
44
|
+
id: number
|
|
45
|
+
tag: string | number
|
|
46
|
+
}>
|
|
47
|
+
/** Class for private context */
|
|
48
|
+
readonly priv_class: PrivClass | null
|
|
49
|
+
/**
|
|
50
|
+
* Comma-separated list of mime types.
|
|
51
|
+
* It is used check for matching mime types while probing.
|
|
52
|
+
*/
|
|
53
|
+
readonly mime_type: string
|
|
54
|
+
/** Raw demuxers store their codec ID here. */
|
|
55
|
+
readonly raw_codec_id: string
|
|
56
|
+
/** Size of private data so that it can be allocated. */
|
|
57
|
+
readonly priv_data_size: number
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Describes a supported input format
|
|
62
|
+
*/
|
|
63
|
+
export interface OutputFormat {
|
|
64
|
+
/** Object name. */
|
|
65
|
+
readonly type: 'OutputFormat'
|
|
66
|
+
/** A comma separated list of short names for the format. */
|
|
67
|
+
name: string
|
|
68
|
+
/** Descriptive name for the format, meant to be more human-readable */
|
|
69
|
+
long_name: string
|
|
70
|
+
/**
|
|
71
|
+
* Comma-separated list of mime types.
|
|
72
|
+
* It is used check for matching mime types while probing.
|
|
73
|
+
*/
|
|
74
|
+
mime_type: string
|
|
75
|
+
/** comma-separated filename extensions */
|
|
76
|
+
extensions: string
|
|
77
|
+
/** default audio codec */
|
|
78
|
+
audio_codec: string
|
|
79
|
+
/** default video codec */
|
|
80
|
+
video_codec: string
|
|
81
|
+
/** default subtitle codec */
|
|
82
|
+
subtitle_codec: string
|
|
83
|
+
flags: {
|
|
84
|
+
NOFILE?: boolean
|
|
85
|
+
/** Needs '%d' in filename. */
|
|
86
|
+
NEEDNUMBER?: boolean
|
|
87
|
+
/** Format wants global header. */
|
|
88
|
+
GLOBALHEADER?: boolean
|
|
89
|
+
/** Format does not need / have any timestamps. */
|
|
90
|
+
NOTIMESTAMPS?: boolean
|
|
91
|
+
/** Format allows variable fps. */
|
|
92
|
+
VARIABLE_FPS?: boolean
|
|
93
|
+
/** Format does not need width/height */
|
|
94
|
+
NODIMENSIONS?: boolean
|
|
95
|
+
/** Format does not require any streams */
|
|
96
|
+
NOSTREAMS?: boolean
|
|
97
|
+
/** Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */
|
|
98
|
+
ALLOW_FLUSH?: boolean
|
|
99
|
+
/** Format does not require strictly increasing timestamps, but they must still be monotonic */
|
|
100
|
+
TS_NONSTRICT?: boolean
|
|
101
|
+
/**
|
|
102
|
+
* Format allows muxing negative timestamps. If not set the timestamp will be shifted in av_write_frame and
|
|
103
|
+
* av_interleaved_write_frame so they start from 0.
|
|
104
|
+
* The user or muxer can override this through AVFormatContext.avoid_negative_ts
|
|
105
|
+
*/
|
|
106
|
+
TS_NEGATIVE?: boolean
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* List of supported codec_id-codec_tag pairs, ordered by "better
|
|
110
|
+
* choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
|
|
111
|
+
*/
|
|
112
|
+
codec_tag: Array<{
|
|
113
|
+
id: number
|
|
114
|
+
tag: string | number
|
|
115
|
+
}>
|
|
116
|
+
/** Class for private context */
|
|
117
|
+
priv_class: PrivClass | null
|
|
118
|
+
/** size of private data so that it can be allocated */
|
|
119
|
+
priv_data_size: number
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Return the output format in the list of registered output formats which best matches the provided name,
|
|
124
|
+
* or return null if there is no match.
|
|
125
|
+
*/
|
|
126
|
+
export function guessFormat(name: string): OutputFormat | null;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Format I/O context.
|
|
130
|
+
*/
|
|
131
|
+
export interface FormatContext {
|
|
132
|
+
/** Object name. */
|
|
133
|
+
readonly type: string
|
|
134
|
+
/** The input format description. */
|
|
135
|
+
iformat: InputFormat
|
|
136
|
+
/** The output format description. */
|
|
137
|
+
oformat: OutputFormat
|
|
138
|
+
/** Format private data. */
|
|
139
|
+
priv_data: {
|
|
140
|
+
[key: string]: any
|
|
141
|
+
}
|
|
142
|
+
/** Flags signalling stream properties. */
|
|
143
|
+
readonly ctx_flags: {
|
|
144
|
+
NOHEADER: boolean
|
|
145
|
+
UNSEEKABLE: boolean
|
|
146
|
+
}
|
|
147
|
+
/** An array of all streams in the file. */
|
|
148
|
+
streams: Array<Stream>
|
|
149
|
+
/** input or output URL. Unlike the old filename field, this field has no length restriction. */
|
|
150
|
+
url: string
|
|
151
|
+
/**
|
|
152
|
+
* Position of the first frame of the component, in
|
|
153
|
+
* AV_TIME_BASE fractional seconds. NEVER set this value directly:
|
|
154
|
+
* It is deduced from the AVStream values. Demuxing only
|
|
155
|
+
*/
|
|
156
|
+
readonly start_time: number
|
|
157
|
+
/**
|
|
158
|
+
* Duration of the stream, in AV_TIME_BASE fractional
|
|
159
|
+
* seconds. Only set this value if you know none of the individual stream
|
|
160
|
+
* durations and also do not set any of them. This is deduced from the
|
|
161
|
+
* Stream values if not set.
|
|
162
|
+
*/
|
|
163
|
+
duration: number
|
|
164
|
+
/**
|
|
165
|
+
* Total stream bitrate in bit/s, 0 if not
|
|
166
|
+
* available. Never set it directly if the file_size and the
|
|
167
|
+
* duration are known as FFmpeg can compute it automatically.
|
|
168
|
+
*/
|
|
169
|
+
bit_rate: number
|
|
170
|
+
|
|
171
|
+
packet_size: number
|
|
172
|
+
max_delay: number
|
|
173
|
+
/** Flags modifying the demuxer behaviour. A combination of AVFMT_FLAG_*. */
|
|
174
|
+
flags: {
|
|
175
|
+
/** Generate missing pts even if it requires parsing future frames. */
|
|
176
|
+
GENPTS?: boolean
|
|
177
|
+
/** Ignore index. */
|
|
178
|
+
IGNIDX?: boolean
|
|
179
|
+
/** Do not block when reading packets from input. */
|
|
180
|
+
NONBLOCK?: boolean
|
|
181
|
+
/** Ignore DTS on frames that contain both DTS & PTS */
|
|
182
|
+
IGNDTS?: boolean
|
|
183
|
+
/** Do not infer any values from other values, just return what is stored in the container */
|
|
184
|
+
NOFILLIN?: boolean
|
|
185
|
+
/** Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled */
|
|
186
|
+
NOPARSE?: boolean
|
|
187
|
+
/** Do not buffer frames when possible */
|
|
188
|
+
NOBUFFER?: boolean
|
|
189
|
+
/** The caller has supplied a custom AVIOContext, don't avio_close() it. */
|
|
190
|
+
CUSTOM_IO?: boolean
|
|
191
|
+
/** Discard frames marked corrupted */
|
|
192
|
+
DISCARD_CORRUPT?: boolean
|
|
193
|
+
/** Flush the AVIOContext every packet. */
|
|
194
|
+
FLUSH_PACKETS?: boolean
|
|
195
|
+
/** This flag is mainly intended for testing. */
|
|
196
|
+
BITEXACT?: boolean
|
|
197
|
+
/** try to interleave outputted packets by dts (using this flag can slow demuxing down) */
|
|
198
|
+
SORT_DTS?: boolean
|
|
199
|
+
/** Enable use of private options by delaying codec open (this could be made default once all code is converted) */
|
|
200
|
+
PRIV_OPT?: boolean
|
|
201
|
+
/** Enable fast, but inaccurate seeks for some formats */
|
|
202
|
+
FAST_SEEK?: boolean
|
|
203
|
+
/** Stop muxing when the shortest stream stops. */
|
|
204
|
+
SHORTEST?: boolean
|
|
205
|
+
/** Add bitstream filters as requested by the muxer */
|
|
206
|
+
AUTO_BSF?: boolean
|
|
207
|
+
}
|
|
208
|
+
/** Maximum size of the data read from input for determining the input container format. */
|
|
209
|
+
probesize: number
|
|
210
|
+
/**
|
|
211
|
+
* Maximum duration (in AV_TIME_BASE units) of the data read
|
|
212
|
+
* from input in avformat_find_stream_info().
|
|
213
|
+
* Demuxing only, set by the caller before avformat_find_stream_info().
|
|
214
|
+
* Can be set to 0 to let avformat choose using a heuristic.
|
|
215
|
+
*/
|
|
216
|
+
max_analyze_duration: number
|
|
217
|
+
readonly key: Buffer
|
|
218
|
+
readonly programs: ReadonlyArray<object>
|
|
219
|
+
// video_codec_id / audio_codec_id / subtitle_codec_id
|
|
220
|
+
/**
|
|
221
|
+
* Maximum amount of memory in bytes to use for the index of each stream.
|
|
222
|
+
* If the index exceeds this size, entries will be discarded as
|
|
223
|
+
* needed to maintain a smaller size. This can lead to slower or less
|
|
224
|
+
* accurate seeking (depends on demuxer).
|
|
225
|
+
* Demuxers for which a full in-memory index is mandatory will ignore
|
|
226
|
+
* this.
|
|
227
|
+
*/
|
|
228
|
+
max_index_size: number
|
|
229
|
+
/**
|
|
230
|
+
* Maximum amount of memory in bytes to use for buffering frames
|
|
231
|
+
* obtained from realtime capture devices.
|
|
232
|
+
*/
|
|
233
|
+
max_picture_buffer: number
|
|
234
|
+
// chapters?
|
|
235
|
+
/**
|
|
236
|
+
* Metadata that applies to the whole file.
|
|
237
|
+
*/
|
|
238
|
+
metadata: { [key: string]: string }
|
|
239
|
+
/**
|
|
240
|
+
* Start time of the stream in real world time, in microseconds
|
|
241
|
+
* since the Unix epoch (00:00 1st January 1970). That is, pts=0 in the
|
|
242
|
+
* stream was captured at this real world time.
|
|
243
|
+
* AV_NOPTS_VALUE if unknown. Note that the value may become known after
|
|
244
|
+
* some number of frames have been received.
|
|
245
|
+
*/
|
|
246
|
+
start_time_realtime: number | null
|
|
247
|
+
/** The number of frames used for determining the framerate */
|
|
248
|
+
fps_probe_size: number
|
|
249
|
+
/**
|
|
250
|
+
* Error recognition - higher values will detect more errors but may
|
|
251
|
+
* misdetect some more or less valid parts as errors.
|
|
252
|
+
*/
|
|
253
|
+
error_recognition: number
|
|
254
|
+
/** Flags to enable debugging. */
|
|
255
|
+
debug: { TS: boolean }
|
|
256
|
+
/**
|
|
257
|
+
* Maximum buffering duration for interleaving.
|
|
258
|
+
*
|
|
259
|
+
* To ensure all the streams are interleaved correctly,
|
|
260
|
+
* av_interleaved_write_frame() will wait until it has at least one packet
|
|
261
|
+
* for each stream before actually writing any packets to the output file.
|
|
262
|
+
* When some streams are "sparse" (i.e. there are large gaps between
|
|
263
|
+
* successive packets), this can result in excessive buffering.
|
|
264
|
+
*
|
|
265
|
+
* This field specifies the maximum difference between the timestamps of the
|
|
266
|
+
* first and the last packet in the muxing queue, above which libavformat
|
|
267
|
+
* will output a packet regardless of whether it has queued a packet for all
|
|
268
|
+
* the streams.
|
|
269
|
+
*
|
|
270
|
+
* Muxing only, set by the caller before avformat_write_header().
|
|
271
|
+
*/
|
|
272
|
+
max_interleave_delta: number
|
|
273
|
+
/** Allow non-standard and experimental extension */
|
|
274
|
+
strict_std_compliance: 'very-strict' | 'strict' | 'normal' | 'unofficial' | 'experimental'
|
|
275
|
+
/**
|
|
276
|
+
* Flags for the user to detect events happening on the file. Flags must
|
|
277
|
+
* be cleared by the user once the event has been handled.
|
|
278
|
+
* A combination of AVFMT_EVENT_FLAG_*.
|
|
279
|
+
*/
|
|
280
|
+
event_flags: { METADATA_UPDATED?: boolean }
|
|
281
|
+
/** Maximum number of packets to read while waiting for the first timestamp. */
|
|
282
|
+
max_ts_probe: number
|
|
283
|
+
/**
|
|
284
|
+
* Avoid negative timestamps during muxing. Any value of the AVFMT_AVOID_NEG_TS_* constants.
|
|
285
|
+
* Note, this only works when using av_interleaved_write_frame. (interleave_packet_per_dts is in use)
|
|
286
|
+
*/
|
|
287
|
+
avoid_negative_ts: 'auto' | 'make_non_negative' | 'make_zero'
|
|
288
|
+
/** Audio preload in microseconds. Note, not all formats support this and unpredictable things may happen if it is used when not supported. */
|
|
289
|
+
audio_preload: number
|
|
290
|
+
/** Max chunk time in microseconds. Note, not all formats support this and unpredictable things may happen if it is used when not supported. */
|
|
291
|
+
max_chunk_duration: number
|
|
292
|
+
/** Max chunk size in bytes Note, not all formats support this and unpredictable things may happen if it is used when not supported. */
|
|
293
|
+
max_chunk_size: number
|
|
294
|
+
/**
|
|
295
|
+
* forces the use of wallclock timestamps as pts/dts of packets
|
|
296
|
+
* This has undefined results in the presence of B frames.
|
|
297
|
+
*/
|
|
298
|
+
use_wallclock_as_timestamps: boolean
|
|
299
|
+
/** avio flags, used to force AVIO_FLAG_DIRECT. */
|
|
300
|
+
avio_flags: {
|
|
301
|
+
READ?: boolean
|
|
302
|
+
WRITE?: boolean
|
|
303
|
+
NONBLOCK?: boolean
|
|
304
|
+
DIRECT?: boolean
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The duration field can be estimated through various ways, and this field can be used
|
|
308
|
+
* to know how the duration was estimated.
|
|
309
|
+
*/
|
|
310
|
+
readonly duration_estimation_method: 'from_pts' | 'from_stream' | 'from_bitrate'
|
|
311
|
+
/** Skip initial bytes when opening stream */
|
|
312
|
+
skip_initial_bytes: number
|
|
313
|
+
/** Correct single timestamp overflows */
|
|
314
|
+
correct_ts_overflow: boolean
|
|
315
|
+
/** Force seeking to any (also non key) frames. */
|
|
316
|
+
seek2any: boolean
|
|
317
|
+
/** Flush the I/O context after each packet. */
|
|
318
|
+
flush_packets: number
|
|
319
|
+
/**
|
|
320
|
+
* format probing score.
|
|
321
|
+
* The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
|
|
322
|
+
* the format.
|
|
323
|
+
*/
|
|
324
|
+
readonly probe_score: number
|
|
325
|
+
/** number of bytes to read maximally to identify format. */
|
|
326
|
+
format_probesize: number
|
|
327
|
+
/**
|
|
328
|
+
* ',' separated list of allowed decoders.
|
|
329
|
+
* If NULL then all are allowed
|
|
330
|
+
*/
|
|
331
|
+
codec_whitelist: string | null
|
|
332
|
+
/**
|
|
333
|
+
* ',' separated list of allowed demuxers.
|
|
334
|
+
* If NULL then all are allowed
|
|
335
|
+
*/
|
|
336
|
+
format_whitelist: string | null
|
|
337
|
+
/**
|
|
338
|
+
* IO repositioned flag.
|
|
339
|
+
* This is set by avformat when the underlaying IO context read pointer
|
|
340
|
+
* is repositioned, for example when doing byte based seeking.
|
|
341
|
+
* Demuxers can use the flag to detect such changes.
|
|
342
|
+
*/
|
|
343
|
+
readonly io_repositioned: boolean
|
|
344
|
+
/** Number of bytes to be written as padding in a metadata header. */
|
|
345
|
+
metadata_header_padding: number
|
|
346
|
+
// not exposing opaque
|
|
347
|
+
/** Output timestamp offset, in microseconds. */
|
|
348
|
+
output_ts_offset: number
|
|
349
|
+
/**
|
|
350
|
+
* dump format separator.
|
|
351
|
+
* can be ", " or "\n " or anything else
|
|
352
|
+
*/
|
|
353
|
+
dump_separator: string
|
|
354
|
+
/** ',' separated list of allowed protocols. */
|
|
355
|
+
protocol_whitelist: string
|
|
356
|
+
/** ',' separated list of disallowed protocols. */
|
|
357
|
+
protocol_blacklist: string
|
|
358
|
+
/** The maximum number of streams. */
|
|
359
|
+
max_streams: number
|
|
360
|
+
/** Skip duration calcuation in estimate_timings_from_pts. */
|
|
361
|
+
skip_estimate_duration_from_pts: boolean
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Add a stream to the format with the next available stream index.
|
|
365
|
+
* @param options Object including the codec name for the stream and any other parameters that need
|
|
366
|
+
* to be initialised in the Stream object
|
|
367
|
+
* @returns A Stream object
|
|
368
|
+
*/
|
|
369
|
+
newStream(options: { name: string, [key: string]: any }): Stream
|
|
370
|
+
/**
|
|
371
|
+
* Add a stream to the format with the next available stream index.
|
|
372
|
+
* @param stream Source stream from which to copy the parameters for the new stream
|
|
373
|
+
* @returns A Stream object
|
|
374
|
+
*/
|
|
375
|
+
newStream(stream: Stream): Stream
|
|
376
|
+
/** Retun a JSON string containing the object properties. */
|
|
377
|
+
toJSON(): string
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function format(options: { [key: string]: any }): FormatContext
|
package/types/Frame.d.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { HWFramesContext } from "./HWContext";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This object describes decoded (raw) audio or video data.
|
|
5
|
+
*/
|
|
6
|
+
export interface Frame {
|
|
7
|
+
/** Object name. */
|
|
8
|
+
readonly type: 'Frame'
|
|
9
|
+
/**
|
|
10
|
+
* For video, size in bytes of each picture line.
|
|
11
|
+
* For audio, size in bytes of each plane.
|
|
12
|
+
*
|
|
13
|
+
* For audio, only linesize[0] may be set. For planar audio, each channel
|
|
14
|
+
* plane must be the same size.
|
|
15
|
+
*
|
|
16
|
+
* For video the linesizes should be multiples of the CPUs alignment
|
|
17
|
+
* preference, this is 16 or 32 for modern desktop CPUs.
|
|
18
|
+
* Some code requires such alignment other code can be slower without
|
|
19
|
+
* correct alignment, for yet other it makes no difference.
|
|
20
|
+
*
|
|
21
|
+
* @note The linesize may be larger than the size of usable data -- there
|
|
22
|
+
* may be extra padding present for performance reasons.
|
|
23
|
+
*/
|
|
24
|
+
linesize: Array<number>
|
|
25
|
+
/**
|
|
26
|
+
* Video dimensions
|
|
27
|
+
* Video frames only. The coded dimensions (in pixels) of the video frame,
|
|
28
|
+
* i.e. the size of the rectangle that contains some well-defined values.
|
|
29
|
+
*
|
|
30
|
+
* @note The part of the frame intended for display/presentation is further
|
|
31
|
+
* restricted by the "Cropping rectangle".
|
|
32
|
+
*/
|
|
33
|
+
width: number
|
|
34
|
+
height: number
|
|
35
|
+
/** number of audio samples (per channel) described by this frame */
|
|
36
|
+
nb_samples: number
|
|
37
|
+
/** format of the frame, null if unknown or unset */
|
|
38
|
+
format: string | null
|
|
39
|
+
/** Whether this frame is a keyframe */
|
|
40
|
+
key_frame: boolean
|
|
41
|
+
/** Picture type of the frame. */
|
|
42
|
+
pict_type: 'I' | 'P' | 'B' | 'S' | 'SI' | 'SP' | 'BI' | null
|
|
43
|
+
/** Sample aspect ratio for the video frame, 0/1 if unknown/unspecified. */
|
|
44
|
+
sample_aspect_ratio: Array<number>
|
|
45
|
+
/** Presentation timestamp in time_base units (time when frame should be shown to user). */
|
|
46
|
+
pts: number
|
|
47
|
+
/**
|
|
48
|
+
* DTS copied from the Packet that triggered returning this frame. (if frame threading isn't used)
|
|
49
|
+
* This is also the Presentation time of this Frame calculated from
|
|
50
|
+
* only Packet.dts values without pts values.
|
|
51
|
+
*/
|
|
52
|
+
pkt_dts: number
|
|
53
|
+
/** picture number in bitstream order */
|
|
54
|
+
coded_picture_number: number
|
|
55
|
+
/** picture number in display order */
|
|
56
|
+
display_picture_number: number
|
|
57
|
+
/** quality (between 1 (good) and FF_LAMBDA_MAX (bad)) */
|
|
58
|
+
quality: number
|
|
59
|
+
/**
|
|
60
|
+
* When decoding, this signals how much the picture must be delayed.
|
|
61
|
+
* extra_delay = repeat_pict / (2*fps)
|
|
62
|
+
*/
|
|
63
|
+
repeat_pict: number
|
|
64
|
+
/** The content of the picture is interlaced. */
|
|
65
|
+
interlaced_frame: boolean
|
|
66
|
+
/** If the content is interlaced, is top field displayed first. */
|
|
67
|
+
top_field_first: boolean
|
|
68
|
+
/** Tell user application that palette has changed from previous frame. */
|
|
69
|
+
palette_has_changed: boolean
|
|
70
|
+
/**
|
|
71
|
+
* reordered opaque 64 bits (generally an integer or a double precision float
|
|
72
|
+
* PTS but can be anything).
|
|
73
|
+
* The user sets AVCodecContext.reordered_opaque to represent the input at
|
|
74
|
+
* that time,
|
|
75
|
+
* the decoder reorders values as needed and sets AVFrame.reordered_opaque
|
|
76
|
+
* to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
|
|
77
|
+
* @deprecated in favor of pkt_pts
|
|
78
|
+
*/
|
|
79
|
+
reordered_opaque: number | null
|
|
80
|
+
/** Sample rate of the audio data. */
|
|
81
|
+
sample_rate: number
|
|
82
|
+
/** Channel layout of the audio data. */
|
|
83
|
+
channel_layout: string
|
|
84
|
+
/**
|
|
85
|
+
* Raw data for the picture/channel planes.
|
|
86
|
+
*
|
|
87
|
+
* Some decoders access areas outside 0,0 - width,height, please
|
|
88
|
+
* see avcodec_align_dimensions2(). Some filters and swscale can read
|
|
89
|
+
* up to 16 bytes beyond the planes, if these filters are to be used,
|
|
90
|
+
* then 16 extra bytes must be allocated.
|
|
91
|
+
*/
|
|
92
|
+
data: Array<Buffer>
|
|
93
|
+
/**
|
|
94
|
+
* Additional data that can be provided by the container.
|
|
95
|
+
* Frame can contain several types of side information.
|
|
96
|
+
*/
|
|
97
|
+
side_data: { type: string, [key: string]: Buffer | string } | null
|
|
98
|
+
/** Frame flags */
|
|
99
|
+
flags: {
|
|
100
|
+
CORRUPT?: boolean
|
|
101
|
+
DISCARD?: boolean
|
|
102
|
+
}
|
|
103
|
+
/** MPEG vs JPEG YUV range. */
|
|
104
|
+
color_range: string
|
|
105
|
+
/** Chromaticity coordinates of the source primaries. */
|
|
106
|
+
color_primaries?: string
|
|
107
|
+
/** Color Transfer Characteristic. */
|
|
108
|
+
color_trc: string
|
|
109
|
+
/** YUV colorspace type. */
|
|
110
|
+
colorspace: string
|
|
111
|
+
/**
|
|
112
|
+
* Location of chroma samples.
|
|
113
|
+
*
|
|
114
|
+
* Illustration showing the location of the first (top left) chroma sample of the
|
|
115
|
+
* image, the left shows only luma, the right
|
|
116
|
+
* shows the location of the chroma sample, the 2 could be imagined to overlay
|
|
117
|
+
* each other but are drawn separately due to limitations of ASCII
|
|
118
|
+
*```
|
|
119
|
+
* 1st 2nd 1st 2nd horizontal luma sample positions
|
|
120
|
+
* v v v v
|
|
121
|
+
* ______ ______
|
|
122
|
+
*1st luma line > |X X ... |3 4 X ... X are luma samples,
|
|
123
|
+
*. | |1 2 1-6 are possible chroma positions
|
|
124
|
+
*2nd luma line > |X X ... |5 6 X ... 0 is undefined/unknown position
|
|
125
|
+
*```
|
|
126
|
+
*/
|
|
127
|
+
chroma_location: 'unspecified' | 'left' | 'center' | 'topleft' | 'top' | 'bottomleft' | 'bottom'
|
|
128
|
+
/** frame timestamp estimated using various heuristics, in stream time base */
|
|
129
|
+
best_effort_timestamp: number
|
|
130
|
+
/** reordered pos from the last AVPacket that has been input into the decoder */
|
|
131
|
+
pkt_pos: number
|
|
132
|
+
/** duration of the corresponding packet, expressed in Stream->time_base units, 0 if unknown. */
|
|
133
|
+
pkt_duration: number
|
|
134
|
+
metadata: { [key: string]: string }
|
|
135
|
+
/**
|
|
136
|
+
* decode error flags of the frame, set if the decoder produced a frame, but there
|
|
137
|
+
* were errors during the decoding.
|
|
138
|
+
*/
|
|
139
|
+
decode_error_flags: {
|
|
140
|
+
INVALID_BITSTREAM: boolean
|
|
141
|
+
MISSING_REFERENCE: boolean
|
|
142
|
+
}
|
|
143
|
+
/** number of audio channels, only used for audio. */
|
|
144
|
+
channels: number
|
|
145
|
+
/**
|
|
146
|
+
* size of the corresponding packet containing the compressed frame.
|
|
147
|
+
* It is set to a negative value if unknown.
|
|
148
|
+
*/
|
|
149
|
+
pkt_size: number
|
|
150
|
+
/**
|
|
151
|
+
* For hwaccel-format frames, this should be a reference to the
|
|
152
|
+
* HWFramesContext describing the frame.
|
|
153
|
+
*/
|
|
154
|
+
hw_frames_ctx: HWFramesContext
|
|
155
|
+
/**
|
|
156
|
+
* Video frames only. The number of pixels to discard from the the
|
|
157
|
+
* top/bottom/left/right border of the frame to obtain the sub-rectangle of
|
|
158
|
+
* the frame intended for presentation.
|
|
159
|
+
*/
|
|
160
|
+
crop_top: number
|
|
161
|
+
crop_bottom: number
|
|
162
|
+
crop_left: number
|
|
163
|
+
crop_right: number
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Beam coder exposes some of FFmpeg's ability to calculate the size of data buffers.
|
|
167
|
+
* If you pass width, height and format properties for video frames, or channels/channel_layout,
|
|
168
|
+
* sample_rate and format for audio frames, as options to the frame constructor then the linesize
|
|
169
|
+
* array (number of bytes per line per plane) is computed. For video, multiply each value by the
|
|
170
|
+
* height to get the minimum buffer size for the plane. For audio, the first element of the array
|
|
171
|
+
* is the buffer size for each plane.
|
|
172
|
+
*
|
|
173
|
+
* To use the linesize numbers to automatically allocate buffers of the correct size,
|
|
174
|
+
* call alloc() after the factory method. For example:
|
|
175
|
+
* `let f = beamcoder.frame({ width: 1920, height: 1080, format: 'yuv422p' }).alloc()`
|
|
176
|
+
*/
|
|
177
|
+
alloc(): Frame
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Create a frame for encoding or filtering
|
|
182
|
+
* Set parameters as required from the Frame object
|
|
183
|
+
*/
|
|
184
|
+
export function frame(options: { [key: string]: any, data?: Array<Buffer> }): Frame
|
|
185
|
+
|
|
186
|
+
/** Pixel format description */
|
|
187
|
+
export interface PixelFormat {
|
|
188
|
+
name: string
|
|
189
|
+
/** The number of components each pixel has, (1-4) */
|
|
190
|
+
nb_components: number
|
|
191
|
+
/**
|
|
192
|
+
* Amount to shift the luma height right to find the chroma height.
|
|
193
|
+
* For YV12 this is 1 for example.
|
|
194
|
+
* chroma_height= AV_CEIL_RSHIFT(luma_height, log2_chroma_h)
|
|
195
|
+
* The note above is needed to ensure rounding up.
|
|
196
|
+
* This value only refers to the chroma components.
|
|
197
|
+
*/
|
|
198
|
+
log2_chroma_h: number
|
|
199
|
+
/**
|
|
200
|
+
* Amount to shift the luma width right to find the chroma width.
|
|
201
|
+
* For YV12 this is 1 for example.
|
|
202
|
+
* chroma_width = AV_CEIL_RSHIFT(luma_width, log2_chroma_w)
|
|
203
|
+
* The note above is needed to ensure rounding up.
|
|
204
|
+
* This value only refers to the chroma components.
|
|
205
|
+
*/
|
|
206
|
+
log2_chroma_w: number
|
|
207
|
+
flags: {
|
|
208
|
+
/** Pixel format is big-endian. */
|
|
209
|
+
BE: boolean
|
|
210
|
+
/** Pixel format has a palette in data[1], values are indexes in this palette. */
|
|
211
|
+
PAL: boolean
|
|
212
|
+
/** All values of a component are bit-wise packed end to end. */
|
|
213
|
+
BITSTREAM: boolean
|
|
214
|
+
/** Pixel format is an HW accelerated format. */
|
|
215
|
+
HWACCEL: boolean
|
|
216
|
+
/** At least one pixel component is not in the first data plane. */
|
|
217
|
+
PLANAR: boolean
|
|
218
|
+
/** The pixel format contains RGB-like data (as opposed to YUV/grayscale). */
|
|
219
|
+
RGB: boolean
|
|
220
|
+
/**
|
|
221
|
+
* The pixel format is "pseudo-paletted". This means that it contains a
|
|
222
|
+
* fixed palette in the 2nd plane but the palette is fixed/constant for each
|
|
223
|
+
* PIX_FMT. This allows interpreting the data as if it was PAL8, which can
|
|
224
|
+
* in some cases be simpler. Or the data can be interpreted purely based on
|
|
225
|
+
* the pixel format without using the palette.
|
|
226
|
+
* An example of a pseudo-paletted format is AV_PIX_FMT_GRAY8
|
|
227
|
+
* @deprecated This flag is deprecated, and will be removed.
|
|
228
|
+
*/
|
|
229
|
+
PSEUDOPAL: boolean
|
|
230
|
+
/**
|
|
231
|
+
* The pixel format has an alpha channel. This is set on all formats that
|
|
232
|
+
* support alpha in some way, including AV_PIX_FMT_PAL8. The alpha is always
|
|
233
|
+
* straight, never pre-multiplied.
|
|
234
|
+
|
|
235
|
+
* If a codec or a filter does not support alpha, it should set all alpha to
|
|
236
|
+
* opaque, or use the equivalent pixel formats without alpha component, e.g.
|
|
237
|
+
* AV_PIX_FMT_RGB0 (or AV_PIX_FMT_RGB24 etc.) instead of AV_PIX_FMT_RGBA.
|
|
238
|
+
*/
|
|
239
|
+
ALPHA: boolean
|
|
240
|
+
/** The pixel format is following a Bayer pattern. */
|
|
241
|
+
BAYER: boolean
|
|
242
|
+
/**
|
|
243
|
+
* The pixel format contains IEEE-754 floating point values. Precision (double,
|
|
244
|
+
* single, or half) should be determined by the pixel size (64, 32, or 16 bits).
|
|
245
|
+
*/
|
|
246
|
+
FLOAT: boolean
|
|
247
|
+
}
|
|
248
|
+
comp: Array< {
|
|
249
|
+
/** Code letter for the contents of the component */
|
|
250
|
+
code: 'R' | 'G' | 'B' | 'Y' | 'U' | 'V' | 'A'
|
|
251
|
+
/** Which of the 4 planes contains the component. */
|
|
252
|
+
plane: number
|
|
253
|
+
/**
|
|
254
|
+
* Number of elements between 2 horizontally consecutive pixels.
|
|
255
|
+
* Elements are bits for bitstream formats, bytes otherwise.
|
|
256
|
+
*/
|
|
257
|
+
step: number
|
|
258
|
+
/**
|
|
259
|
+
* Number of elements before the component of the first pixel.
|
|
260
|
+
* Elements are bits for bitstream formats, bytes otherwise.
|
|
261
|
+
*/
|
|
262
|
+
offset: number
|
|
263
|
+
/** Number of least significant bits that must be shifted away to get the value. */
|
|
264
|
+
shift: number
|
|
265
|
+
/** Number of bits in the component. */
|
|
266
|
+
depth: number
|
|
267
|
+
}>
|
|
268
|
+
/** Alternative comma-separated names. */
|
|
269
|
+
alias: string
|
|
270
|
+
}
|
|
271
|
+
/** Format details for all supported pixel format names */
|
|
272
|
+
export function pix_fmts(): { [key: string]: PixelFormat }
|
|
273
|
+
|
|
274
|
+
/** Audio sample formats */
|
|
275
|
+
export interface SampleFormat {
|
|
276
|
+
type: 'SampleFormat'
|
|
277
|
+
name: string
|
|
278
|
+
/** The packed alternative form of the sample format. */
|
|
279
|
+
packed: string
|
|
280
|
+
/** The planar alternative form of the sample format. */
|
|
281
|
+
planar: string
|
|
282
|
+
/** Number of bytes per sample or zero if unknown. */
|
|
283
|
+
bytes_per_sample: number
|
|
284
|
+
/** Whether the sample format is planar. */
|
|
285
|
+
is_planar: boolean
|
|
286
|
+
}
|
|
287
|
+
/** Format details for all supported sample format names */
|
|
288
|
+
export function sample_fmts(): { [key: string]: SampleFormat }
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Note that when creating buffers from Javascript,
|
|
292
|
+
* FFmpeg recommends that a small amount of headroom is added to the minimum length of each buffer.
|
|
293
|
+
* The minimum amount of padding is exposed to Javascript as constant
|
|
294
|
+
*/
|
|
295
|
+
export const AV_INPUT_BUFFER_PADDING_SIZE: number
|