node-av 1.1.0 → 1.2.0
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/README.md +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
|
@@ -3,183 +3,170 @@ import type { CodecContext } from './codec-context.js';
|
|
|
3
3
|
import type { NativeCodecParser, NativeWrapper } from './native-types.js';
|
|
4
4
|
import type { Packet } from './packet.js';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Parser for extracting codec frames from raw bitstream data.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and
|
|
11
|
-
*
|
|
12
|
-
* raw video files without container format.
|
|
8
|
+
* Analyzes and splits raw bitstream data into individual codec frames.
|
|
9
|
+
* Essential for processing elementary streams, extracting NAL units,
|
|
10
|
+
* and handling frame boundaries in raw codec data. Commonly used for
|
|
11
|
+
* parsing H.264/H.265 streams, AAC ADTS streams, and other raw formats.
|
|
13
12
|
*
|
|
14
|
-
* Direct
|
|
13
|
+
* Direct mapping to FFmpeg's AVCodecParserContext.
|
|
15
14
|
*
|
|
16
15
|
* @example
|
|
17
16
|
* ```typescript
|
|
18
17
|
* import { CodecParser, CodecContext, Packet, FFmpegError } from 'node-av';
|
|
19
|
-
* import { AV_CODEC_ID_H264
|
|
18
|
+
* import { AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
20
19
|
*
|
|
20
|
+
* // Create and initialize parser
|
|
21
21
|
* const parser = new CodecParser();
|
|
22
22
|
* parser.init(AV_CODEC_ID_H264);
|
|
23
23
|
*
|
|
24
|
-
* // Parse raw
|
|
24
|
+
* // Parse raw data into packets
|
|
25
25
|
* const packet = new Packet();
|
|
26
26
|
* packet.alloc();
|
|
27
27
|
*
|
|
28
|
-
* const
|
|
28
|
+
* const rawData = Buffer.from([...]); // Raw H.264 stream
|
|
29
|
+
* const ret = parser.parse2(
|
|
29
30
|
* codecContext,
|
|
30
31
|
* packet,
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* 0
|
|
32
|
+
* rawData,
|
|
33
|
+
* 0n, // pts
|
|
34
|
+
* 0n, // dts
|
|
35
|
+
* 0 // position
|
|
35
36
|
* );
|
|
36
37
|
*
|
|
37
|
-
* if (
|
|
38
|
-
* //
|
|
39
|
-
*
|
|
40
|
-
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
38
|
+
* if (ret > 0) {
|
|
39
|
+
* // Got complete packet, ret is consumed bytes
|
|
40
|
+
* console.log(`Parsed ${ret} bytes into packet`);
|
|
41
41
|
* }
|
|
42
42
|
*
|
|
43
|
+
* // Cleanup
|
|
43
44
|
* parser.close();
|
|
44
45
|
* ```
|
|
45
46
|
*
|
|
47
|
+
* @see [AVCodecParserContext](https://ffmpeg.org/doxygen/trunk/structAVCodecParserContext.html) - FFmpeg Doxygen
|
|
46
48
|
* @see {@link CodecContext} For decoding parsed packets
|
|
47
|
-
* @see {@link Packet} For storing parsed frame data
|
|
48
49
|
*/
|
|
49
|
-
export declare class CodecParser implements NativeWrapper<NativeCodecParser> {
|
|
50
|
+
export declare class CodecParser implements Disposable, NativeWrapper<NativeCodecParser> {
|
|
50
51
|
private native;
|
|
51
|
-
/**
|
|
52
|
-
* Create a new CodecParser instance.
|
|
53
|
-
*
|
|
54
|
-
* The parser is uninitialized - you must call init() before use.
|
|
55
|
-
* No FFmpeg resources are allocated until init() is called.
|
|
56
|
-
*
|
|
57
|
-
* Direct wrapper around AVCodecParserContext allocation.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* import { CodecParser } from 'node-av';
|
|
62
|
-
* import { AV_CODEC_ID_MPEG1VIDEO } from 'node-av/constants';
|
|
63
|
-
*
|
|
64
|
-
* const parser = new CodecParser();
|
|
65
|
-
* parser.init(AV_CODEC_ID_MPEG1VIDEO);
|
|
66
|
-
* // parser is now ready for use
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
52
|
constructor();
|
|
70
53
|
/**
|
|
71
|
-
* Initialize
|
|
54
|
+
* Initialize parser for specific codec.
|
|
72
55
|
*
|
|
73
|
-
*
|
|
74
|
-
* Must be called before
|
|
56
|
+
* Sets up the parser to handle a specific codec format.
|
|
57
|
+
* Must be called before parsing data.
|
|
75
58
|
*
|
|
76
|
-
* Direct mapping to av_parser_init()
|
|
59
|
+
* Direct mapping to av_parser_init().
|
|
77
60
|
*
|
|
78
|
-
* @param codecId -
|
|
61
|
+
* @param codecId - Codec ID to parse
|
|
79
62
|
*
|
|
80
|
-
* @throws {Error}
|
|
63
|
+
* @throws {Error} If codec parser not available
|
|
81
64
|
*
|
|
82
65
|
* @example
|
|
83
66
|
* ```typescript
|
|
84
|
-
* import {
|
|
85
|
-
* import { AV_CODEC_ID_H264, AV_CODEC_ID_HEVC } from 'node-av/constants';
|
|
67
|
+
* import { AV_CODEC_ID_AAC } from 'node-av/constants';
|
|
86
68
|
*
|
|
87
69
|
* const parser = new CodecParser();
|
|
88
|
-
*
|
|
89
|
-
* //
|
|
90
|
-
* parser.init(AV_CODEC_ID_H264);
|
|
91
|
-
* // Parser is now ready to parse H.264 streams
|
|
92
|
-
*
|
|
93
|
-
* // For HEVC/H.265
|
|
94
|
-
* const hevcParser = new CodecParser();
|
|
95
|
-
* hevcParser.init(AV_CODEC_ID_HEVC);
|
|
70
|
+
* parser.init(AV_CODEC_ID_AAC);
|
|
71
|
+
* // Parser ready for AAC ADTS streams
|
|
96
72
|
* ```
|
|
97
73
|
*
|
|
98
|
-
* @see {@link parse2}
|
|
74
|
+
* @see {@link parse2} To parse data
|
|
75
|
+
* @see {@link close} To cleanup
|
|
99
76
|
*/
|
|
100
77
|
init(codecId: AVCodecID): void;
|
|
101
78
|
/**
|
|
102
|
-
* Parse
|
|
79
|
+
* Parse bitstream data into packets.
|
|
103
80
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* into multiple packets, depending on the codec and stream format.
|
|
81
|
+
* Analyzes raw bitstream data and extracts complete codec frames.
|
|
82
|
+
* May require multiple calls to accumulate enough data for a complete frame.
|
|
83
|
+
* Returns the number of bytes consumed from the input buffer.
|
|
108
84
|
*
|
|
109
|
-
* Direct mapping to av_parser_parse2()
|
|
85
|
+
* Direct mapping to av_parser_parse2().
|
|
110
86
|
*
|
|
111
|
-
* @param codecContext - Codec context
|
|
112
|
-
* @param packet - Packet to
|
|
113
|
-
* @param data -
|
|
114
|
-
* @param pts - Presentation timestamp
|
|
115
|
-
* @param dts - Decoding timestamp
|
|
116
|
-
* @param pos - Byte position
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* -
|
|
120
|
-
* - 0: More data needed to complete a frame
|
|
87
|
+
* @param codecContext - Codec context for parser state
|
|
88
|
+
* @param packet - Packet to receive parsed frame
|
|
89
|
+
* @param data - Raw bitstream data to parse
|
|
90
|
+
* @param pts - Presentation timestamp for data
|
|
91
|
+
* @param dts - Decoding timestamp for data
|
|
92
|
+
* @param pos - Byte position in stream
|
|
93
|
+
* @returns Number of bytes consumed from data, negative on error:
|
|
94
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
95
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
121
96
|
*
|
|
122
97
|
* @example
|
|
123
98
|
* ```typescript
|
|
124
|
-
* import {
|
|
125
|
-
* import { AV_NOPTS_VALUE } from 'node-av/constants';
|
|
126
|
-
* import * as fs from 'fs';
|
|
127
|
-
*
|
|
128
|
-
* const inbuf = Buffer.alloc(4096);
|
|
129
|
-
* const bytesRead = fs.readSync(fd, inbuf, 0, 4096, null);
|
|
99
|
+
* import { FFmpegError } from 'node-av';
|
|
130
100
|
*
|
|
131
101
|
* let offset = 0;
|
|
132
|
-
* while (offset <
|
|
133
|
-
* const
|
|
102
|
+
* while (offset < rawData.length) {
|
|
103
|
+
* const remaining = rawData.subarray(offset);
|
|
104
|
+
* const ret = parser.parse2(
|
|
134
105
|
* codecContext,
|
|
135
106
|
* packet,
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
107
|
+
* remaining,
|
|
108
|
+
* pts,
|
|
109
|
+
* dts,
|
|
110
|
+
* offset
|
|
140
111
|
* );
|
|
141
112
|
*
|
|
142
|
-
*
|
|
113
|
+
* if (ret < 0) {
|
|
114
|
+
* FFmpegError.throwIfError(ret, 'parse2');
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* offset += ret;
|
|
143
118
|
*
|
|
144
119
|
* if (packet.size > 0) {
|
|
145
|
-
* //
|
|
146
|
-
*
|
|
147
|
-
*
|
|
120
|
+
* // Got complete packet
|
|
121
|
+
* await processPacket(packet);
|
|
122
|
+
* packet.unref();
|
|
148
123
|
* }
|
|
149
124
|
* }
|
|
150
125
|
* ```
|
|
151
126
|
*
|
|
152
|
-
* @see {@link init}
|
|
153
|
-
* @see {@link close} Should be called when done parsing
|
|
127
|
+
* @see {@link init} To initialize parser
|
|
154
128
|
*/
|
|
155
129
|
parse2(codecContext: CodecContext, packet: Packet, data: Buffer, pts: bigint, dts: bigint, pos: number): number;
|
|
156
130
|
/**
|
|
157
|
-
* Close the parser
|
|
131
|
+
* Close the codec parser.
|
|
158
132
|
*
|
|
159
|
-
* Releases all resources associated with the parser
|
|
160
|
-
*
|
|
133
|
+
* Releases all resources associated with the parser.
|
|
134
|
+
* The parser becomes invalid after calling this.
|
|
161
135
|
*
|
|
162
|
-
* Direct mapping to av_parser_close()
|
|
136
|
+
* Direct mapping to av_parser_close().
|
|
163
137
|
*
|
|
164
138
|
* @example
|
|
165
139
|
* ```typescript
|
|
166
|
-
* import { CodecParser } from 'node-av';
|
|
167
|
-
*
|
|
168
|
-
* const parser = new CodecParser();
|
|
169
|
-
* // ... use parser ...
|
|
170
|
-
*
|
|
171
140
|
* parser.close();
|
|
172
|
-
* // Parser
|
|
173
|
-
* // Do not use parser after this point
|
|
141
|
+
* // Parser is now invalid
|
|
174
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link init} To initialize
|
|
145
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
175
146
|
*/
|
|
176
147
|
close(): void;
|
|
177
148
|
/**
|
|
178
|
-
*
|
|
179
|
-
* Get the underlying native codec parser object.
|
|
180
|
-
* This method is for internal use by other FFmpeg classes.
|
|
149
|
+
* Get the underlying native CodecParser object.
|
|
181
150
|
*
|
|
182
|
-
* @returns The
|
|
151
|
+
* @returns The native CodecParser binding object
|
|
152
|
+
*
|
|
153
|
+
* @internal
|
|
183
154
|
*/
|
|
184
155
|
getNative(): NativeCodecParser;
|
|
156
|
+
/**
|
|
157
|
+
* Dispose of the codec parser.
|
|
158
|
+
*
|
|
159
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
160
|
+
* Equivalent to calling close().
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* {
|
|
165
|
+
* using parser = new CodecParser();
|
|
166
|
+
* parser.init(AV_CODEC_ID_H264);
|
|
167
|
+
* // Use parser...
|
|
168
|
+
* } // Automatically closed when leaving scope
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
[Symbol.dispose](): void;
|
|
185
172
|
}
|
package/dist/lib/codec-parser.js
CHANGED
|
@@ -1,193 +1,182 @@
|
|
|
1
1
|
import { bindings } from './binding.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parser for extracting codec frames from raw bitstream data.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* and
|
|
8
|
-
*
|
|
9
|
-
* raw video files without container format.
|
|
5
|
+
* Analyzes and splits raw bitstream data into individual codec frames.
|
|
6
|
+
* Essential for processing elementary streams, extracting NAL units,
|
|
7
|
+
* and handling frame boundaries in raw codec data. Commonly used for
|
|
8
|
+
* parsing H.264/H.265 streams, AAC ADTS streams, and other raw formats.
|
|
10
9
|
*
|
|
11
|
-
* Direct
|
|
10
|
+
* Direct mapping to FFmpeg's AVCodecParserContext.
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
13
|
* ```typescript
|
|
15
14
|
* import { CodecParser, CodecContext, Packet, FFmpegError } from 'node-av';
|
|
16
|
-
* import { AV_CODEC_ID_H264
|
|
15
|
+
* import { AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
17
16
|
*
|
|
17
|
+
* // Create and initialize parser
|
|
18
18
|
* const parser = new CodecParser();
|
|
19
19
|
* parser.init(AV_CODEC_ID_H264);
|
|
20
20
|
*
|
|
21
|
-
* // Parse raw
|
|
21
|
+
* // Parse raw data into packets
|
|
22
22
|
* const packet = new Packet();
|
|
23
23
|
* packet.alloc();
|
|
24
24
|
*
|
|
25
|
-
* const
|
|
25
|
+
* const rawData = Buffer.from([...]); // Raw H.264 stream
|
|
26
|
+
* const ret = parser.parse2(
|
|
26
27
|
* codecContext,
|
|
27
28
|
* packet,
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* 0
|
|
29
|
+
* rawData,
|
|
30
|
+
* 0n, // pts
|
|
31
|
+
* 0n, // dts
|
|
32
|
+
* 0 // position
|
|
32
33
|
* );
|
|
33
34
|
*
|
|
34
|
-
* if (
|
|
35
|
-
* //
|
|
36
|
-
*
|
|
37
|
-
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
35
|
+
* if (ret > 0) {
|
|
36
|
+
* // Got complete packet, ret is consumed bytes
|
|
37
|
+
* console.log(`Parsed ${ret} bytes into packet`);
|
|
38
38
|
* }
|
|
39
39
|
*
|
|
40
|
+
* // Cleanup
|
|
40
41
|
* parser.close();
|
|
41
42
|
* ```
|
|
42
43
|
*
|
|
44
|
+
* @see [AVCodecParserContext](https://ffmpeg.org/doxygen/trunk/structAVCodecParserContext.html) - FFmpeg Doxygen
|
|
43
45
|
* @see {@link CodecContext} For decoding parsed packets
|
|
44
|
-
* @see {@link Packet} For storing parsed frame data
|
|
45
46
|
*/
|
|
46
47
|
export class CodecParser {
|
|
47
48
|
native;
|
|
48
|
-
/**
|
|
49
|
-
* Create a new CodecParser instance.
|
|
50
|
-
*
|
|
51
|
-
* The parser is uninitialized - you must call init() before use.
|
|
52
|
-
* No FFmpeg resources are allocated until init() is called.
|
|
53
|
-
*
|
|
54
|
-
* Direct wrapper around AVCodecParserContext allocation.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* import { CodecParser } from 'node-av';
|
|
59
|
-
* import { AV_CODEC_ID_MPEG1VIDEO } from 'node-av/constants';
|
|
60
|
-
*
|
|
61
|
-
* const parser = new CodecParser();
|
|
62
|
-
* parser.init(AV_CODEC_ID_MPEG1VIDEO);
|
|
63
|
-
* // parser is now ready for use
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
49
|
constructor() {
|
|
67
50
|
this.native = new bindings.CodecParser();
|
|
68
51
|
}
|
|
69
52
|
/**
|
|
70
|
-
* Initialize
|
|
53
|
+
* Initialize parser for specific codec.
|
|
71
54
|
*
|
|
72
|
-
*
|
|
73
|
-
* Must be called before
|
|
55
|
+
* Sets up the parser to handle a specific codec format.
|
|
56
|
+
* Must be called before parsing data.
|
|
74
57
|
*
|
|
75
|
-
* Direct mapping to av_parser_init()
|
|
58
|
+
* Direct mapping to av_parser_init().
|
|
76
59
|
*
|
|
77
|
-
* @param codecId -
|
|
60
|
+
* @param codecId - Codec ID to parse
|
|
78
61
|
*
|
|
79
|
-
* @throws {Error}
|
|
62
|
+
* @throws {Error} If codec parser not available
|
|
80
63
|
*
|
|
81
64
|
* @example
|
|
82
65
|
* ```typescript
|
|
83
|
-
* import {
|
|
84
|
-
* import { AV_CODEC_ID_H264, AV_CODEC_ID_HEVC } from 'node-av/constants';
|
|
66
|
+
* import { AV_CODEC_ID_AAC } from 'node-av/constants';
|
|
85
67
|
*
|
|
86
68
|
* const parser = new CodecParser();
|
|
87
|
-
*
|
|
88
|
-
* //
|
|
89
|
-
* parser.init(AV_CODEC_ID_H264);
|
|
90
|
-
* // Parser is now ready to parse H.264 streams
|
|
91
|
-
*
|
|
92
|
-
* // For HEVC/H.265
|
|
93
|
-
* const hevcParser = new CodecParser();
|
|
94
|
-
* hevcParser.init(AV_CODEC_ID_HEVC);
|
|
69
|
+
* parser.init(AV_CODEC_ID_AAC);
|
|
70
|
+
* // Parser ready for AAC ADTS streams
|
|
95
71
|
* ```
|
|
96
72
|
*
|
|
97
|
-
* @see {@link parse2}
|
|
73
|
+
* @see {@link parse2} To parse data
|
|
74
|
+
* @see {@link close} To cleanup
|
|
98
75
|
*/
|
|
99
76
|
init(codecId) {
|
|
100
77
|
this.native.init(codecId);
|
|
101
78
|
}
|
|
102
79
|
/**
|
|
103
|
-
* Parse
|
|
80
|
+
* Parse bitstream data into packets.
|
|
104
81
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* into multiple packets, depending on the codec and stream format.
|
|
82
|
+
* Analyzes raw bitstream data and extracts complete codec frames.
|
|
83
|
+
* May require multiple calls to accumulate enough data for a complete frame.
|
|
84
|
+
* Returns the number of bytes consumed from the input buffer.
|
|
109
85
|
*
|
|
110
|
-
* Direct mapping to av_parser_parse2()
|
|
86
|
+
* Direct mapping to av_parser_parse2().
|
|
111
87
|
*
|
|
112
|
-
* @param codecContext - Codec context
|
|
113
|
-
* @param packet - Packet to
|
|
114
|
-
* @param data -
|
|
115
|
-
* @param pts - Presentation timestamp
|
|
116
|
-
* @param dts - Decoding timestamp
|
|
117
|
-
* @param pos - Byte position
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* -
|
|
121
|
-
* - 0: More data needed to complete a frame
|
|
88
|
+
* @param codecContext - Codec context for parser state
|
|
89
|
+
* @param packet - Packet to receive parsed frame
|
|
90
|
+
* @param data - Raw bitstream data to parse
|
|
91
|
+
* @param pts - Presentation timestamp for data
|
|
92
|
+
* @param dts - Decoding timestamp for data
|
|
93
|
+
* @param pos - Byte position in stream
|
|
94
|
+
* @returns Number of bytes consumed from data, negative on error:
|
|
95
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
96
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
122
97
|
*
|
|
123
98
|
* @example
|
|
124
99
|
* ```typescript
|
|
125
|
-
* import {
|
|
126
|
-
* import { AV_NOPTS_VALUE } from 'node-av/constants';
|
|
127
|
-
* import * as fs from 'fs';
|
|
128
|
-
*
|
|
129
|
-
* const inbuf = Buffer.alloc(4096);
|
|
130
|
-
* const bytesRead = fs.readSync(fd, inbuf, 0, 4096, null);
|
|
100
|
+
* import { FFmpegError } from 'node-av';
|
|
131
101
|
*
|
|
132
102
|
* let offset = 0;
|
|
133
|
-
* while (offset <
|
|
134
|
-
* const
|
|
103
|
+
* while (offset < rawData.length) {
|
|
104
|
+
* const remaining = rawData.subarray(offset);
|
|
105
|
+
* const ret = parser.parse2(
|
|
135
106
|
* codecContext,
|
|
136
107
|
* packet,
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
108
|
+
* remaining,
|
|
109
|
+
* pts,
|
|
110
|
+
* dts,
|
|
111
|
+
* offset
|
|
141
112
|
* );
|
|
142
113
|
*
|
|
143
|
-
*
|
|
114
|
+
* if (ret < 0) {
|
|
115
|
+
* FFmpegError.throwIfError(ret, 'parse2');
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* offset += ret;
|
|
144
119
|
*
|
|
145
120
|
* if (packet.size > 0) {
|
|
146
|
-
* //
|
|
147
|
-
*
|
|
148
|
-
*
|
|
121
|
+
* // Got complete packet
|
|
122
|
+
* await processPacket(packet);
|
|
123
|
+
* packet.unref();
|
|
149
124
|
* }
|
|
150
125
|
* }
|
|
151
126
|
* ```
|
|
152
127
|
*
|
|
153
|
-
* @see {@link init}
|
|
154
|
-
* @see {@link close} Should be called when done parsing
|
|
128
|
+
* @see {@link init} To initialize parser
|
|
155
129
|
*/
|
|
156
130
|
parse2(codecContext, packet, data, pts, dts, pos) {
|
|
157
131
|
return this.native.parse2(codecContext.getNative(), packet.getNative(), data, pts, dts, pos);
|
|
158
132
|
}
|
|
159
133
|
/**
|
|
160
|
-
* Close the parser
|
|
134
|
+
* Close the codec parser.
|
|
161
135
|
*
|
|
162
|
-
* Releases all resources associated with the parser
|
|
163
|
-
*
|
|
136
|
+
* Releases all resources associated with the parser.
|
|
137
|
+
* The parser becomes invalid after calling this.
|
|
164
138
|
*
|
|
165
|
-
* Direct mapping to av_parser_close()
|
|
139
|
+
* Direct mapping to av_parser_close().
|
|
166
140
|
*
|
|
167
141
|
* @example
|
|
168
142
|
* ```typescript
|
|
169
|
-
* import { CodecParser } from 'node-av';
|
|
170
|
-
*
|
|
171
|
-
* const parser = new CodecParser();
|
|
172
|
-
* // ... use parser ...
|
|
173
|
-
*
|
|
174
143
|
* parser.close();
|
|
175
|
-
* // Parser
|
|
176
|
-
* // Do not use parser after this point
|
|
144
|
+
* // Parser is now invalid
|
|
177
145
|
* ```
|
|
146
|
+
*
|
|
147
|
+
* @see {@link init} To initialize
|
|
148
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
178
149
|
*/
|
|
179
150
|
close() {
|
|
180
151
|
this.native.close();
|
|
181
152
|
}
|
|
182
153
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
154
|
+
* Get the underlying native CodecParser object.
|
|
155
|
+
*
|
|
156
|
+
* @returns The native CodecParser binding object
|
|
186
157
|
*
|
|
187
|
-
* @
|
|
158
|
+
* @internal
|
|
188
159
|
*/
|
|
189
160
|
getNative() {
|
|
190
161
|
return this.native;
|
|
191
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Dispose of the codec parser.
|
|
165
|
+
*
|
|
166
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
167
|
+
* Equivalent to calling close().
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* {
|
|
172
|
+
* using parser = new CodecParser();
|
|
173
|
+
* parser.init(AV_CODEC_ID_H264);
|
|
174
|
+
* // Use parser...
|
|
175
|
+
* } // Automatically closed when leaving scope
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
[Symbol.dispose]() {
|
|
179
|
+
this.close();
|
|
180
|
+
}
|
|
192
181
|
}
|
|
193
182
|
//# sourceMappingURL=codec-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec-parser.js","sourceRoot":"","sources":["../../src/lib/codec-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAOxC
|
|
1
|
+
{"version":3,"file":"codec-parser.js","sourceRoot":"","sources":["../../src/lib/codec-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAOxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAoB;IAElC;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,CAAC,OAAkB;QACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACH,MAAM,CAAC,YAA0B,EAAE,MAAc,EAAE,IAAY,EAAE,GAAW,EAAE,GAAW,EAAE,GAAW;QACpG,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/F,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
|