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.
Files changed (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -1,155 +1,230 @@
1
- /**
2
- * FFmpeg utility functions collection.
3
- *
4
- * Provides direct mappings to various FFmpeg utility functions from libavutil.
5
- * These functions handle common operations like timestamp conversion, image buffer
6
- * allocation, sample format queries, and more.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { avImageAlloc, avTs2TimeStr, avRescaleQ, FFmpegError } from 'node-av';
11
- * import { AV_PIX_FMT_YUV420P, IRational } from 'node-av';
12
- *
13
- * // Allocate image buffer
14
- * const image = avImageAlloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
15
- * console.log(`Allocated ${image.size} bytes`);
16
- *
17
- * // Convert timestamp to readable time
18
- * const timebase: IRational = { num: 1, den: 90000 };
19
- * const pts = 450000n;
20
- * console.log(avTs2TimeStr(pts, timebase)); // "5.000000"
21
- * ```
22
- */
23
1
  import { bindings } from './binding.js';
24
2
  import { FFmpegError } from './error.js';
25
3
  /**
26
- * Get bytes per sample for a sample format.
4
+ * Get bytes per audio sample.
27
5
  *
28
- * Returns the number of bytes required to store one sample in the given format.
6
+ * Returns the number of bytes required to store a single audio sample
7
+ * in the specified format.
29
8
  *
30
- * Direct mapping to av_get_bytes_per_sample()
9
+ * Direct mapping to av_get_bytes_per_sample().
31
10
  *
32
11
  * @param sampleFmt - Audio sample format
33
- *
34
- * @returns Number of bytes per sample, or 0 for invalid format
12
+ * @returns Number of bytes per sample, or 0 if unknown format
35
13
  *
36
14
  * @example
37
15
  * ```typescript
38
- * import { avGetBytesPerSample, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT } from 'node-av';
16
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
39
17
  *
40
- * console.log(avGetBytesPerSample(AV_SAMPLE_FMT_S16)); // 2
41
- * console.log(avGetBytesPerSample(AV_SAMPLE_FMT_FLT)); // 4
18
+ * const bytesS16 = avGetBytesPerSample(AV_SAMPLE_FMT_S16); // Returns 2
19
+ * const bytesFloat = avGetBytesPerSample(AV_SAMPLE_FMT_FLTP); // Returns 4
42
20
  * ```
43
21
  */
44
22
  export function avGetBytesPerSample(sampleFmt) {
45
23
  return bindings.avGetBytesPerSample(sampleFmt);
46
24
  }
47
25
  /**
48
- * Get the name of a sample format.
26
+ * Get sample format name.
49
27
  *
50
- * Returns a string describing the sample format.
28
+ * Returns the name of the audio sample format as a string.
51
29
  *
52
- * Direct mapping to av_get_sample_fmt_name()
30
+ * Direct mapping to av_get_sample_fmt_name().
53
31
  *
54
32
  * @param sampleFmt - Audio sample format
55
- *
56
- * @returns Format name string, or null for invalid format
33
+ * @returns Format name, or null if unknown
57
34
  *
58
35
  * @example
59
36
  * ```typescript
60
- * import { avGetSampleFmtName, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av';
37
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
61
38
  *
62
- * console.log(avGetSampleFmtName(AV_SAMPLE_FMT_S16)); // "s16"
63
- * console.log(avGetSampleFmtName(AV_SAMPLE_FMT_FLTP)); // "fltp"
39
+ * const name1 = avGetSampleFmtName(AV_SAMPLE_FMT_S16); // Returns "s16"
40
+ * const name2 = avGetSampleFmtName(AV_SAMPLE_FMT_FLTP); // Returns "fltp"
64
41
  * ```
65
42
  */
66
43
  export function avGetSampleFmtName(sampleFmt) {
67
44
  return bindings.avGetSampleFmtName(sampleFmt);
68
45
  }
69
46
  /**
70
- * Get packed sample format
71
- * Direct mapping to av_get_packed_sample_fmt()
47
+ * Get packed sample format.
48
+ *
49
+ * Returns the packed (interleaved) version of a planar sample format,
50
+ * or the format itself if already packed.
51
+ *
52
+ * Direct mapping to av_get_packed_sample_fmt().
53
+ *
54
+ * @param sampleFmt - Audio sample format
55
+ * @returns Packed version of the format
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT } from 'node-av/constants';
60
+ *
61
+ * const packed = avGetPackedSampleFmt(AV_SAMPLE_FMT_FLTP); // Returns AV_SAMPLE_FMT_FLT
62
+ * const same = avGetPackedSampleFmt(AV_SAMPLE_FMT_FLT); // Returns AV_SAMPLE_FMT_FLT
63
+ * ```
64
+ *
65
+ * @see {@link avGetPlanarSampleFmt} For getting planar version
72
66
  */
73
67
  export function avGetPackedSampleFmt(sampleFmt) {
74
68
  return bindings.avGetPackedSampleFmt(sampleFmt);
75
69
  }
76
70
  /**
77
- * Get planar sample format
78
- * Direct mapping to av_get_planar_sample_fmt()
71
+ * Get planar sample format.
72
+ *
73
+ * Returns the planar (non-interleaved) version of a packed sample format,
74
+ * or the format itself if already planar.
75
+ *
76
+ * Direct mapping to av_get_planar_sample_fmt().
77
+ *
78
+ * @param sampleFmt - Audio sample format
79
+ * @returns Planar version of the format
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * import { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
84
+ *
85
+ * const planar = avGetPlanarSampleFmt(AV_SAMPLE_FMT_FLT); // Returns AV_SAMPLE_FMT_FLTP
86
+ * const same = avGetPlanarSampleFmt(AV_SAMPLE_FMT_FLTP); // Returns AV_SAMPLE_FMT_FLTP
87
+ * ```
88
+ *
89
+ * @see {@link avGetPackedSampleFmt} For getting packed version
79
90
  */
80
91
  export function avGetPlanarSampleFmt(sampleFmt) {
81
92
  return bindings.avGetPlanarSampleFmt(sampleFmt);
82
93
  }
83
94
  /**
84
- * Check if sample format is planar
85
- * Direct mapping to av_sample_fmt_is_planar()
95
+ * Check if sample format is planar.
96
+ *
97
+ * Returns whether the audio sample format stores channels in separate planes
98
+ * (planar) rather than interleaved.
99
+ *
100
+ * Direct mapping to av_sample_fmt_is_planar().
101
+ *
102
+ * @param sampleFmt - Audio sample format to check
103
+ * @returns True if planar, false if packed/interleaved
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P } from 'node-av/constants';
108
+ *
109
+ * const isPacked = avSampleFmtIsPlanar(AV_SAMPLE_FMT_S16); // Returns false
110
+ * const isPlanar = avSampleFmtIsPlanar(AV_SAMPLE_FMT_S16P); // Returns true
111
+ * ```
86
112
  */
87
113
  export function avSampleFmtIsPlanar(sampleFmt) {
88
114
  return bindings.avSampleFmtIsPlanar(sampleFmt);
89
115
  }
90
116
  /**
91
- * Get pixel format name
92
- * Direct mapping to av_get_pix_fmt_name()
117
+ * Get pixel format name.
118
+ *
119
+ * Returns the name of the pixel format as a string.
120
+ *
121
+ * Direct mapping to av_get_pix_fmt_name().
122
+ *
123
+ * @param pixFmt - Pixel format
124
+ * @returns Format name, or null if unknown
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
129
+ *
130
+ * const name1 = avGetPixFmtName(AV_PIX_FMT_YUV420P); // Returns "yuv420p"
131
+ * const name2 = avGetPixFmtName(AV_PIX_FMT_RGB24); // Returns "rgb24"
132
+ * ```
93
133
  */
94
134
  export function avGetPixFmtName(pixFmt) {
95
135
  return bindings.avGetPixFmtName(pixFmt);
96
136
  }
97
137
  /**
98
- * Get pixel format from name
99
- * Direct mapping to av_get_pix_fmt()
138
+ * Get pixel format from name.
139
+ *
140
+ * Returns the pixel format enum value from its string name.
141
+ *
142
+ * Direct mapping to av_get_pix_fmt().
143
+ *
144
+ * @param name - Pixel format name
145
+ * @returns Pixel format enum, or AV_PIX_FMT_NONE if unknown
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const fmt1 = avGetPixFmtFromName("yuv420p"); // Returns AV_PIX_FMT_YUV420P
150
+ * const fmt2 = avGetPixFmtFromName("rgb24"); // Returns AV_PIX_FMT_RGB24
151
+ * const none = avGetPixFmtFromName("invalid"); // Returns AV_PIX_FMT_NONE
152
+ * ```
100
153
  */
101
154
  export function avGetPixFmtFromName(name) {
102
155
  return bindings.avGetPixFmtFromName(name);
103
156
  }
104
157
  /**
105
- * Check if a pixel format is hardware-accelerated
106
- * Direct mapping using av_pix_fmt_desc_get() and AV_PIX_FMT_FLAG_HWACCEL
158
+ * Check if pixel format is hardware accelerated.
159
+ *
160
+ * Returns whether the pixel format represents hardware-accelerated frames
161
+ * (GPU memory) rather than software frames (system memory).
162
+ *
163
+ * Direct mapping to av_pix_fmt_desc_get() with hwaccel check.
164
+ *
165
+ * @param pixFmt - Pixel format to check
166
+ * @returns True if hardware format, false if software format
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_CUDA } from 'node-av/constants';
171
+ *
172
+ * const isSoftware = avIsHardwarePixelFormat(AV_PIX_FMT_YUV420P); // Returns false
173
+ * const isHardware = avIsHardwarePixelFormat(AV_PIX_FMT_CUDA); // Returns true
174
+ * ```
107
175
  */
108
176
  export function avIsHardwarePixelFormat(pixFmt) {
109
177
  return bindings.avIsHardwarePixelFormat(pixFmt);
110
178
  }
111
179
  /**
112
- * Get media type string
113
- * Direct mapping to av_get_media_type_string()
180
+ * Get media type string.
181
+ *
182
+ * Returns a human-readable string for the media type.
183
+ *
184
+ * Direct mapping to av_get_media_type_string().
185
+ *
186
+ * @param mediaType - Media type enum
187
+ * @returns Media type name, or null if unknown
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * import { AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO } from 'node-av/constants';
192
+ *
193
+ * const video = avGetMediaTypeString(AVMEDIA_TYPE_VIDEO); // Returns "video"
194
+ * const audio = avGetMediaTypeString(AVMEDIA_TYPE_AUDIO); // Returns "audio"
195
+ * ```
114
196
  */
115
197
  export function avGetMediaTypeString(mediaType) {
116
198
  return bindings.avGetMediaTypeString(mediaType);
117
199
  }
118
200
  /**
119
- * Allocate an image with size, pixel format and alignment.
201
+ * Allocate image buffer.
120
202
  *
121
- * Allocates a buffer large enough to hold an image with the given parameters.
122
- * The allocated buffer is properly aligned for optimal performance.
203
+ * Allocates a buffer large enough to hold an image with the specified dimensions
204
+ * and pixel format. Returns buffer and layout information.
123
205
  *
124
- * Direct mapping to av_image_alloc()
206
+ * Direct mapping to av_image_alloc().
125
207
  *
126
208
  * @param width - Image width in pixels
127
209
  * @param height - Image height in pixels
128
210
  * @param pixFmt - Pixel format
129
- * @param align - Buffer alignment (1 for no alignment, 32 for SIMD)
211
+ * @param align - Buffer alignment (typically 1 or 32)
212
+ * @returns Object with buffer, size, and line sizes
130
213
  *
131
- * @returns Object containing:
132
- * - buffer: Allocated image buffer
133
- * - size: Total size in bytes
134
- * - linesizes: Array of line sizes for each plane
135
- *
136
- * @throws {Error} If allocation fails
214
+ * @throws {FFmpegError} If allocation fails
137
215
  *
138
216
  * @example
139
217
  * ```typescript
140
- * import { avImageAlloc, AV_PIX_FMT_YUV420P, FFmpegError } from 'node-av';
141
- *
142
- * try {
143
- * const result = avImageAlloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
144
- * console.log(`Allocated ${result.size} bytes`);
145
- * console.log(`Y linesize: ${result.linesizes[0]}`);
146
- * // Use result.buffer for image data
147
- * } catch (error) {
148
- * console.error('Failed to allocate image buffer');
149
- * }
218
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
219
+ *
220
+ * const { buffer, size, linesizes } = avImageAlloc(
221
+ * 1920, 1080, AV_PIX_FMT_YUV420P, 32
222
+ * );
223
+ * console.log(`Allocated ${size} bytes`);
224
+ * console.log(`Line sizes: ${linesizes}`);
150
225
  * ```
151
226
  *
152
- * @see {@link avImageGetBufferSize} To calculate required size without allocating
227
+ * @see {@link avImageGetBufferSize} To calculate size without allocating
153
228
  */
154
229
  export function avImageAlloc(width, height, pixFmt, align) {
155
230
  const result = bindings.avImageAlloc(width, height, pixFmt, align);
@@ -160,86 +235,123 @@ export function avImageAlloc(width, height, pixFmt, align) {
160
235
  return result;
161
236
  }
162
237
  /**
163
- * Copy image data from src to dst
164
- * Direct mapping to av_image_copy2()
238
+ * Copy image data.
239
+ *
240
+ * Copies image data from source to destination buffers.
241
+ *
242
+ * Direct mapping to av_image_copy2().
165
243
  *
166
- * @param dstData - Destination data buffers (one per plane)
167
- * @param dstLinesizes - Destination line sizes
168
- * @param srcData - Source data buffers (one per plane)
169
- * @param srcLinesizes - Source line sizes
244
+ * @param dstData - Destination data planes
245
+ * @param dstLinesizes - Destination bytes per line
246
+ * @param srcData - Source data planes
247
+ * @param srcLinesizes - Source bytes per line
170
248
  * @param pixFmt - Pixel format
171
249
  * @param width - Image width
172
250
  * @param height - Image height
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * avImageCopy2(
255
+ * dstPlanes, dstStrides,
256
+ * srcPlanes, srcStrides,
257
+ * AV_PIX_FMT_YUV420P, 1920, 1080
258
+ * );
259
+ * ```
173
260
  */
174
261
  export function avImageCopy2(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height) {
175
262
  bindings.avImageCopy2(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height);
176
263
  }
177
264
  /**
178
- * Get the required buffer size for an image
179
- * Direct mapping to av_image_get_buffer_size()
265
+ * Get image buffer size.
266
+ *
267
+ * Calculates the required buffer size for an image without allocating.
268
+ *
269
+ * Direct mapping to av_image_get_buffer_size().
270
+ *
271
+ * @param pixFmt - Pixel format
272
+ * @param width - Image width
273
+ * @param height - Image height
274
+ * @param align - Buffer alignment
275
+ * @returns Required buffer size in bytes
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
280
+ *
281
+ * const size = avImageGetBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
282
+ * console.log(`Need ${size} bytes for Full HD RGB24`);
283
+ * ```
180
284
  *
181
- * @returns The required buffer size in bytes, or negative on error
285
+ * @see {@link avImageAlloc} To allocate the buffer
182
286
  */
183
287
  export function avImageGetBufferSize(pixFmt, width, height, align) {
184
288
  return bindings.avImageGetBufferSize(pixFmt, width, height, align);
185
289
  }
186
290
  /**
187
- * Copy image data to a single buffer.
291
+ * Copy image to buffer.
188
292
  *
189
- * Copies image data from separate planes into a single continuous buffer.
190
- * Useful for serialization or when a single buffer is required.
293
+ * Copies image data from separate planes to a single contiguous buffer.
191
294
  *
192
- * Direct mapping to av_image_copy_to_buffer()
295
+ * Direct mapping to av_image_copy_to_buffer().
193
296
  *
194
297
  * @param dst - Destination buffer
195
- * @param dstSize - Size of destination buffer in bytes
196
- * @param srcData - Array of source data planes
197
- * @param srcLinesize - Array of source linesizes
298
+ * @param dstSize - Destination buffer size
299
+ * @param srcData - Source data planes
300
+ * @param srcLinesize - Source bytes per line
198
301
  * @param pixFmt - Pixel format
199
- * @param width - Image width in pixels
200
- * @param height - Image height in pixels
302
+ * @param width - Image width
303
+ * @param height - Image height
201
304
  * @param align - Buffer alignment
202
- *
203
- * @returns Number of bytes written to dst, or negative AVERROR on error:
204
- * - >0: Number of bytes written
205
- * - AVERROR(EINVAL): Invalid parameters
206
- * - AVERROR(ENOMEM): Destination buffer too small
305
+ * @returns Bytes written, or negative AVERROR
207
306
  *
208
307
  * @example
209
308
  * ```typescript
210
- * import { avImageCopyToBuffer, avImageGetBufferSize, FFmpegError } from 'node-av';
211
- * import { AV_PIX_FMT_RGB24 } from 'node-av';
212
- *
213
- * const width = 640, height = 480;
214
- * const pixFmt = AV_PIX_FMT_RGB24;
215
- *
216
- * // Calculate required buffer size
217
- * const dstSize = avImageGetBufferSize(pixFmt, width, height, 1);
218
- * const dst = Buffer.alloc(dstSize);
219
- *
220
- * const ret = avImageCopyToBuffer(
221
- * dst, dstSize,
222
- * srcData, srcLinesize,
223
- * pixFmt, width, height, 1
309
+ * const buffer = Buffer.alloc(bufferSize);
310
+ * const written = avImageCopyToBuffer(
311
+ * buffer, bufferSize,
312
+ * srcPlanes, srcStrides,
313
+ * AV_PIX_FMT_YUV420P, 1920, 1080, 1
224
314
  * );
225
- *
226
- * FFmpegError.throwIfError(ret, 'avImageCopyToBuffer');
227
- * console.log(`Copied ${ret} bytes to buffer`);
228
315
  * ```
229
316
  */
230
317
  export function avImageCopyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align) {
231
318
  return bindings.avImageCopyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align);
232
319
  }
233
320
  /**
234
- * Convert timestamp to string
235
- * Direct mapping to av_ts2str()
321
+ * Convert timestamp to string.
322
+ *
323
+ * Converts a timestamp to a string representation.
324
+ *
325
+ * Direct mapping to av_ts2str().
326
+ *
327
+ * @param ts - Timestamp value
328
+ * @returns String representation
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * const str1 = avTs2Str(1234567n); // Returns "1234567"
333
+ * const str2 = avTs2Str(null); // Returns "NOPTS"
334
+ * ```
236
335
  */
237
336
  export function avTs2Str(ts) {
238
337
  return bindings.avTs2Str(ts);
239
338
  }
240
339
  /**
241
- * Convert timestamp to time string
242
- * Direct mapping to av_ts2timestr()
340
+ * Convert timestamp to time string.
341
+ *
342
+ * Converts a timestamp to a time string using the specified time base.
343
+ *
344
+ * Direct mapping to av_ts2timestr().
345
+ *
346
+ * @param ts - Timestamp value
347
+ * @param timeBase - Time base for conversion
348
+ * @returns Time string representation
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const timeStr = avTs2TimeStr(90000n, { num: 1, den: 90000 }); // Returns "1.000000"
353
+ * const nopts = avTs2TimeStr(null, { num: 1, den: 1000 }); // Returns "NOPTS"
354
+ * ```
243
355
  */
244
356
  export function avTs2TimeStr(ts, timeBase) {
245
357
  if (!timeBase) {
@@ -248,8 +360,23 @@ export function avTs2TimeStr(ts, timeBase) {
248
360
  return bindings.avTs2TimeStr(ts, timeBase);
249
361
  }
250
362
  /**
251
- * Helper to separate image allocation result into separate arrays
252
- * This is useful when you need separate data and linesize arrays
363
+ * Allocate image arrays.
364
+ *
365
+ * Allocates image data as separate plane arrays.
366
+ *
367
+ * @param width - Image width
368
+ * @param height - Image height
369
+ * @param pixFmt - Pixel format
370
+ * @param align - Buffer alignment
371
+ * @returns Object with data planes, line sizes, and total size
372
+ *
373
+ * @example
374
+ * ```typescript
375
+ * const { data, linesizes, size } = avImageAllocArrays(
376
+ * 1920, 1080, AV_PIX_FMT_YUV420P, 32
377
+ * );
378
+ * console.log(`Allocated ${data.length} planes, total ${size} bytes`);
379
+ * ```
253
380
  */
254
381
  export function avImageAllocArrays(width, height, pixFmt, align) {
255
382
  const result = avImageAlloc(width, height, pixFmt, align);
@@ -266,71 +393,124 @@ export function avImageAllocArrays(width, height, pixFmt, align) {
266
393
  };
267
394
  }
268
395
  /**
269
- * Compare two timestamps
270
- * Direct mapping to av_compare_ts()
396
+ * Compare timestamps.
397
+ *
398
+ * Compares two timestamps with different time bases.
399
+ *
400
+ * Direct mapping to av_compare_ts().
271
401
  *
272
- * @returns -1 if tsA < tsB, 0 if tsA == tsB, 1 if tsA > tsB
402
+ * @param tsA - First timestamp
403
+ * @param tbA - First time base
404
+ * @param tsB - Second timestamp
405
+ * @param tbB - Second time base
406
+ * @returns -1 if A < B, 0 if A == B, 1 if A > B
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * const cmp = avCompareTs(
411
+ * 1000n, { num: 1, den: 1000 }, // 1 second
412
+ * 900n, { num: 1, den: 900 } // 1 second
413
+ * );
414
+ * // Returns 0 (equal)
415
+ * ```
273
416
  */
274
417
  export function avCompareTs(tsA, tbA, tsB, tbB) {
275
418
  return bindings.avCompareTs(tsA, tbA, tsB, tbB);
276
419
  }
277
420
  /**
278
- * Rescale a timestamp from one timebase to another
279
- * Direct mapping to av_rescale_q()
421
+ * Rescale timestamp.
422
+ *
423
+ * Rescales a timestamp from one time base to another.
424
+ *
425
+ * Direct mapping to av_rescale_q().
426
+ *
427
+ * @param a - Timestamp to rescale
428
+ * @param bq - Source time base
429
+ * @param cq - Destination time base
430
+ * @returns Rescaled timestamp
431
+ *
432
+ * @example
433
+ * ```typescript
434
+ * // Convert 1 second from 1000Hz to 90kHz
435
+ * const rescaled = avRescaleQ(
436
+ * 1000n,
437
+ * { num: 1, den: 1000 }, // 1000 Hz
438
+ * { num: 1, den: 90000 } // 90 kHz
439
+ * );
440
+ * // Returns 90000n
441
+ * ```
280
442
  */
281
443
  export function avRescaleQ(a, bq, cq) {
282
444
  return bindings.avRescaleQ(a, bq, cq);
283
445
  }
284
446
  /**
285
- * Sleep for a specified number of microseconds.
447
+ * Sleep for microseconds.
286
448
  *
287
- * Provides a cross-platform microsecond sleep function.
288
- * Useful for timing operations or frame pacing.
449
+ * Suspends execution for the specified number of microseconds.
289
450
  *
290
- * Direct mapping to av_usleep()
451
+ * Direct mapping to av_usleep().
291
452
  *
292
- * @param usec - Number of microseconds to sleep
453
+ * @param usec - Microseconds to sleep
293
454
  *
294
455
  * @example
295
456
  * ```typescript
296
- * import { avUsleep } from 'node-av';
297
- *
298
- * // Sleep for 100ms (100,000 microseconds)
299
- * avUsleep(100000);
300
- *
301
- * // Sleep for 1 second
302
- * avUsleep(1000000);
303
- *
304
- * // Frame pacing for 30fps (33.33ms per frame)
305
- * const frameTime = 1000000 / 30;
306
- * avUsleep(frameTime);
457
+ * avUsleep(1000000); // Sleep for 1 second
458
+ * avUsleep(16667); // Sleep for ~16.67ms (60fps frame time)
307
459
  * ```
308
460
  */
309
461
  export function avUsleep(usec) {
310
462
  bindings.avUsleep(usec);
311
463
  }
312
464
  /**
313
- * Rescale a timestamp with rounding
314
- * Direct mapping to av_rescale_rnd()
465
+ * Rescale with rounding.
466
+ *
467
+ * Rescales a value with specified rounding behavior.
468
+ *
469
+ * Direct mapping to av_rescale_rnd().
315
470
  *
316
471
  * @param a - Value to rescale
317
- * @param b - Numerator of scale factor
318
- * @param c - Denominator of scale factor
319
- * @param rnd - Rounding mode (AVRounding enum)
472
+ * @param b - Multiplier
473
+ * @param c - Divisor
474
+ * @param rnd - Rounding mode (AV_ROUND_*)
320
475
  * @returns Rescaled value
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * import { AV_ROUND_NEAR_INF } from 'node-av/constants';
480
+ *
481
+ * const rescaled = avRescaleRnd(1000n, 90000n, 1000n, AV_ROUND_NEAR_INF);
482
+ * // Returns 90000n
483
+ * ```
321
484
  */
322
485
  export function avRescaleRnd(a, b, c, rnd) {
323
486
  return bindings.avRescaleRnd(a, b, c, rnd);
324
487
  }
325
488
  /**
326
- * Allocate audio sample buffers
327
- * Direct mapping to av_samples_alloc()
489
+ * Allocate audio samples buffer.
328
490
  *
329
- * @param nbChannels - Number of channels
491
+ * Allocates buffers for audio samples with the specified format.
492
+ *
493
+ * Direct mapping to av_samples_alloc().
494
+ *
495
+ * @param nbChannels - Number of audio channels
330
496
  * @param nbSamples - Number of samples per channel
331
497
  * @param sampleFmt - Sample format
332
- * @param align - Buffer alignment (0 for default)
333
- * @returns Object with allocated data buffers, linesize and total size, or error code
498
+ * @param align - Buffer alignment
499
+ * @returns Object with data buffers, line size, and total size
500
+ *
501
+ * @throws {FFmpegError} If allocation fails
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
506
+ *
507
+ * const { data, linesize, size } = avSamplesAlloc(
508
+ * 2, 1024, AV_SAMPLE_FMT_FLTP, 0
509
+ * );
510
+ * console.log(`Allocated ${data.length} buffers, ${size} bytes total`);
511
+ * ```
512
+ *
513
+ * @see {@link avSamplesGetBufferSize} To calculate size without allocating
334
514
  */
335
515
  export function avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align) {
336
516
  const result = bindings.avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align);
@@ -340,14 +520,31 @@ export function avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align) {
340
520
  return result;
341
521
  }
342
522
  /**
343
- * Get the required buffer size for audio samples
344
- * Direct mapping to av_samples_get_buffer_size()
523
+ * Get audio samples buffer size.
524
+ *
525
+ * Calculates the required buffer size for audio samples.
526
+ *
527
+ * Direct mapping to av_samples_get_buffer_size().
345
528
  *
346
529
  * @param nbChannels - Number of channels
347
530
  * @param nbSamples - Number of samples per channel
348
531
  * @param sampleFmt - Sample format
349
- * @param align - Buffer alignment (0 for default)
350
- * @returns Object with size and linesize, or error code
532
+ * @param align - Buffer alignment
533
+ * @returns Object with size and line size
534
+ *
535
+ * @throws {FFmpegError} If parameters are invalid
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
540
+ *
541
+ * const { size, linesize } = avSamplesGetBufferSize(
542
+ * 2, 1024, AV_SAMPLE_FMT_S16, 0
543
+ * );
544
+ * console.log(`Need ${size} bytes, ${linesize} per channel`);
545
+ * ```
546
+ *
547
+ * @see {@link avSamplesAlloc} To allocate the buffer
351
548
  */
352
549
  export function avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align) {
353
550
  const result = bindings.avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align);
@@ -357,47 +554,41 @@ export function avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align)
357
554
  return result;
358
555
  }
359
556
  /**
360
- * Get a string description of a channel layout.
361
- * Direct mapping to av_channel_layout_describe()
557
+ * Describe channel layout.
362
558
  *
363
- * @param channelLayout - The channel layout object with order, nbChannels, and mask
364
- * @returns String description of the channel layout, or null if invalid
559
+ * Returns a human-readable description of a channel layout.
560
+ *
561
+ * Direct mapping to av_channel_layout_describe().
562
+ *
563
+ * @param channelLayout - Channel layout to describe
564
+ * @returns Layout description string, or null
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * const stereo = { nbChannels: 2, order: 1, u: { mask: 3n } };
569
+ * const desc = avChannelLayoutDescribe(stereo); // Returns "stereo"
570
+ * ```
365
571
  */
366
572
  export function avChannelLayoutDescribe(channelLayout) {
367
573
  return bindings.avChannelLayoutDescribe(channelLayout);
368
574
  }
369
575
  /**
370
- * Create an SDP (Session Description Protocol) string for RTP/RTSP streaming.
576
+ * Create SDP from format contexts.
371
577
  *
372
- * Generates an SDP description from one or more FormatContext objects.
373
- * Useful for RTP/RTSP streaming scenarios where you need to describe
374
- * the media streams to clients.
578
+ * Creates an SDP (Session Description Protocol) string from format contexts.
579
+ * Used for RTP/RTSP streaming.
375
580
  *
376
- * Direct mapping to av_sdp_create()
581
+ * Direct mapping to av_sdp_create().
377
582
  *
378
- * @param contexts - Array of FormatContext objects to describe
379
- * @returns SDP string on success, or null on failure
380
- *
381
- * @throws {FFmpegError} On invalid parameters or SDP creation failure
583
+ * @param contexts - Array of format contexts
584
+ * @returns SDP string, or null on error
382
585
  *
383
586
  * @example
384
587
  * ```typescript
385
- * import { avSdpCreate, FormatContext, FFmpegError } from 'node-av';
386
- *
387
- * // Create format contexts for RTP output
388
- * const contexts: FormatContext[] = [];
389
- *
390
- * const ctx = new FormatContext();
391
- * // ... configure context for RTP output ...
392
- * contexts.push(ctx);
393
- *
394
- * // Generate SDP
395
- * const sdp = avSdpCreate(contexts);
588
+ * const sdp = avSdpCreate([outputContext]);
396
589
  * if (sdp) {
397
- * console.log('SDP:', result);
590
+ * console.log('SDP:\n' + sdp);
398
591
  * }
399
- *
400
- * // Use the SDP string for RTSP server or save to .sdp file
401
592
  * ```
402
593
  */
403
594
  export function avSdpCreate(contexts) {