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
package/dist/lib/packet.d.ts
CHANGED
|
@@ -2,458 +2,402 @@ import type { AVPacketFlag, AVPacketSideDataType } from '../constants/constants.
|
|
|
2
2
|
import type { NativePacket, NativeWrapper } from './native-types.js';
|
|
3
3
|
import type { IRational } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Container for compressed audio/video data.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Stores encoded data from demuxers or to be sent to muxers. Each packet contains
|
|
8
|
+
* a portion of compressed stream data, typically one video frame or several audio frames.
|
|
9
|
+
* Includes timing information (PTS/DTS), stream index, and flags. Essential for
|
|
10
|
+
* demuxing, muxing, and codec operations.
|
|
10
11
|
*
|
|
11
12
|
* Direct mapping to FFmpeg's AVPacket.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
|
-
* import { Packet,
|
|
16
|
+
* import { Packet, FFmpegError } from 'node-av';
|
|
17
|
+
* import { AV_PKT_FLAG_KEY } from 'node-av/constants';
|
|
16
18
|
*
|
|
17
|
-
* // Create and allocate packet
|
|
19
|
+
* // Create and allocate packet
|
|
18
20
|
* const packet = new Packet();
|
|
19
21
|
* packet.alloc();
|
|
20
22
|
*
|
|
21
|
-
* // Read from
|
|
23
|
+
* // Read packet from format context
|
|
22
24
|
* const ret = await formatContext.readFrame(packet);
|
|
23
25
|
* FFmpegError.throwIfError(ret, 'readFrame');
|
|
24
26
|
*
|
|
25
|
-
* //
|
|
26
|
-
* console.log(`Stream: ${packet.streamIndex}
|
|
27
|
+
* // Check packet properties
|
|
28
|
+
* console.log(`Stream: ${packet.streamIndex}`);
|
|
29
|
+
* console.log(`PTS: ${packet.pts}`);
|
|
30
|
+
* console.log(`Size: ${packet.size} bytes`);
|
|
31
|
+
* console.log(`Keyframe: ${packet.isKeyframe}`);
|
|
27
32
|
*
|
|
28
33
|
* // Send to decoder
|
|
29
|
-
* const
|
|
30
|
-
* FFmpegError.throwIfError(
|
|
34
|
+
* const ret2 = await codecContext.sendPacket(packet);
|
|
35
|
+
* FFmpegError.throwIfError(ret2, 'sendPacket');
|
|
31
36
|
*
|
|
32
37
|
* // Cleanup
|
|
33
|
-
* packet.unref();
|
|
34
|
-
* packet.free(); // Free packet completely
|
|
38
|
+
* packet.unref();
|
|
35
39
|
* ```
|
|
36
40
|
*
|
|
37
|
-
* @see
|
|
41
|
+
* @see [AVPacket](https://ffmpeg.org/doxygen/trunk/structAVPacket.html) - FFmpeg Doxygen
|
|
38
42
|
* @see {@link FormatContext} For reading/writing packets
|
|
43
|
+
* @see {@link CodecContext} For encoding/decoding packets
|
|
39
44
|
*/
|
|
40
45
|
export declare class Packet implements Disposable, NativeWrapper<NativePacket> {
|
|
41
46
|
private native;
|
|
42
|
-
/**
|
|
43
|
-
* Create a new packet instance.
|
|
44
|
-
*
|
|
45
|
-
* The packet is uninitialized - you must call alloc() before use.
|
|
46
|
-
* No FFmpeg resources are allocated until alloc() is called.
|
|
47
|
-
*
|
|
48
|
-
* Direct wrapper around AVPacket allocation.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { Packet } from 'node-av';
|
|
53
|
-
*
|
|
54
|
-
* const packet = new Packet();
|
|
55
|
-
* packet.alloc();
|
|
56
|
-
* // Packet is now ready for use
|
|
57
|
-
*
|
|
58
|
-
* // Always free when done
|
|
59
|
-
* packet.free();
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
47
|
constructor();
|
|
63
48
|
/**
|
|
64
49
|
* Stream index this packet belongs to.
|
|
65
50
|
*
|
|
66
|
-
*
|
|
51
|
+
* Identifies which stream in a format context this packet is from/for.
|
|
52
|
+
* Set automatically when reading, must be set manually when writing.
|
|
67
53
|
*
|
|
68
|
-
*
|
|
69
|
-
* Must be set by user for muxing.
|
|
54
|
+
* Direct mapping to AVPacket->stream_index.
|
|
70
55
|
*/
|
|
71
56
|
get streamIndex(): number;
|
|
72
57
|
set streamIndex(value: number);
|
|
73
58
|
/**
|
|
74
|
-
* Presentation timestamp
|
|
59
|
+
* Presentation timestamp.
|
|
75
60
|
*
|
|
76
|
-
*
|
|
61
|
+
* Time when the decompressed packet should be presented to the user.
|
|
62
|
+
* In stream time base units. AV_NOPTS_VALUE if unknown.
|
|
77
63
|
*
|
|
78
|
-
*
|
|
79
|
-
* Can be AV_NOPTS_VALUE if it is not stored in the file.
|
|
80
|
-
* pts MUST be larger or equal to dts as presentation cannot happen before
|
|
81
|
-
* decompression, unless one wants to view hex dumps. Some formats misuse
|
|
82
|
-
* the terms dts and pts/cts to mean something different. Such timestamps
|
|
83
|
-
* must be converted to true pts/dts before they are stored in AVPacket.
|
|
64
|
+
* Direct mapping to AVPacket->pts.
|
|
84
65
|
*/
|
|
85
66
|
get pts(): bigint;
|
|
86
67
|
set pts(value: bigint);
|
|
87
68
|
/**
|
|
88
|
-
* Decompression timestamp
|
|
69
|
+
* Decompression timestamp.
|
|
89
70
|
*
|
|
90
|
-
*
|
|
71
|
+
* Time when the packet should be decompressed.
|
|
72
|
+
* In stream time base units. AV_NOPTS_VALUE if unknown.
|
|
91
73
|
*
|
|
92
|
-
*
|
|
93
|
-
* Can be AV_NOPTS_VALUE if it is not stored in the file.
|
|
74
|
+
* Direct mapping to AVPacket->dts.
|
|
94
75
|
*/
|
|
95
76
|
get dts(): bigint;
|
|
96
77
|
set dts(value: bigint);
|
|
97
78
|
/**
|
|
98
|
-
* Duration of this packet
|
|
79
|
+
* Duration of this packet.
|
|
99
80
|
*
|
|
100
|
-
*
|
|
81
|
+
* Duration in stream time base units, 0 if unknown.
|
|
82
|
+
* Typically equal to next_pts - this_pts.
|
|
101
83
|
*
|
|
102
|
-
*
|
|
84
|
+
* Direct mapping to AVPacket->duration.
|
|
103
85
|
*/
|
|
104
86
|
get duration(): bigint;
|
|
105
87
|
set duration(value: bigint);
|
|
106
88
|
/**
|
|
107
|
-
* Byte position in stream
|
|
89
|
+
* Byte position in stream.
|
|
108
90
|
*
|
|
109
|
-
*
|
|
91
|
+
* Byte position of packet data in the input file.
|
|
92
|
+
* -1 if unknown.
|
|
110
93
|
*
|
|
111
|
-
*
|
|
94
|
+
* Direct mapping to AVPacket->pos.
|
|
112
95
|
*/
|
|
113
96
|
get pos(): bigint;
|
|
114
97
|
set pos(value: bigint);
|
|
115
98
|
/**
|
|
116
99
|
* Size of packet data in bytes.
|
|
117
100
|
*
|
|
118
|
-
* Direct mapping to AVPacket->size
|
|
119
|
-
*
|
|
120
|
-
* @readonly
|
|
101
|
+
* Direct mapping to AVPacket->size.
|
|
121
102
|
*/
|
|
122
103
|
get size(): number;
|
|
123
104
|
/**
|
|
124
|
-
*
|
|
105
|
+
* Packet flags.
|
|
125
106
|
*
|
|
126
|
-
*
|
|
107
|
+
* Combination of AV_PKT_FLAG values indicating packet properties
|
|
108
|
+
* (e.g., AV_PKT_FLAG_KEY for keyframes).
|
|
127
109
|
*
|
|
128
|
-
*
|
|
129
|
-
* - AV_PKT_FLAG_CORRUPT: The packet content is corrupted
|
|
130
|
-
* - AV_PKT_FLAG_DISCARD: Flag for packets that should be dropped
|
|
131
|
-
* - AV_PKT_FLAG_TRUSTED: The packet comes from a trusted source
|
|
132
|
-
* - AV_PKT_FLAG_DISPOSABLE: Flag for packets that can be dropped if needed
|
|
110
|
+
* Direct mapping to AVPacket->flags.
|
|
133
111
|
*/
|
|
134
112
|
get flags(): AVPacketFlag;
|
|
135
113
|
set flags(value: AVPacketFlag);
|
|
136
114
|
/**
|
|
137
115
|
* Packet data buffer.
|
|
138
116
|
*
|
|
139
|
-
*
|
|
117
|
+
* Contains the compressed audio/video data.
|
|
118
|
+
* May be null for packets signaling special conditions.
|
|
140
119
|
*
|
|
141
|
-
*
|
|
142
|
-
* Setting null will unref the packet data.
|
|
143
|
-
* When setting a new buffer, av_packet_from_data() is called internally.
|
|
120
|
+
* Direct mapping to AVPacket->data.
|
|
144
121
|
*/
|
|
145
122
|
get data(): Buffer | null;
|
|
146
123
|
set data(value: Buffer | null);
|
|
147
124
|
/**
|
|
148
125
|
* Check if packet contains a keyframe.
|
|
149
126
|
*
|
|
150
|
-
*
|
|
127
|
+
* Convenience property that checks AV_PKT_FLAG_KEY flag.
|
|
128
|
+
* Keyframes can be decoded independently without reference frames.
|
|
151
129
|
*/
|
|
152
130
|
get isKeyframe(): boolean;
|
|
153
131
|
set isKeyframe(value: boolean);
|
|
154
132
|
/**
|
|
155
|
-
* Allocate
|
|
133
|
+
* Allocate a new packet.
|
|
156
134
|
*
|
|
157
|
-
* Allocates the
|
|
158
|
-
*
|
|
135
|
+
* Allocates the packet structure. Must be called before using the packet
|
|
136
|
+
* unless it was created by another function (e.g., clone()).
|
|
159
137
|
*
|
|
160
|
-
* Direct mapping to av_packet_alloc()
|
|
138
|
+
* Direct mapping to av_packet_alloc().
|
|
161
139
|
*
|
|
162
|
-
* @throws {Error}
|
|
140
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
163
141
|
*
|
|
164
142
|
* @example
|
|
165
143
|
* ```typescript
|
|
166
|
-
* import { Packet } from 'node-av';
|
|
167
|
-
*
|
|
168
144
|
* const packet = new Packet();
|
|
169
145
|
* packet.alloc();
|
|
170
|
-
* // Packet is now
|
|
171
|
-
* // pts = AV_NOPTS_VALUE, dts = AV_NOPTS_VALUE
|
|
172
|
-
* // size = 0, data = null
|
|
146
|
+
* // Packet is now ready for use
|
|
173
147
|
* ```
|
|
174
148
|
*
|
|
175
|
-
* @see {@link free}
|
|
176
|
-
* @see {@link unref} To clear data but keep allocation
|
|
149
|
+
* @see {@link free} To deallocate the packet
|
|
177
150
|
*/
|
|
178
151
|
alloc(): void;
|
|
179
152
|
/**
|
|
180
153
|
* Free the packet.
|
|
181
154
|
*
|
|
182
|
-
*
|
|
155
|
+
* Deallocates the packet and its data. The packet becomes invalid after this.
|
|
183
156
|
*
|
|
184
|
-
*
|
|
185
|
-
* After calling this, the packet is no longer usable until alloc() is called again.
|
|
186
|
-
*
|
|
187
|
-
* @note
|
|
188
|
-
* Calling this multiple times is safe, because we check the freed state
|
|
157
|
+
* Direct mapping to av_packet_free().
|
|
189
158
|
*
|
|
190
159
|
* @example
|
|
191
160
|
* ```typescript
|
|
192
161
|
* packet.free();
|
|
193
|
-
* //
|
|
162
|
+
* // Packet is now invalid
|
|
194
163
|
* ```
|
|
164
|
+
*
|
|
165
|
+
* @see {@link unref} To only free data, keeping structure
|
|
195
166
|
*/
|
|
196
167
|
free(): void;
|
|
197
168
|
/**
|
|
198
|
-
*
|
|
169
|
+
* Create a reference to another packet.
|
|
199
170
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* All the other fields are copied from src.
|
|
171
|
+
* Sets up this packet as a reference to the source packet's data.
|
|
172
|
+
* Both packets will share the same data buffer.
|
|
203
173
|
*
|
|
204
|
-
* Direct mapping to av_packet_ref()
|
|
174
|
+
* Direct mapping to av_packet_ref().
|
|
205
175
|
*
|
|
206
176
|
* @param src - Source packet to reference
|
|
207
|
-
*
|
|
208
177
|
* @returns 0 on success, negative AVERROR on error:
|
|
209
|
-
* -
|
|
210
|
-
* -
|
|
211
|
-
* - AVERROR(EINVAL): Invalid parameters (null packet)
|
|
178
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
179
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
212
180
|
*
|
|
213
181
|
* @example
|
|
214
182
|
* ```typescript
|
|
215
|
-
* import {
|
|
183
|
+
* import { FFmpegError } from 'node-av';
|
|
216
184
|
*
|
|
217
|
-
* const
|
|
218
|
-
*
|
|
219
|
-
* const
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* const ret = dst.ref(src);
|
|
223
|
-
* FFmpegError.throwIfError(ret, 'packet.ref');
|
|
224
|
-
* // dst now references the same data as src
|
|
185
|
+
* const packet2 = new Packet();
|
|
186
|
+
* packet2.alloc();
|
|
187
|
+
* const ret = packet2.ref(packet1);
|
|
188
|
+
* FFmpegError.throwIfError(ret, 'ref');
|
|
189
|
+
* // packet2 now references packet1's data
|
|
225
190
|
* ```
|
|
226
191
|
*
|
|
227
192
|
* @see {@link unref} To remove reference
|
|
228
|
-
* @see {@link clone}
|
|
193
|
+
* @see {@link clone} To create independent copy
|
|
229
194
|
*/
|
|
230
195
|
ref(src: Packet): number;
|
|
231
196
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* Direct mapping to av_packet_unref()
|
|
197
|
+
* Unreference the packet.
|
|
235
198
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
199
|
+
* Frees the packet data if this was the last reference.
|
|
200
|
+
* The packet structure remains allocated and can be reused.
|
|
238
201
|
*
|
|
239
|
-
*
|
|
202
|
+
* Direct mapping to av_packet_unref().
|
|
240
203
|
*
|
|
241
204
|
* @example
|
|
242
205
|
* ```typescript
|
|
243
206
|
* packet.unref();
|
|
244
|
-
* // Packet data is
|
|
245
|
-
* // Can reuse the packet for another read
|
|
207
|
+
* // Packet data is freed, structure can be reused
|
|
246
208
|
* ```
|
|
247
209
|
*
|
|
248
|
-
* @
|
|
210
|
+
* @see {@link ref} To create reference
|
|
211
|
+
* @see {@link free} To free everything
|
|
249
212
|
*/
|
|
250
213
|
unref(): void;
|
|
251
214
|
/**
|
|
252
|
-
*
|
|
215
|
+
* Clone the packet.
|
|
253
216
|
*
|
|
254
|
-
*
|
|
255
|
-
* The new packet
|
|
217
|
+
* Creates an independent copy of the packet with its own data buffer.
|
|
218
|
+
* The new packet has the same content but can be modified independently.
|
|
256
219
|
*
|
|
257
|
-
* Direct mapping to av_packet_clone()
|
|
220
|
+
* Direct mapping to av_packet_clone().
|
|
258
221
|
*
|
|
259
|
-
* @returns New packet
|
|
222
|
+
* @returns New packet instance, or null on allocation failure
|
|
260
223
|
*
|
|
261
224
|
* @example
|
|
262
225
|
* ```typescript
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* const cloned = original.clone();
|
|
269
|
-
* if (!cloned) {
|
|
270
|
-
* throw new Error('Failed to clone packet: Out of memory');
|
|
226
|
+
* const copy = packet.clone();
|
|
227
|
+
* if (copy) {
|
|
228
|
+
* // Modify copy without affecting original
|
|
229
|
+
* copy.pts = packet.pts + 1000n;
|
|
271
230
|
* }
|
|
272
|
-
* // cloned references the same data as original
|
|
273
|
-
* // Both packets must be freed independently
|
|
274
|
-
* cloned.free();
|
|
275
|
-
* original.free();
|
|
276
231
|
* ```
|
|
277
232
|
*
|
|
278
|
-
* @see {@link ref}
|
|
233
|
+
* @see {@link ref} To create reference instead of copy
|
|
279
234
|
*/
|
|
280
235
|
clone(): Packet | null;
|
|
281
236
|
/**
|
|
282
|
-
*
|
|
237
|
+
* Rescale packet timestamps.
|
|
283
238
|
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* different contexts, for example when remuxing or when the decoder and encoder
|
|
287
|
-
* use different timebases.
|
|
239
|
+
* Converts PTS, DTS, and duration from one time base to another.
|
|
240
|
+
* Essential when moving packets between streams with different time bases.
|
|
288
241
|
*
|
|
289
|
-
* Direct mapping to av_packet_rescale_ts()
|
|
242
|
+
* Direct mapping to av_packet_rescale_ts().
|
|
290
243
|
*
|
|
291
|
-
* @param srcTimebase - Source
|
|
292
|
-
* @param dstTimebase - Destination
|
|
244
|
+
* @param srcTimebase - Source time base
|
|
245
|
+
* @param dstTimebase - Destination time base
|
|
293
246
|
*
|
|
294
247
|
* @example
|
|
295
248
|
* ```typescript
|
|
296
|
-
* import {
|
|
297
|
-
*
|
|
298
|
-
* // Convert from stream timebase to codec timebase
|
|
299
|
-
* const streamTimebase = new Rational(1, 90000); // 90kHz
|
|
300
|
-
* const codecTimebase = new Rational(1, 25); // 25 fps
|
|
249
|
+
* import { Rational } from 'node-av';
|
|
301
250
|
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
* );
|
|
306
|
-
* // PTS and DTS are now in codec timebase
|
|
251
|
+
* // Convert from 1/25 fps to 1/1000 (milliseconds)
|
|
252
|
+
* const src = new Rational(1, 25);
|
|
253
|
+
* const dst = new Rational(1, 1000);
|
|
254
|
+
* packet.rescaleTs(src, dst);
|
|
307
255
|
* ```
|
|
308
|
-
*
|
|
309
|
-
* @see {@link Rational} For timebase representation
|
|
310
256
|
*/
|
|
311
257
|
rescaleTs(srcTimebase: IRational, dstTimebase: IRational): void;
|
|
312
258
|
/**
|
|
313
|
-
* Ensure
|
|
259
|
+
* Ensure packet data is reference counted.
|
|
314
260
|
*
|
|
315
|
-
* Makes the packet data
|
|
316
|
-
*
|
|
261
|
+
* Makes sure the packet data is stored in a reference-counted buffer.
|
|
262
|
+
* If not already reference-counted, allocates a new buffer and copies data.
|
|
317
263
|
*
|
|
318
|
-
* Direct mapping to av_packet_make_refcounted()
|
|
264
|
+
* Direct mapping to av_packet_make_refcounted().
|
|
319
265
|
*
|
|
320
266
|
* @returns 0 on success, negative AVERROR on error:
|
|
321
|
-
* -
|
|
322
|
-
* -
|
|
267
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
268
|
+
* - AVERROR_EINVAL: Invalid packet
|
|
323
269
|
*
|
|
324
270
|
* @example
|
|
325
271
|
* ```typescript
|
|
326
|
-
* import {
|
|
272
|
+
* import { FFmpegError } from 'node-av';
|
|
327
273
|
*
|
|
328
274
|
* const ret = packet.makeRefcounted();
|
|
329
275
|
* FFmpegError.throwIfError(ret, 'makeRefcounted');
|
|
330
|
-
* // Packet data is now reference counted
|
|
331
|
-
* // Safe to share with multiple owners
|
|
332
276
|
* ```
|
|
333
|
-
*
|
|
334
|
-
* Note: This function does not ensure that the reference will be writable.
|
|
335
|
-
* Use makeWritable() for that purpose.
|
|
336
|
-
*
|
|
337
|
-
* @see {@link makeWritable} To ensure data is writable
|
|
338
277
|
*/
|
|
339
278
|
makeRefcounted(): number;
|
|
340
279
|
/**
|
|
341
|
-
*
|
|
280
|
+
* Ensure packet data is writable.
|
|
342
281
|
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* is unreferenced. This avoids data copy if possible.
|
|
282
|
+
* Creates a private copy of the data if it's shared with other packets.
|
|
283
|
+
* Call before modifying packet data to avoid affecting other references.
|
|
346
284
|
*
|
|
347
|
-
* Direct mapping to av_packet_make_writable()
|
|
285
|
+
* Direct mapping to av_packet_make_writable().
|
|
348
286
|
*
|
|
349
287
|
* @returns 0 on success, negative AVERROR on error:
|
|
350
|
-
* -
|
|
351
|
-
* -
|
|
288
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
289
|
+
* - AVERROR_EINVAL: Invalid packet
|
|
352
290
|
*
|
|
353
291
|
* @example
|
|
354
292
|
* ```typescript
|
|
355
|
-
* import {
|
|
293
|
+
* import { FFmpegError } from 'node-av';
|
|
356
294
|
*
|
|
357
|
-
* //
|
|
295
|
+
* // Ensure we can safely modify data
|
|
358
296
|
* const ret = packet.makeWritable();
|
|
359
297
|
* FFmpegError.throwIfError(ret, 'makeWritable');
|
|
360
|
-
*
|
|
361
|
-
* // Now safe to modify packet data
|
|
362
|
-
* const data = packet.data;
|
|
363
|
-
* if (data) {
|
|
364
|
-
* // Modify data buffer directly
|
|
365
|
-
* data[0] = 0xFF;
|
|
366
|
-
* }
|
|
298
|
+
* // Now safe to modify packet.data
|
|
367
299
|
* ```
|
|
368
|
-
*
|
|
369
|
-
* @see {@link makeRefcounted} To make data reference counted
|
|
370
300
|
*/
|
|
371
301
|
makeWritable(): number;
|
|
372
302
|
/**
|
|
373
|
-
* Get side data
|
|
303
|
+
* Get packet side data.
|
|
304
|
+
*
|
|
305
|
+
* Retrieves additional data associated with the packet
|
|
306
|
+
* (e.g., palette data, quality stats, encryption info).
|
|
374
307
|
*
|
|
375
|
-
* Direct mapping to av_packet_get_side_data()
|
|
308
|
+
* Direct mapping to av_packet_get_side_data().
|
|
376
309
|
*
|
|
377
|
-
* @param type -
|
|
378
|
-
* @returns
|
|
310
|
+
* @param type - Type of side data to retrieve
|
|
311
|
+
* @returns Side data buffer, or null if not present
|
|
379
312
|
*
|
|
380
313
|
* @example
|
|
381
314
|
* ```typescript
|
|
382
|
-
* import { Packet } from 'node-av';
|
|
383
315
|
* import { AV_PKT_DATA_PALETTE } from 'node-av/constants';
|
|
384
316
|
*
|
|
385
|
-
* const
|
|
386
|
-
* if (
|
|
387
|
-
* console.log(
|
|
317
|
+
* const palette = packet.getSideData(AV_PKT_DATA_PALETTE);
|
|
318
|
+
* if (palette) {
|
|
319
|
+
* console.log(`Palette size: ${palette.length} bytes`);
|
|
388
320
|
* }
|
|
389
321
|
* ```
|
|
322
|
+
*
|
|
323
|
+
* @see {@link addSideData} To add side data
|
|
324
|
+
* @see {@link newSideData} To allocate new side data
|
|
390
325
|
*/
|
|
391
326
|
getSideData(type: AVPacketSideDataType): Buffer | null;
|
|
392
327
|
/**
|
|
393
|
-
* Add side data to
|
|
328
|
+
* Add side data to packet.
|
|
394
329
|
*
|
|
395
|
-
*
|
|
396
|
-
* Direct mapping to av_packet_add_side_data()
|
|
330
|
+
* Attaches additional data to the packet. The data is copied.
|
|
397
331
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* @
|
|
332
|
+
* Direct mapping to av_packet_add_side_data().
|
|
333
|
+
*
|
|
334
|
+
* @param type - Type of side data
|
|
335
|
+
* @param data - Side data buffer
|
|
336
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
337
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
338
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
401
339
|
*
|
|
402
340
|
* @example
|
|
403
341
|
* ```typescript
|
|
404
|
-
* import {
|
|
342
|
+
* import { FFmpegError } from 'node-av';
|
|
405
343
|
* import { AV_PKT_DATA_NEW_EXTRADATA } from 'node-av/constants';
|
|
406
344
|
*
|
|
407
|
-
* const
|
|
408
|
-
* const ret = packet.addSideData(AV_PKT_DATA_NEW_EXTRADATA,
|
|
409
|
-
*
|
|
410
|
-
* console.error('Failed to add side data');
|
|
411
|
-
* }
|
|
345
|
+
* const extradata = Buffer.from([...]);
|
|
346
|
+
* const ret = packet.addSideData(AV_PKT_DATA_NEW_EXTRADATA, extradata);
|
|
347
|
+
* FFmpegError.throwIfError(ret, 'addSideData');
|
|
412
348
|
* ```
|
|
349
|
+
*
|
|
350
|
+
* @see {@link getSideData} To retrieve side data
|
|
351
|
+
* @see {@link newSideData} To allocate in-place
|
|
413
352
|
*/
|
|
414
353
|
addSideData(type: AVPacketSideDataType, data: Buffer): number;
|
|
415
354
|
/**
|
|
416
|
-
* Allocate new side data
|
|
355
|
+
* Allocate new side data.
|
|
356
|
+
*
|
|
357
|
+
* Allocates side data buffer attached to the packet.
|
|
358
|
+
* Returns buffer that can be written to directly.
|
|
359
|
+
*
|
|
360
|
+
* Direct mapping to av_packet_new_side_data().
|
|
417
361
|
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
362
|
+
* @param type - Type of side data
|
|
363
|
+
* @param size - Size in bytes to allocate
|
|
364
|
+
* @returns Allocated buffer for writing
|
|
421
365
|
*
|
|
422
|
-
* @param type - The type of side data to allocate
|
|
423
|
-
* @param size - Size of the side data buffer to allocate
|
|
424
|
-
* @returns Buffer referencing the allocated side data
|
|
425
366
|
* @throws {Error} If allocation fails
|
|
426
367
|
*
|
|
427
368
|
* @example
|
|
428
369
|
* ```typescript
|
|
429
|
-
* import {
|
|
430
|
-
* import { AV_PKT_DATA_STRINGS_METADATA } from 'node-av/constants';
|
|
370
|
+
* import { AV_PKT_DATA_NEW_EXTRADATA } from 'node-av/constants';
|
|
431
371
|
*
|
|
432
|
-
* // Allocate
|
|
433
|
-
* const
|
|
434
|
-
*
|
|
435
|
-
* metadataBuffer.write('key=value', 0, 'utf8');
|
|
372
|
+
* // Allocate and write side data directly
|
|
373
|
+
* const sideData = packet.newSideData(AV_PKT_DATA_NEW_EXTRADATA, 16);
|
|
374
|
+
* sideData.writeUInt32LE(0x12345678, 0);
|
|
436
375
|
* ```
|
|
376
|
+
*
|
|
377
|
+
* @see {@link getSideData} To retrieve side data
|
|
378
|
+
* @see {@link addSideData} To add existing buffer
|
|
437
379
|
*/
|
|
438
380
|
newSideData(type: AVPacketSideDataType, size: number): Buffer;
|
|
439
381
|
/**
|
|
440
|
-
* Free all side data
|
|
382
|
+
* Free all side data.
|
|
383
|
+
*
|
|
384
|
+
* Removes all side data attached to the packet.
|
|
441
385
|
*
|
|
442
|
-
*
|
|
443
|
-
* Direct mapping to av_packet_free_side_data()
|
|
386
|
+
* Direct mapping to av_packet_free_side_data().
|
|
444
387
|
*
|
|
445
388
|
* @example
|
|
446
389
|
* ```typescript
|
|
447
|
-
* // Remove all side data from the packet
|
|
448
390
|
* packet.freeSideData();
|
|
391
|
+
* // All side data removed
|
|
449
392
|
* ```
|
|
450
393
|
*/
|
|
451
394
|
freeSideData(): void;
|
|
452
395
|
/**
|
|
453
|
-
* Get the native
|
|
396
|
+
* Get the underlying native Packet object.
|
|
454
397
|
*
|
|
455
|
-
* @
|
|
456
|
-
*
|
|
398
|
+
* @returns The native Packet binding object
|
|
399
|
+
*
|
|
400
|
+
* @internal
|
|
457
401
|
*/
|
|
458
402
|
getNative(): NativePacket;
|
|
459
403
|
/**
|
|
@@ -464,23 +408,11 @@ export declare class Packet implements Disposable, NativeWrapper<NativePacket> {
|
|
|
464
408
|
*
|
|
465
409
|
* @example
|
|
466
410
|
* ```typescript
|
|
467
|
-
* import { Packet } from 'node-av';
|
|
468
|
-
*
|
|
469
|
-
* // Using 'using' declaration for automatic cleanup
|
|
470
411
|
* {
|
|
471
412
|
* using packet = new Packet();
|
|
472
413
|
* packet.alloc();
|
|
473
|
-
* //
|
|
414
|
+
* // Use packet...
|
|
474
415
|
* } // Automatically freed when leaving scope
|
|
475
|
-
*
|
|
476
|
-
* // Or with try-finally
|
|
477
|
-
* const packet = new Packet();
|
|
478
|
-
* try {
|
|
479
|
-
* packet.alloc();
|
|
480
|
-
* // ... use packet
|
|
481
|
-
* } finally {
|
|
482
|
-
* packet[Symbol.dispose]();
|
|
483
|
-
* }
|
|
484
416
|
* ```
|
|
485
417
|
*/
|
|
486
418
|
[Symbol.dispose](): void;
|