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