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