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.
Files changed (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,558 @@
1
+ import { bindings } from './binding.js';
2
+ /**
3
+ * Packet for compressed audio/video data.
4
+ *
5
+ * Contains compressed audio/video data read from demuxer or to be sent to muxer.
6
+ * Packets are the fundamental unit of data exchange between demuxers, muxers,
7
+ * encoders, and decoders in FFmpeg. User has full control over allocation and lifecycle.
8
+ *
9
+ * Direct mapping to FFmpeg's AVPacket.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { Packet, FormatContext, CodecContext, FFmpegError } from 'node-av';
14
+ *
15
+ * // Create and allocate packet - full control
16
+ * const packet = new Packet();
17
+ * packet.alloc();
18
+ *
19
+ * // Read from demuxer
20
+ * const ret = await formatContext.readFrame(packet);
21
+ * FFmpegError.throwIfError(ret, 'readFrame');
22
+ *
23
+ * // Process packet
24
+ * console.log(`Stream: ${packet.streamIndex}, PTS: ${packet.pts}`);
25
+ *
26
+ * // Send to decoder
27
+ * const sendRet = await codecContext.sendPacket(packet);
28
+ * FFmpegError.throwIfError(sendRet, 'sendPacket');
29
+ *
30
+ * // Cleanup
31
+ * packet.unref(); // Clear data but keep packet allocated
32
+ * packet.free(); // Free packet completely
33
+ * ```
34
+ *
35
+ * @see {@link CodecContext} For encoding/decoding packets
36
+ * @see {@link FormatContext} For reading/writing packets
37
+ */
38
+ export class Packet {
39
+ native;
40
+ /**
41
+ * Create a new packet instance.
42
+ *
43
+ * The packet is uninitialized - you must call alloc() before use.
44
+ * No FFmpeg resources are allocated until alloc() is called.
45
+ *
46
+ * Direct wrapper around AVPacket allocation.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { Packet } from 'node-av';
51
+ *
52
+ * const packet = new Packet();
53
+ * packet.alloc();
54
+ * // Packet is now ready for use
55
+ *
56
+ * // Always free when done
57
+ * packet.free();
58
+ * ```
59
+ */
60
+ constructor() {
61
+ this.native = new bindings.Packet();
62
+ }
63
+ /**
64
+ * Stream index this packet belongs to.
65
+ *
66
+ * Direct mapping to AVPacket->stream_index
67
+ *
68
+ * Set by demuxer to indicate which stream this packet belongs to.
69
+ * Must be set by user for muxing.
70
+ */
71
+ get streamIndex() {
72
+ return this.native.streamIndex;
73
+ }
74
+ set streamIndex(value) {
75
+ this.native.streamIndex = value;
76
+ }
77
+ /**
78
+ * Presentation timestamp in AVStream->time_base units.
79
+ *
80
+ * Direct mapping to AVPacket->pts
81
+ *
82
+ * The time at which the decompressed packet will be presented to the user.
83
+ * Can be AV_NOPTS_VALUE if it is not stored in the file.
84
+ * pts MUST be larger or equal to dts as presentation cannot happen before
85
+ * decompression, unless one wants to view hex dumps. Some formats misuse
86
+ * the terms dts and pts/cts to mean something different. Such timestamps
87
+ * must be converted to true pts/dts before they are stored in AVPacket.
88
+ */
89
+ get pts() {
90
+ return this.native.pts;
91
+ }
92
+ set pts(value) {
93
+ this.native.pts = value;
94
+ }
95
+ /**
96
+ * Decompression timestamp in AVStream->time_base units.
97
+ *
98
+ * Direct mapping to AVPacket->dts
99
+ *
100
+ * The time at which the packet is decompressed.
101
+ * Can be AV_NOPTS_VALUE if it is not stored in the file.
102
+ */
103
+ get dts() {
104
+ return this.native.dts;
105
+ }
106
+ set dts(value) {
107
+ this.native.dts = value;
108
+ }
109
+ /**
110
+ * Duration of this packet in AVStream->time_base units, 0 if unknown.
111
+ *
112
+ * Direct mapping to AVPacket->duration
113
+ *
114
+ * Equals next_pts - this_pts in presentation order.
115
+ */
116
+ get duration() {
117
+ return this.native.duration;
118
+ }
119
+ set duration(value) {
120
+ this.native.duration = value;
121
+ }
122
+ /**
123
+ * Byte position in stream, -1 if unknown.
124
+ *
125
+ * Direct mapping to AVPacket->pos
126
+ *
127
+ * Can be used to derive seeking positions for formats without timestamps.
128
+ */
129
+ get pos() {
130
+ return this.native.pos;
131
+ }
132
+ set pos(value) {
133
+ this.native.pos = value;
134
+ }
135
+ /**
136
+ * Size of packet data in bytes.
137
+ *
138
+ * Direct mapping to AVPacket->size
139
+ *
140
+ * @readonly
141
+ */
142
+ get size() {
143
+ return this.native.size;
144
+ }
145
+ /**
146
+ * A combination of AV_PKT_FLAG values.
147
+ *
148
+ * Direct mapping to AVPacket->flags
149
+ *
150
+ * - AV_PKT_FLAG_KEY: The packet contains a keyframe
151
+ * - AV_PKT_FLAG_CORRUPT: The packet content is corrupted
152
+ * - AV_PKT_FLAG_DISCARD: Flag for packets that should be dropped
153
+ * - AV_PKT_FLAG_TRUSTED: The packet comes from a trusted source
154
+ * - AV_PKT_FLAG_DISPOSABLE: Flag for packets that can be dropped if needed
155
+ */
156
+ get flags() {
157
+ return this.native.flags;
158
+ }
159
+ set flags(value) {
160
+ this.native.flags = value;
161
+ }
162
+ /**
163
+ * Packet data buffer.
164
+ *
165
+ * Direct mapping to AVPacket->data
166
+ *
167
+ * Can be null if the packet is empty or unallocated.
168
+ * Setting null will unref the packet data.
169
+ * When setting a new buffer, av_packet_from_data() is called internally.
170
+ */
171
+ get data() {
172
+ return this.native.data;
173
+ }
174
+ set data(value) {
175
+ this.native.data = value;
176
+ }
177
+ /**
178
+ * Check if packet contains a keyframe.
179
+ *
180
+ * This is a convenience accessor for the AV_PKT_FLAG_KEY flag.
181
+ */
182
+ get isKeyframe() {
183
+ return this.native.isKeyframe;
184
+ }
185
+ set isKeyframe(value) {
186
+ this.native.isKeyframe = value;
187
+ }
188
+ /**
189
+ * Allocate an AVPacket and set its fields to default values.
190
+ *
191
+ * Allocates the AVPacket structure and initializes all fields to default values.
192
+ * This only allocates the packet structure itself, not the data buffers.
193
+ *
194
+ * Direct mapping to av_packet_alloc()
195
+ *
196
+ * @throws {Error} Memory allocation failure (ENOMEM)
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * import { Packet } from 'node-av';
201
+ *
202
+ * const packet = new Packet();
203
+ * packet.alloc();
204
+ * // Packet is now allocated with default values
205
+ * // pts = AV_NOPTS_VALUE, dts = AV_NOPTS_VALUE
206
+ * // size = 0, data = null
207
+ * ```
208
+ *
209
+ * @see {@link free} Must be called when done
210
+ * @see {@link unref} To clear data but keep allocation
211
+ */
212
+ alloc() {
213
+ this.native.alloc();
214
+ }
215
+ /**
216
+ * Free the packet.
217
+ *
218
+ * Direct mapping to av_packet_free()
219
+ *
220
+ * If the packet has a reference counted buffer, it will be unreferenced first.
221
+ * After calling this, the packet is no longer usable until alloc() is called again.
222
+ *
223
+ * @note
224
+ * Calling this multiple times is safe, because we check the freed state
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * packet.free();
229
+ * // packet is now invalid and should not be used
230
+ * ```
231
+ */
232
+ free() {
233
+ this.native.free();
234
+ }
235
+ /**
236
+ * Setup a new reference to the data described by a given packet.
237
+ *
238
+ * If src is reference counted, increase its reference count.
239
+ * Otherwise allocate a new buffer for dst and copy the data from src into it.
240
+ * All the other fields are copied from src.
241
+ *
242
+ * Direct mapping to av_packet_ref()
243
+ *
244
+ * @param src - Source packet to reference
245
+ *
246
+ * @returns 0 on success, negative AVERROR on error:
247
+ * - 0: Success
248
+ * - AVERROR(ENOMEM): Memory allocation failure
249
+ * - AVERROR(EINVAL): Invalid parameters (null packet)
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * import { Packet, FFmpegError } from 'node-av';
254
+ *
255
+ * const src = new Packet();
256
+ * // ... src contains data ...
257
+ * const dst = new Packet();
258
+ * dst.alloc();
259
+ *
260
+ * const ret = dst.ref(src);
261
+ * FFmpegError.throwIfError(ret, 'packet.ref');
262
+ * // dst now references the same data as src
263
+ * ```
264
+ *
265
+ * @see {@link unref} To remove reference
266
+ * @see {@link clone} For simpler cloning
267
+ */
268
+ ref(src) {
269
+ return this.native.ref(src.getNative());
270
+ }
271
+ /**
272
+ * Wipe the packet.
273
+ *
274
+ * Direct mapping to av_packet_unref()
275
+ *
276
+ * Unreference the buffer referenced by the packet and reset the
277
+ * remaining packet fields to their default values.
278
+ *
279
+ * The packet remains allocated and can be reused.
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * packet.unref();
284
+ * // Packet data is cleared but packet remains allocated
285
+ * // Can reuse the packet for another read
286
+ * ```
287
+ *
288
+ * @note The packet must have been allocated with alloc().
289
+ */
290
+ unref() {
291
+ this.native.unref();
292
+ }
293
+ /**
294
+ * Create a new packet that references the same data as this packet.
295
+ *
296
+ * This is a shortcut for av_packet_alloc() + av_packet_ref().
297
+ * The new packet shares the same data buffer through reference counting.
298
+ *
299
+ * Direct mapping to av_packet_clone()
300
+ *
301
+ * @returns New packet referencing the same data, or null on error (ENOMEM)
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * import { Packet } from 'node-av';
306
+ *
307
+ * const original = new Packet();
308
+ * // ... original contains data ...
309
+ *
310
+ * const cloned = original.clone();
311
+ * if (!cloned) {
312
+ * throw new Error('Failed to clone packet: Out of memory');
313
+ * }
314
+ * // cloned references the same data as original
315
+ * // Both packets must be freed independently
316
+ * cloned.free();
317
+ * original.free();
318
+ * ```
319
+ *
320
+ * @see {@link ref} For manual reference setup
321
+ */
322
+ clone() {
323
+ const cloned = this.native.clone();
324
+ if (!cloned) {
325
+ return null;
326
+ }
327
+ // Wrap the native cloned packet
328
+ const packet = Object.create(Packet.prototype);
329
+ // Need to set private property - this is safe since we control the implementation
330
+ packet.native = cloned;
331
+ return packet;
332
+ }
333
+ /**
334
+ * Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
335
+ *
336
+ * Timestamps with unknown values (AV_NOPTS_VALUE) will be ignored.
337
+ * This function is useful when you need to convert packet timestamps between
338
+ * different contexts, for example when remuxing or when the decoder and encoder
339
+ * use different timebases.
340
+ *
341
+ * Direct mapping to av_packet_rescale_ts()
342
+ *
343
+ * @param srcTimebase - Source timebase, in which the timestamps are expressed
344
+ * @param dstTimebase - Destination timebase, to which the timestamps will be converted
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * import { Packet, Rational } from 'node-av';
349
+ *
350
+ * // Convert from stream timebase to codec timebase
351
+ * const streamTimebase = new Rational(1, 90000); // 90kHz
352
+ * const codecTimebase = new Rational(1, 25); // 25 fps
353
+ *
354
+ * packet.rescaleTs(
355
+ * streamTimebase,
356
+ * codecTimebase
357
+ * );
358
+ * // PTS and DTS are now in codec timebase
359
+ * ```
360
+ *
361
+ * @see {@link Rational} For timebase representation
362
+ */
363
+ rescaleTs(srcTimebase, dstTimebase) {
364
+ this.native.rescaleTs({ num: srcTimebase.num, den: srcTimebase.den }, { num: dstTimebase.num, den: dstTimebase.den });
365
+ }
366
+ /**
367
+ * Ensure the data described by the packet is reference counted.
368
+ *
369
+ * Makes the packet data reference counted if it isn't already.
370
+ * This is useful when you need to share packet data between multiple owners.
371
+ *
372
+ * Direct mapping to av_packet_make_refcounted()
373
+ *
374
+ * @returns 0 on success, negative AVERROR on error:
375
+ * - 0: Success (data is now reference counted)
376
+ * - AVERROR(ENOMEM): Memory allocation failure
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * import { Packet, FFmpegError } from 'node-av';
381
+ *
382
+ * const ret = packet.makeRefcounted();
383
+ * FFmpegError.throwIfError(ret, 'makeRefcounted');
384
+ * // Packet data is now reference counted
385
+ * // Safe to share with multiple owners
386
+ * ```
387
+ *
388
+ * Note: This function does not ensure that the reference will be writable.
389
+ * Use makeWritable() for that purpose.
390
+ *
391
+ * @see {@link makeWritable} To ensure data is writable
392
+ */
393
+ makeRefcounted() {
394
+ return this.native.makeRefcounted();
395
+ }
396
+ /**
397
+ * Create a writable reference for the data described by the packet.
398
+ *
399
+ * If the packet data buffer is already writable, this does nothing.
400
+ * Otherwise, a new buffer is allocated, data is copied, and the old buffer
401
+ * is unreferenced. This avoids data copy if possible.
402
+ *
403
+ * Direct mapping to av_packet_make_writable()
404
+ *
405
+ * @returns 0 on success, negative AVERROR on error:
406
+ * - 0: Success (data is now writable)
407
+ * - AVERROR(ENOMEM): Memory allocation failure
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * import { Packet, FFmpegError } from 'node-av';
412
+ *
413
+ * // Before modifying packet data
414
+ * const ret = packet.makeWritable();
415
+ * FFmpegError.throwIfError(ret, 'makeWritable');
416
+ *
417
+ * // Now safe to modify packet data
418
+ * const data = packet.data;
419
+ * if (data) {
420
+ * // Modify data buffer directly
421
+ * data[0] = 0xFF;
422
+ * }
423
+ * ```
424
+ *
425
+ * @see {@link makeRefcounted} To make data reference counted
426
+ */
427
+ makeWritable() {
428
+ return this.native.makeWritable();
429
+ }
430
+ /**
431
+ * Get side data from the packet.
432
+ *
433
+ * Direct mapping to av_packet_get_side_data()
434
+ *
435
+ * @param type - The type of side data to retrieve
436
+ * @returns Buffer containing the side data, or null if not found
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * import { Packet } from 'node-av';
441
+ * import { AV_PKT_DATA_PALETTE } from 'node-av/constants';
442
+ *
443
+ * const paletteData = packet.getSideData(AV_PKT_DATA_PALETTE);
444
+ * if (paletteData) {
445
+ * console.log('Palette data size:', paletteData.length);
446
+ * }
447
+ * ```
448
+ */
449
+ getSideData(type) {
450
+ return this.native.getSideData(type);
451
+ }
452
+ /**
453
+ * Add side data to the packet.
454
+ *
455
+ * Allocates and adds side data to the packet. The data is copied.
456
+ * Direct mapping to av_packet_add_side_data()
457
+ *
458
+ * @param type - The type of side data to add
459
+ * @param data - Buffer containing the side data
460
+ * @returns 0 on success, negative AVERROR on failure
461
+ *
462
+ * @example
463
+ * ```typescript
464
+ * import { Packet } from 'node-av';
465
+ * import { AV_PKT_DATA_NEW_EXTRADATA } from 'node-av/constants';
466
+ *
467
+ * const extraData = Buffer.from([0x01, 0x02, 0x03]);
468
+ * const ret = packet.addSideData(AV_PKT_DATA_NEW_EXTRADATA, extraData);
469
+ * if (ret < 0) {
470
+ * console.error('Failed to add side data');
471
+ * }
472
+ * ```
473
+ */
474
+ addSideData(type, data) {
475
+ return this.native.addSideData(type, data);
476
+ }
477
+ /**
478
+ * Allocate new side data for the packet.
479
+ *
480
+ * Allocates a new side data buffer of the specified size.
481
+ * Returns a Buffer that references the allocated memory.
482
+ * Direct mapping to av_packet_new_side_data()
483
+ *
484
+ * @param type - The type of side data to allocate
485
+ * @param size - Size of the side data buffer to allocate
486
+ * @returns Buffer referencing the allocated side data
487
+ * @throws {Error} If allocation fails
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * import { Packet } from 'node-av';
492
+ * import { AV_PKT_DATA_STRINGS_METADATA } from 'node-av/constants';
493
+ *
494
+ * // Allocate 256 bytes for metadata
495
+ * const metadataBuffer = packet.newSideData(AV_PKT_DATA_STRINGS_METADATA, 256);
496
+ * // Write metadata to the buffer
497
+ * metadataBuffer.write('key=value', 0, 'utf8');
498
+ * ```
499
+ */
500
+ newSideData(type, size) {
501
+ return this.native.newSideData(type, size);
502
+ }
503
+ /**
504
+ * Free all side data from the packet.
505
+ *
506
+ * Removes and frees all side data attached to the packet.
507
+ * Direct mapping to av_packet_free_side_data()
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * // Remove all side data from the packet
512
+ * packet.freeSideData();
513
+ * ```
514
+ */
515
+ freeSideData() {
516
+ this.native.freeSideData();
517
+ }
518
+ /**
519
+ * Get the native FFmpeg AVPacket pointer.
520
+ *
521
+ * @internal For use by other wrapper classes
522
+ * @returns The underlying native packet object
523
+ */
524
+ getNative() {
525
+ return this.native;
526
+ }
527
+ /**
528
+ * Dispose of the packet.
529
+ *
530
+ * Implements the Disposable interface for automatic cleanup.
531
+ * Equivalent to calling free().
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * import { Packet } from 'node-av';
536
+ *
537
+ * // Using 'using' declaration for automatic cleanup
538
+ * {
539
+ * using packet = new Packet();
540
+ * packet.alloc();
541
+ * // ... use packet
542
+ * } // Automatically freed when leaving scope
543
+ *
544
+ * // Or with try-finally
545
+ * const packet = new Packet();
546
+ * try {
547
+ * packet.alloc();
548
+ * // ... use packet
549
+ * } finally {
550
+ * packet[Symbol.dispose]();
551
+ * }
552
+ * ```
553
+ */
554
+ [Symbol.dispose]() {
555
+ this.native[Symbol.dispose]();
556
+ }
557
+ }
558
+ //# sourceMappingURL=packet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packet.js","sourceRoot":"","sources":["../../src/lib/packet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAMxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,MAAM;IACT,MAAM,CAAe;IAE7B;;;;;;;;;;;;;;;;;;;OAmBG;IACH;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IACjC,CAAC;IAED,IAAI,WAAW,CAAC,KAAa;QAC3B,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAa;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAa;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAED,IAAI,QAAQ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