node-av 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/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOStream - Custom I/O Factory for FFmpeg
|
|
3
|
+
*
|
|
4
|
+
* Provides factory methods for creating IOContext instances from various sources.
|
|
5
|
+
* Supports Buffers for in-memory operations and custom callbacks for full control.
|
|
6
|
+
*
|
|
7
|
+
* All methods are static - this class cannot be instantiated.
|
|
8
|
+
* Use the overloaded create() method to create IOContext from different input types.
|
|
9
|
+
*
|
|
10
|
+
* @module api/io-stream
|
|
11
|
+
*/
|
|
12
|
+
import { IOContext } from '../lib/index.js';
|
|
13
|
+
import type { IOInputCallbacks, MediaInputOptions } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Factory class for creating IOContext instances.
|
|
16
|
+
*
|
|
17
|
+
* Provides a unified interface for creating custom I/O contexts from:
|
|
18
|
+
* - Buffers for in-memory data
|
|
19
|
+
* - Custom callbacks for full I/O control
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { IOStream } from 'node-av/api';
|
|
24
|
+
* import { readFile } from 'fs/promises';
|
|
25
|
+
*
|
|
26
|
+
* // From Buffer
|
|
27
|
+
* const buffer = await readFile('video.mp4');
|
|
28
|
+
* const ioContext = IOStream.create(buffer);
|
|
29
|
+
*
|
|
30
|
+
* // From custom callbacks
|
|
31
|
+
* const ioContext = IOStream.create({
|
|
32
|
+
* read: (size) => customSource.read(size),
|
|
33
|
+
* seek: (offset, whence) => customSource.seek(offset, whence)
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class IOStream {
|
|
38
|
+
private constructor();
|
|
39
|
+
/**
|
|
40
|
+
* Create IOContext from a Buffer.
|
|
41
|
+
*
|
|
42
|
+
* Creates an I/O context for reading from in-memory data.
|
|
43
|
+
* Automatically handles seeking within the buffer.
|
|
44
|
+
*
|
|
45
|
+
* @param buffer - Buffer containing media data
|
|
46
|
+
* @param options - Optional configuration
|
|
47
|
+
*
|
|
48
|
+
* @returns IOContext instance ready for use
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const buffer = await readFile('video.mp4');
|
|
53
|
+
* const ioContext = IOStream.create(buffer);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
static create(buffer: Buffer, options?: MediaInputOptions): IOContext;
|
|
57
|
+
/**
|
|
58
|
+
* Create IOContext from custom callbacks.
|
|
59
|
+
*
|
|
60
|
+
* Creates an I/O context with custom read and seek operations.
|
|
61
|
+
* Callbacks must be synchronous and return immediately.
|
|
62
|
+
*
|
|
63
|
+
* @param callbacks - Custom I/O callbacks (read required, seek optional)
|
|
64
|
+
* @param options - Optional configuration
|
|
65
|
+
*
|
|
66
|
+
* @returns IOContext instance ready for use
|
|
67
|
+
*
|
|
68
|
+
* @throws {Error} If read callback is not provided
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const ioContext = IOStream.create({
|
|
73
|
+
* read: (size) => buffer.slice(pos, pos + size),
|
|
74
|
+
* seek: (offset, whence) => calculatePosition(offset, whence)
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static create(callbacks: IOInputCallbacks, options?: MediaInputOptions): IOContext;
|
|
79
|
+
/**
|
|
80
|
+
* Create IOContext from a Buffer with position tracking.
|
|
81
|
+
*
|
|
82
|
+
* Sets up read and seek callbacks that operate on the buffer.
|
|
83
|
+
* Maintains internal position state for sequential reading.
|
|
84
|
+
*
|
|
85
|
+
* @param buffer - Buffer containing the data
|
|
86
|
+
* @param bufferSize - Internal buffer size for IOContext
|
|
87
|
+
*
|
|
88
|
+
* @returns Configured IOContext instance
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
private static createFromBuffer;
|
|
93
|
+
/**
|
|
94
|
+
* Create IOContext from user-provided callbacks.
|
|
95
|
+
*
|
|
96
|
+
* Validates and wraps the provided callbacks for use with FFmpeg.
|
|
97
|
+
* Only supports read mode as high-level API doesn't expose write operations.
|
|
98
|
+
*
|
|
99
|
+
* @param callbacks - User-provided I/O callbacks
|
|
100
|
+
* @param bufferSize - Internal buffer size for IOContext
|
|
101
|
+
*
|
|
102
|
+
* @returns Configured IOContext instance
|
|
103
|
+
*
|
|
104
|
+
* @throws {Error} If read callback is not provided
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
private static createFromCallbacks;
|
|
109
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IOStream - Custom I/O Factory for FFmpeg
|
|
3
|
+
*
|
|
4
|
+
* Provides factory methods for creating IOContext instances from various sources.
|
|
5
|
+
* Supports Buffers for in-memory operations and custom callbacks for full control.
|
|
6
|
+
*
|
|
7
|
+
* All methods are static - this class cannot be instantiated.
|
|
8
|
+
* Use the overloaded create() method to create IOContext from different input types.
|
|
9
|
+
*
|
|
10
|
+
* @module api/io-stream
|
|
11
|
+
*/
|
|
12
|
+
import { AVSEEK_CUR, AVSEEK_END, AVSEEK_SET, AVSEEK_SIZE, IOContext } from '../lib/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Factory class for creating IOContext instances.
|
|
15
|
+
*
|
|
16
|
+
* Provides a unified interface for creating custom I/O contexts from:
|
|
17
|
+
* - Buffers for in-memory data
|
|
18
|
+
* - Custom callbacks for full I/O control
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { IOStream } from 'node-av/api';
|
|
23
|
+
* import { readFile } from 'fs/promises';
|
|
24
|
+
*
|
|
25
|
+
* // From Buffer
|
|
26
|
+
* const buffer = await readFile('video.mp4');
|
|
27
|
+
* const ioContext = IOStream.create(buffer);
|
|
28
|
+
*
|
|
29
|
+
* // From custom callbacks
|
|
30
|
+
* const ioContext = IOStream.create({
|
|
31
|
+
* read: (size) => customSource.read(size),
|
|
32
|
+
* seek: (offset, whence) => customSource.seek(offset, whence)
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class IOStream {
|
|
37
|
+
// Private constructor to prevent instantiation
|
|
38
|
+
constructor() {
|
|
39
|
+
throw new Error('IOStream is a static class and cannot be instantiated');
|
|
40
|
+
}
|
|
41
|
+
static create(input, options = {}) {
|
|
42
|
+
const { bufferSize = 8192 } = options;
|
|
43
|
+
// Handle Buffer
|
|
44
|
+
if (Buffer.isBuffer(input)) {
|
|
45
|
+
return this.createFromBuffer(input, bufferSize);
|
|
46
|
+
}
|
|
47
|
+
// Handle custom callbacks
|
|
48
|
+
if (typeof input === 'object' && 'read' in input) {
|
|
49
|
+
return this.createFromCallbacks(input, bufferSize);
|
|
50
|
+
}
|
|
51
|
+
throw new TypeError('Invalid input type. Expected Buffer or IOInputCallbacks');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create IOContext from a Buffer with position tracking.
|
|
55
|
+
*
|
|
56
|
+
* Sets up read and seek callbacks that operate on the buffer.
|
|
57
|
+
* Maintains internal position state for sequential reading.
|
|
58
|
+
*
|
|
59
|
+
* @param buffer - Buffer containing the data
|
|
60
|
+
* @param bufferSize - Internal buffer size for IOContext
|
|
61
|
+
*
|
|
62
|
+
* @returns Configured IOContext instance
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
static createFromBuffer(buffer, bufferSize) {
|
|
67
|
+
let position = 0;
|
|
68
|
+
const ioContext = new IOContext();
|
|
69
|
+
ioContext.allocContextWithCallbacks(bufferSize, 0, (size) => {
|
|
70
|
+
if (position >= buffer.length) {
|
|
71
|
+
return null; // EOF
|
|
72
|
+
}
|
|
73
|
+
const chunk = buffer.subarray(position, Math.min(position + size, buffer.length));
|
|
74
|
+
position += chunk.length;
|
|
75
|
+
return chunk;
|
|
76
|
+
}, undefined, (offset, whence) => {
|
|
77
|
+
switch (whence) {
|
|
78
|
+
case AVSEEK_SIZE:
|
|
79
|
+
return BigInt(buffer.length);
|
|
80
|
+
case AVSEEK_SET:
|
|
81
|
+
position = Number(offset);
|
|
82
|
+
break;
|
|
83
|
+
case AVSEEK_CUR:
|
|
84
|
+
position += Number(offset);
|
|
85
|
+
break;
|
|
86
|
+
case AVSEEK_END:
|
|
87
|
+
position = buffer.length + Number(offset);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
// Clamp position
|
|
91
|
+
position = Math.max(0, Math.min(position, buffer.length));
|
|
92
|
+
return BigInt(position);
|
|
93
|
+
});
|
|
94
|
+
return ioContext;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create IOContext from user-provided callbacks.
|
|
98
|
+
*
|
|
99
|
+
* Validates and wraps the provided callbacks for use with FFmpeg.
|
|
100
|
+
* Only supports read mode as high-level API doesn't expose write operations.
|
|
101
|
+
*
|
|
102
|
+
* @param callbacks - User-provided I/O callbacks
|
|
103
|
+
* @param bufferSize - Internal buffer size for IOContext
|
|
104
|
+
*
|
|
105
|
+
* @returns Configured IOContext instance
|
|
106
|
+
*
|
|
107
|
+
* @throws {Error} If read callback is not provided
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
static createFromCallbacks(callbacks, bufferSize) {
|
|
112
|
+
// We only support read mode in the high-level API
|
|
113
|
+
// Write mode would be needed for custom output, which we don't currently support
|
|
114
|
+
if (!callbacks.read) {
|
|
115
|
+
throw new Error('Read callback is required');
|
|
116
|
+
}
|
|
117
|
+
const ioContext = new IOContext();
|
|
118
|
+
ioContext.allocContextWithCallbacks(bufferSize, 0, // Always read mode
|
|
119
|
+
callbacks.read, undefined, // No write callback in high-level API
|
|
120
|
+
callbacks.seek);
|
|
121
|
+
return ioContext;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=io-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io-stream.js","sourceRoot":"","sources":["../../src/api/io-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI7F;;;;;;;;;;;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-level interface for opening and reading media from various sources.
|
|
5
|
+
* Supports files, URLs, and Buffers with automatic format detection.
|
|
6
|
+
*
|
|
7
|
+
* Central entry point for all media input operations.
|
|
8
|
+
* Manages FormatContext lifecycle and provides stream information.
|
|
9
|
+
*
|
|
10
|
+
* @module api/media-input
|
|
11
|
+
*/
|
|
12
|
+
import { FormatContext, Packet } from '../lib/index.js';
|
|
13
|
+
import type { AVMediaType, AVSeekFlag, Stream } from '../lib/index.js';
|
|
14
|
+
import type { MediaInputOptions, RawData } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* MediaInput - High-level media input handler.
|
|
17
|
+
*
|
|
18
|
+
* Opens and provides access to media streams from various sources.
|
|
19
|
+
* Automatically detects format and finds stream information.
|
|
20
|
+
*
|
|
21
|
+
* Manages the FormatContext and provides convenient methods for
|
|
22
|
+
* accessing streams, metadata, and packets.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { MediaInput } from 'node-av/api';
|
|
27
|
+
*
|
|
28
|
+
* // Open from file
|
|
29
|
+
* const media = await MediaInput.open('video.mp4');
|
|
30
|
+
* console.log(`Found ${media.streams.length} streams`);
|
|
31
|
+
* console.log(`Duration: ${media.duration} seconds`);
|
|
32
|
+
*
|
|
33
|
+
* // Open from buffer
|
|
34
|
+
* const buffer = await fs.readFile('video.mp4');
|
|
35
|
+
* const media = await MediaInput.open(buffer);
|
|
36
|
+
*
|
|
37
|
+
* // Iterate packets
|
|
38
|
+
* for await (const packet of media.packets()) {
|
|
39
|
+
* console.log(`Packet from stream ${packet.streamIndex}`);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class MediaInput implements AsyncDisposable {
|
|
44
|
+
private formatContext;
|
|
45
|
+
private _streams;
|
|
46
|
+
private ioContext?;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new MediaInput instance.
|
|
49
|
+
*
|
|
50
|
+
* Private constructor - use MediaInput.open() to create instances.
|
|
51
|
+
*
|
|
52
|
+
* Parses stream information immediately after construction.
|
|
53
|
+
*
|
|
54
|
+
* @param formatContext - Opened FormatContext
|
|
55
|
+
*/
|
|
56
|
+
private constructor();
|
|
57
|
+
/**
|
|
58
|
+
* Probe the format of media without fully opening it.
|
|
59
|
+
*
|
|
60
|
+
* Detects the container format and basic information without
|
|
61
|
+
* parsing all stream information. Useful for quick format validation.
|
|
62
|
+
*
|
|
63
|
+
* @param input - File path or Buffer to probe
|
|
64
|
+
*
|
|
65
|
+
* @returns Format information or null if unrecognized
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Probe a file
|
|
70
|
+
* const info = await MediaInput.probeFormat('video.mp4');
|
|
71
|
+
* if (info) {
|
|
72
|
+
* console.log(`Format: ${info.format}`);
|
|
73
|
+
* console.log(`Confidence: ${info.confidence}%`);
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* // Probe a buffer
|
|
77
|
+
* const buffer = await fs.readFile('video.mp4');
|
|
78
|
+
* const info = await MediaInput.probeFormat(buffer);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
static probeFormat(input: string | Buffer): Promise<{
|
|
82
|
+
format: string;
|
|
83
|
+
longName?: string;
|
|
84
|
+
extensions?: string;
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
confidence: number;
|
|
87
|
+
} | null>;
|
|
88
|
+
/**
|
|
89
|
+
* Open a media input from various sources.
|
|
90
|
+
*
|
|
91
|
+
* Creates a FormatContext and opens the input for reading.
|
|
92
|
+
* Automatically detects format and finds stream information.
|
|
93
|
+
*
|
|
94
|
+
* Uses av_format_open_input() and av_find_stream_info() internally.
|
|
95
|
+
*
|
|
96
|
+
* @param input - File path, URL, or Buffer
|
|
97
|
+
* @param options - Optional configuration for timestamp handling
|
|
98
|
+
*
|
|
99
|
+
* @returns Promise resolving to MediaInput instance
|
|
100
|
+
*
|
|
101
|
+
* @throws {Error} If input cannot be opened or stream info not found
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // From file
|
|
106
|
+
* const media = await MediaInput.open('video.mp4');
|
|
107
|
+
*
|
|
108
|
+
* // From URL
|
|
109
|
+
* const media = await MediaInput.open('https://example.com/video.mp4');
|
|
110
|
+
*
|
|
111
|
+
* // From Buffer
|
|
112
|
+
* const buffer = await fs.readFile('video.mp4');
|
|
113
|
+
* const media = await MediaInput.open(buffer);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
static open(input: string | Buffer, options?: MediaInputOptions): Promise<MediaInput>;
|
|
117
|
+
/**
|
|
118
|
+
* Open raw video or audio data.
|
|
119
|
+
*
|
|
120
|
+
* @param rawData - Raw video or audio configuration
|
|
121
|
+
*
|
|
122
|
+
* @returns Promise resolving to MediaInput instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Raw video
|
|
127
|
+
* const input = await MediaInput.open({
|
|
128
|
+
* type: 'video',
|
|
129
|
+
* data: 'input.yuv',
|
|
130
|
+
* width: 1280,
|
|
131
|
+
* height: 720,
|
|
132
|
+
* pixelFormat: 'yuv420p',
|
|
133
|
+
* frameRate: 30
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Raw audio
|
|
137
|
+
* const input = await MediaInput.open({
|
|
138
|
+
* type: 'audio',
|
|
139
|
+
* data: 'input.pcm',
|
|
140
|
+
* sampleRate: 48000,
|
|
141
|
+
* channels: 2,
|
|
142
|
+
* sampleFormat: 's16le'
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
static open(rawData: RawData, options?: MediaInputOptions): Promise<MediaInput>;
|
|
147
|
+
/**
|
|
148
|
+
* Get all streams in the container.
|
|
149
|
+
*
|
|
150
|
+
* @returns Array of stream information
|
|
151
|
+
*/
|
|
152
|
+
get streams(): Stream[];
|
|
153
|
+
/**
|
|
154
|
+
* Get media duration in seconds.
|
|
155
|
+
*
|
|
156
|
+
* Returns 0 if duration is not available.
|
|
157
|
+
*
|
|
158
|
+
* @returns Duration in seconds
|
|
159
|
+
*/
|
|
160
|
+
get duration(): number;
|
|
161
|
+
/**
|
|
162
|
+
* Get container metadata.
|
|
163
|
+
*
|
|
164
|
+
* @returns Metadata key-value pairs
|
|
165
|
+
*/
|
|
166
|
+
get metadata(): Record<string, string>;
|
|
167
|
+
/**
|
|
168
|
+
* Get container format name.
|
|
169
|
+
*
|
|
170
|
+
* @returns Format name (e.g., 'mov,mp4,m4a,3gp,3g2,mj2')
|
|
171
|
+
*/
|
|
172
|
+
get formatName(): string;
|
|
173
|
+
/**
|
|
174
|
+
* Get container format long name.
|
|
175
|
+
*
|
|
176
|
+
* @returns Format long name (e.g., 'QuickTime / MOV')
|
|
177
|
+
*/
|
|
178
|
+
get formatLongName(): string;
|
|
179
|
+
/**
|
|
180
|
+
* Get the first video stream.
|
|
181
|
+
*
|
|
182
|
+
* @param index - Video stream index (0 for first, 1 for second, etc.)
|
|
183
|
+
*
|
|
184
|
+
* @returns Stream info or undefined if not found
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const videoStream = media.video();
|
|
189
|
+
* if (videoStream) {
|
|
190
|
+
* console.log(`Video: ${videoStream.width}x${videoStream.height}`);
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
video(index?: number): Stream | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Get the first audio stream.
|
|
197
|
+
*
|
|
198
|
+
* @param index - Audio stream index (0 for first, 1 for second, etc.)
|
|
199
|
+
*
|
|
200
|
+
* @returns Stream info or undefined if not found
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const audioStream = media.audio();
|
|
205
|
+
* if (audioStream) {
|
|
206
|
+
* console.log(`Audio: ${audioStream.sampleRate}Hz, ${audioStream.channels}ch`);
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
audio(index?: number): Stream | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Find the best stream of a given type.
|
|
213
|
+
*
|
|
214
|
+
* Uses FFmpeg's stream selection logic to find the most suitable stream.
|
|
215
|
+
*
|
|
216
|
+
* Uses av_find_best_stream() internally for optimal stream selection.
|
|
217
|
+
*
|
|
218
|
+
* @param type - Media type to search for
|
|
219
|
+
*
|
|
220
|
+
* @returns Stream info or undefined if not found
|
|
221
|
+
*/
|
|
222
|
+
findBestStream(type: AVMediaType): Stream | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Iterate over all packets in the container.
|
|
225
|
+
*
|
|
226
|
+
* Allocates a single packet and reuses it for efficiency.
|
|
227
|
+
* Automatically unreferences the packet between iterations.
|
|
228
|
+
*
|
|
229
|
+
* Uses av_read_frame() internally.
|
|
230
|
+
*
|
|
231
|
+
* @yields Packet from the container
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* for await (const packet of media.packets()) {
|
|
236
|
+
* if (packet.streamIndex === videoStream.index) {
|
|
237
|
+
* // Process video packet
|
|
238
|
+
* await decoder.decode(packet);
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
packets(index?: number): AsyncGenerator<Packet>;
|
|
244
|
+
/**
|
|
245
|
+
* Seek to a specific timestamp.
|
|
246
|
+
*
|
|
247
|
+
* Uses av_seek_frame() internally.
|
|
248
|
+
*
|
|
249
|
+
* Converts seconds to microseconds for FFmpeg's AV_TIME_BASE.
|
|
250
|
+
*
|
|
251
|
+
* @param timestamp - Target timestamp in seconds
|
|
252
|
+
* @param streamIndex - Stream to seek in (-1 for default)
|
|
253
|
+
* @param flags - Seek flags (0 for default)
|
|
254
|
+
*
|
|
255
|
+
* @returns 0 on success, negative error code on failure
|
|
256
|
+
*/
|
|
257
|
+
seek(timestamp: number, streamIndex?: number, flags?: AVSeekFlag): Promise<number>;
|
|
258
|
+
/**
|
|
259
|
+
* Close the input and free resources.
|
|
260
|
+
*
|
|
261
|
+
* Uses avformat_close_input() internally.
|
|
262
|
+
*
|
|
263
|
+
* Properly cleans up IOContext references before closing to prevent
|
|
264
|
+
* use-after-free errors.
|
|
265
|
+
*/
|
|
266
|
+
close(): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Get the low-level FormatContext.
|
|
269
|
+
*
|
|
270
|
+
* Internal method for advanced use cases.
|
|
271
|
+
*
|
|
272
|
+
* Provides direct access to the underlying AVFormatContext.
|
|
273
|
+
*
|
|
274
|
+
* @returns FFmpeg FormatContext
|
|
275
|
+
*
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
getFormatContext(): FormatContext;
|
|
279
|
+
/**
|
|
280
|
+
* Async cleanup when using 'await using' statement.
|
|
281
|
+
*
|
|
282
|
+
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
283
|
+
*
|
|
284
|
+
* Calls close() to free all resources.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* {
|
|
289
|
+
* await using media = await MediaInput.open('video.mp4');
|
|
290
|
+
* // Use media...
|
|
291
|
+
* } // Automatically closed
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
295
|
+
}
|