@revizly/node-av 5.2.2-beta.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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,590 @@
1
+ import { bindings } from './binding.js';
2
+ /**
3
+ * Container for compressed audio/video data.
4
+ *
5
+ * Stores encoded data from demuxers or to be sent to muxers. Each packet contains
6
+ * a portion of compressed stream data, typically one video frame or several audio frames.
7
+ * Includes timing information (PTS/DTS), stream index, and flags. Essential for
8
+ * demuxing, muxing, and codec operations.
9
+ *
10
+ * Direct mapping to FFmpeg's AVPacket.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { Packet, FFmpegError } from 'node-av';
15
+ * import { AV_PKT_FLAG_KEY } from 'node-av/constants';
16
+ *
17
+ * // Create and allocate packet
18
+ * const packet = new Packet();
19
+ * packet.alloc();
20
+ *
21
+ * // Read packet from format context
22
+ * const ret = await formatContext.readFrame(packet);
23
+ * FFmpegError.throwIfError(ret, 'readFrame');
24
+ *
25
+ * // Check packet properties
26
+ * console.log(`Stream: ${packet.streamIndex}`);
27
+ * console.log(`PTS: ${packet.pts}`);
28
+ * console.log(`Size: ${packet.size} bytes`);
29
+ * console.log(`Keyframe: ${packet.isKeyframe}`);
30
+ *
31
+ * // Send to decoder
32
+ * const ret2 = await codecContext.sendPacket(packet);
33
+ * FFmpegError.throwIfError(ret2, 'sendPacket');
34
+ *
35
+ * // Cleanup
36
+ * packet.unref();
37
+ * ```
38
+ *
39
+ * @see [AVPacket](https://ffmpeg.org/doxygen/trunk/structAVPacket.html) - FFmpeg Doxygen
40
+ * @see {@link FormatContext} For reading/writing packets
41
+ * @see {@link CodecContext} For encoding/decoding packets
42
+ */
43
+ export class Packet {
44
+ native;
45
+ constructor() {
46
+ this.native = new bindings.Packet();
47
+ }
48
+ /**
49
+ * Stream index this packet belongs to.
50
+ *
51
+ * Identifies which stream in a format context this packet is from/for.
52
+ * Set automatically when reading, must be set manually when writing.
53
+ *
54
+ * Direct mapping to AVPacket->stream_index.
55
+ */
56
+ get streamIndex() {
57
+ return this.native.streamIndex;
58
+ }
59
+ set streamIndex(value) {
60
+ this.native.streamIndex = value;
61
+ }
62
+ /**
63
+ * Presentation timestamp.
64
+ *
65
+ * Time when the decompressed packet should be presented to the user.
66
+ * In stream time base units. AV_NOPTS_VALUE if unknown.
67
+ *
68
+ * Direct mapping to AVPacket->pts.
69
+ */
70
+ get pts() {
71
+ return this.native.pts;
72
+ }
73
+ set pts(value) {
74
+ this.native.pts = value;
75
+ }
76
+ /**
77
+ * Decompression timestamp.
78
+ *
79
+ * Time when the packet should be decompressed.
80
+ * In stream time base units. AV_NOPTS_VALUE if unknown.
81
+ *
82
+ * Direct mapping to AVPacket->dts.
83
+ */
84
+ get dts() {
85
+ return this.native.dts;
86
+ }
87
+ set dts(value) {
88
+ this.native.dts = value;
89
+ }
90
+ /**
91
+ * Duration of this packet.
92
+ *
93
+ * Duration in stream time base units, 0 if unknown.
94
+ * Typically equal to next_pts - this_pts.
95
+ *
96
+ * Direct mapping to AVPacket->duration.
97
+ */
98
+ get duration() {
99
+ return this.native.duration;
100
+ }
101
+ set duration(value) {
102
+ this.native.duration = value;
103
+ }
104
+ /**
105
+ * Timebase for timestamps in this packet.
106
+ *
107
+ * Used by av_interleaved_write_frame() to correctly sort packets from different streams.
108
+ * Must be set to the output stream's timebase before calling av_interleaved_write_frame().
109
+ *
110
+ * Direct mapping to AVPacket->time_base.
111
+ */
112
+ get timeBase() {
113
+ return this.native.timeBase;
114
+ }
115
+ set timeBase(value) {
116
+ this.native.timeBase = value;
117
+ }
118
+ /**
119
+ * Byte position in stream.
120
+ *
121
+ * Byte position of packet data in the input file.
122
+ * -1 if unknown.
123
+ *
124
+ * Direct mapping to AVPacket->pos.
125
+ */
126
+ get pos() {
127
+ return this.native.pos;
128
+ }
129
+ set pos(value) {
130
+ this.native.pos = value;
131
+ }
132
+ /**
133
+ * Size of packet data in bytes.
134
+ *
135
+ * Direct mapping to AVPacket->size.
136
+ */
137
+ get size() {
138
+ return this.native.size;
139
+ }
140
+ /**
141
+ * Packet flags.
142
+ *
143
+ * Combination of AV_PKT_FLAG values indicating packet properties
144
+ * (e.g., AV_PKT_FLAG_KEY for keyframes).
145
+ *
146
+ * Direct mapping to AVPacket->flags.
147
+ */
148
+ get flags() {
149
+ return this.native.flags;
150
+ }
151
+ set flags(value) {
152
+ this.native.flags = value;
153
+ }
154
+ /**
155
+ * Packet data buffer.
156
+ *
157
+ * Contains the compressed audio/video data.
158
+ * May be null for packets signaling special conditions.
159
+ *
160
+ * Direct mapping to AVPacket->data.
161
+ */
162
+ get data() {
163
+ return this.native.data;
164
+ }
165
+ set data(value) {
166
+ this.native.data = value;
167
+ }
168
+ /**
169
+ * Check if packet contains a keyframe.
170
+ *
171
+ * Convenience property that checks AV_PKT_FLAG_KEY flag.
172
+ * Keyframes can be decoded independently without reference frames.
173
+ */
174
+ get isKeyframe() {
175
+ return this.native.isKeyframe;
176
+ }
177
+ set isKeyframe(value) {
178
+ this.native.isKeyframe = value;
179
+ }
180
+ /**
181
+ * Allocate a new packet.
182
+ *
183
+ * Allocates the packet structure. Must be called before using the packet
184
+ * unless it was created by another function (e.g., clone()).
185
+ *
186
+ * Direct mapping to av_packet_alloc().
187
+ *
188
+ * @throws {Error} If allocation fails (ENOMEM)
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const packet = new Packet();
193
+ * packet.alloc();
194
+ * // Packet is now ready for use
195
+ * ```
196
+ *
197
+ * @see {@link free} To deallocate the packet
198
+ */
199
+ alloc() {
200
+ this.native.alloc();
201
+ }
202
+ /**
203
+ * Free the packet.
204
+ *
205
+ * Deallocates the packet and its data. The packet becomes invalid after this.
206
+ *
207
+ * Direct mapping to av_packet_free().
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * packet.free();
212
+ * // Packet is now invalid
213
+ * ```
214
+ *
215
+ * @see {@link unref} To only free data, keeping structure
216
+ */
217
+ free() {
218
+ this.native.free();
219
+ }
220
+ /**
221
+ * Create a reference to another packet.
222
+ *
223
+ * Sets up this packet as a reference to the source packet's data.
224
+ * Both packets will share the same data buffer.
225
+ *
226
+ * Direct mapping to av_packet_ref().
227
+ *
228
+ * @param src - Source packet to reference
229
+ *
230
+ * @returns 0 on success, negative AVERROR on error:
231
+ * - AVERROR_ENOMEM: Memory allocation failure
232
+ * - AVERROR_EINVAL: Invalid parameters
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * import { FFmpegError } from 'node-av';
237
+ *
238
+ * const packet2 = new Packet();
239
+ * packet2.alloc();
240
+ * const ret = packet2.ref(packet1);
241
+ * FFmpegError.throwIfError(ret, 'ref');
242
+ * // packet2 now references packet1's data
243
+ * ```
244
+ *
245
+ * @see {@link unref} To remove reference
246
+ * @see {@link clone} To create independent copy
247
+ */
248
+ ref(src) {
249
+ return this.native.ref(src.getNative());
250
+ }
251
+ /**
252
+ * Unreference the packet.
253
+ *
254
+ * Frees the packet data if this was the last reference.
255
+ * The packet structure remains allocated and can be reused.
256
+ *
257
+ * Direct mapping to av_packet_unref().
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * packet.unref();
262
+ * // Packet data is freed, structure can be reused
263
+ * ```
264
+ *
265
+ * @see {@link ref} To create reference
266
+ * @see {@link free} To free everything
267
+ */
268
+ unref() {
269
+ this.native.unref();
270
+ }
271
+ /**
272
+ * Clone the packet.
273
+ *
274
+ * Creates an independent copy of the packet with its own data buffer.
275
+ * The new packet has the same content but can be modified independently.
276
+ *
277
+ * Direct mapping to av_packet_clone().
278
+ *
279
+ * @returns New packet instance, or null on allocation failure
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const copy = packet.clone();
284
+ * if (copy) {
285
+ * // Modify copy without affecting original
286
+ * copy.pts = packet.pts + 1000n;
287
+ * }
288
+ * ```
289
+ *
290
+ * @see {@link ref} To create reference instead of copy
291
+ */
292
+ clone() {
293
+ const cloned = this.native.clone();
294
+ if (!cloned) {
295
+ return null;
296
+ }
297
+ // Wrap the native cloned packet
298
+ const packet = Object.create(Packet.prototype);
299
+ packet.native = cloned;
300
+ return packet;
301
+ }
302
+ /**
303
+ * Rescale packet timestamps.
304
+ *
305
+ * Converts PTS, DTS, and duration from one time base to another.
306
+ * Essential when moving packets between streams with different time bases.
307
+ *
308
+ * Direct mapping to av_packet_rescale_ts().
309
+ *
310
+ * @param srcTimebase - Source time base
311
+ *
312
+ * @param dstTimebase - Destination time base
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * import { Rational } from 'node-av';
317
+ *
318
+ * // Convert from 1/25 fps to 1/1000 (milliseconds)
319
+ * const src = new Rational(1, 25);
320
+ * const dst = new Rational(1, 1000);
321
+ * packet.rescaleTs(src, dst);
322
+ * ```
323
+ */
324
+ rescaleTs(srcTimebase, dstTimebase) {
325
+ this.native.rescaleTs({ num: srcTimebase.num, den: srcTimebase.den }, { num: dstTimebase.num, den: dstTimebase.den });
326
+ }
327
+ /**
328
+ * Ensure packet data is reference counted.
329
+ *
330
+ * Makes sure the packet data is stored in a reference-counted buffer.
331
+ * If not already reference-counted, allocates a new buffer and copies data.
332
+ *
333
+ * Direct mapping to av_packet_make_refcounted().
334
+ *
335
+ * @returns 0 on success, negative AVERROR on error:
336
+ * - AVERROR_ENOMEM: Memory allocation failure
337
+ * - AVERROR_EINVAL: Invalid packet
338
+ *
339
+ * @example
340
+ * ```typescript
341
+ * import { FFmpegError } from 'node-av';
342
+ *
343
+ * const ret = packet.makeRefcounted();
344
+ * FFmpegError.throwIfError(ret, 'makeRefcounted');
345
+ * ```
346
+ */
347
+ makeRefcounted() {
348
+ return this.native.makeRefcounted();
349
+ }
350
+ /**
351
+ * Ensure packet data is writable.
352
+ *
353
+ * Creates a private copy of the data if it's shared with other packets.
354
+ * Call before modifying packet data to avoid affecting other references.
355
+ *
356
+ * Direct mapping to av_packet_make_writable().
357
+ *
358
+ * @returns 0 on success, negative AVERROR on error:
359
+ * - AVERROR_ENOMEM: Memory allocation failure
360
+ * - AVERROR_EINVAL: Invalid packet
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * import { FFmpegError } from 'node-av';
365
+ *
366
+ * // Ensure we can safely modify data
367
+ * const ret = packet.makeWritable();
368
+ * FFmpegError.throwIfError(ret, 'makeWritable');
369
+ * // Now safe to modify packet.data
370
+ * ```
371
+ */
372
+ makeWritable() {
373
+ return this.native.makeWritable();
374
+ }
375
+ /**
376
+ * Get packet side data.
377
+ *
378
+ * Retrieves additional data associated with the packet
379
+ * (e.g., palette data, quality stats, encryption info).
380
+ *
381
+ * Direct mapping to av_packet_get_side_data().
382
+ *
383
+ * @param type - Type of side data to retrieve
384
+ *
385
+ * @returns Side data buffer, or null if not present
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * import { AV_PKT_DATA_PALETTE } from 'node-av/constants';
390
+ *
391
+ * const palette = packet.getSideData(AV_PKT_DATA_PALETTE);
392
+ * if (palette) {
393
+ * console.log(`Palette size: ${palette.length} bytes`);
394
+ * }
395
+ * ```
396
+ *
397
+ * @see {@link addSideData} To add side data
398
+ * @see {@link newSideData} To allocate new side data
399
+ */
400
+ getSideData(type) {
401
+ return this.native.getSideData(type);
402
+ }
403
+ /**
404
+ * Add side data to packet.
405
+ *
406
+ * Attaches additional data to the packet. The data is copied.
407
+ *
408
+ * Direct mapping to av_packet_add_side_data().
409
+ *
410
+ * @param type - Type of side data
411
+ *
412
+ * @param data - Side data buffer
413
+ *
414
+ * @returns 0 on success, negative AVERROR on error:
415
+ * - AVERROR_ENOMEM: Memory allocation failure
416
+ * - AVERROR_EINVAL: Invalid parameters
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * import { FFmpegError } from 'node-av';
421
+ * import { AV_PKT_DATA_NEW_EXTRADATA } from 'node-av/constants';
422
+ *
423
+ * const extradata = Buffer.from([...]);
424
+ * const ret = packet.addSideData(AV_PKT_DATA_NEW_EXTRADATA, extradata);
425
+ * FFmpegError.throwIfError(ret, 'addSideData');
426
+ * ```
427
+ *
428
+ * @see {@link getSideData} To retrieve side data
429
+ * @see {@link newSideData} To allocate in-place
430
+ */
431
+ addSideData(type, data) {
432
+ return this.native.addSideData(type, data);
433
+ }
434
+ /**
435
+ * Allocate new side data.
436
+ *
437
+ * Allocates side data buffer attached to the packet.
438
+ * Returns buffer that can be written to directly.
439
+ *
440
+ * Direct mapping to av_packet_new_side_data().
441
+ *
442
+ * @param type - Type of side data
443
+ *
444
+ * @param size - Size in bytes to allocate
445
+ *
446
+ * @returns Allocated buffer for writing
447
+ *
448
+ * @throws {Error} If allocation fails
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * import { AV_PKT_DATA_NEW_EXTRADATA } from 'node-av/constants';
453
+ *
454
+ * // Allocate and write side data directly
455
+ * const sideData = packet.newSideData(AV_PKT_DATA_NEW_EXTRADATA, 16);
456
+ * sideData.writeUInt32LE(0x12345678, 0);
457
+ * ```
458
+ *
459
+ * @see {@link getSideData} To retrieve side data
460
+ * @see {@link addSideData} To add existing buffer
461
+ */
462
+ newSideData(type, size) {
463
+ return this.native.newSideData(type, size);
464
+ }
465
+ /**
466
+ * Free all side data.
467
+ *
468
+ * Removes all side data attached to the packet.
469
+ *
470
+ * Direct mapping to av_packet_free_side_data().
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * packet.freeSideData();
475
+ * // All side data removed
476
+ * ```
477
+ */
478
+ freeSideData() {
479
+ this.native.freeSideData();
480
+ }
481
+ /**
482
+ * Set packet flags.
483
+ *
484
+ * Sets one or more flags using bitwise OR. Allows setting multiple flags
485
+ * without manually performing bitwise operations.
486
+ *
487
+ * @param flags - One or more flag values to set
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * import { AV_PKT_FLAG_KEY, AV_PKT_FLAG_DISCARD } from 'node-av/constants';
492
+ *
493
+ * // Set multiple flags at once
494
+ * packet.setFlags(AV_PKT_FLAG_KEY, AV_PKT_FLAG_DISCARD);
495
+ * ```
496
+ *
497
+ * @see {@link clearFlags} To unset flags
498
+ * @see {@link hasFlags} To check flags
499
+ * @see {@link flags} For direct flag access
500
+ */
501
+ setFlags(...flags) {
502
+ for (const flag of flags) {
503
+ this.native.flags = (this.native.flags | flag);
504
+ }
505
+ }
506
+ /**
507
+ * Clear packet flags.
508
+ *
509
+ * Clears one or more flags using bitwise AND NOT. Allows clearing multiple
510
+ * flags without manually performing bitwise operations.
511
+ *
512
+ * @param flags - One or more flag values to clear
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * import { AV_PKT_FLAG_DISCARD } from 'node-av/constants';
517
+ *
518
+ * // Clear specific flag
519
+ * packet.clearFlags(AV_PKT_FLAG_DISCARD);
520
+ * ```
521
+ *
522
+ * @see {@link setFlags} To set flags
523
+ * @see {@link hasFlags} To check flags
524
+ * @see {@link flags} For direct flag access
525
+ */
526
+ clearFlags(...flags) {
527
+ for (const flag of flags) {
528
+ this.native.flags = (this.native.flags & ~flag);
529
+ }
530
+ }
531
+ /**
532
+ * Check if packet has specific flags.
533
+ *
534
+ * Tests whether all specified flags are set using bitwise AND.
535
+ *
536
+ * @param flags - One or more flag values to check
537
+ *
538
+ * @returns true if all specified flags are set, false otherwise
539
+ *
540
+ * @example
541
+ * ```typescript
542
+ * import { AV_PKT_FLAG_KEY } from 'node-av/constants';
543
+ *
544
+ * if (packet.hasFlags(AV_PKT_FLAG_KEY)) {
545
+ * console.log('This is a keyframe packet');
546
+ * }
547
+ * ```
548
+ *
549
+ * @see {@link setFlags} To set flags
550
+ * @see {@link clearFlags} To unset flags
551
+ * @see {@link flags} For direct flag access
552
+ */
553
+ hasFlags(...flags) {
554
+ for (const flag of flags) {
555
+ if ((this.native.flags & flag) !== flag) {
556
+ return false;
557
+ }
558
+ }
559
+ return true;
560
+ }
561
+ /**
562
+ * Get the underlying native Packet object.
563
+ *
564
+ * @returns The native Packet binding object
565
+ *
566
+ * @internal
567
+ */
568
+ getNative() {
569
+ return this.native;
570
+ }
571
+ /**
572
+ * Dispose of the packet.
573
+ *
574
+ * Implements the Disposable interface for automatic cleanup.
575
+ * Equivalent to calling free().
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * {
580
+ * using packet = new Packet();
581
+ * packet.alloc();
582
+ * // Use packet...
583
+ * } // Automatically freed when leaving scope
584
+ * ```
585
+ */
586
+ [Symbol.dispose]() {
587
+ this.native[Symbol.dispose]();
588
+ }
589
+ }
590
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,OAAO,MAAM;IACT,MAAM,CAAe;IAE7B;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;;;;;;;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;;;;;;;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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