node-av 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio Sample Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with audio sample buffers in FFmpeg.
|
|
5
|
+
* All methods are static and map directly to FFmpeg's libavutil functions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audio-sample-utils
|
|
8
|
+
*/
|
|
9
|
+
import { bindings } from '../../lib/binding.js';
|
|
10
|
+
import { FFmpegError } from '../../lib/error.js';
|
|
11
|
+
/**
|
|
12
|
+
* Audio sample buffer utilities.
|
|
13
|
+
*
|
|
14
|
+
* Provides static methods for allocating and managing audio sample buffers.
|
|
15
|
+
* These utilities handle the memory layout for various sample formats,
|
|
16
|
+
* including planar formats where each channel has its own buffer.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { AudioSampleUtils } from 'node-av';
|
|
21
|
+
* import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
22
|
+
*
|
|
23
|
+
* // Allocate audio buffers for stereo float planar
|
|
24
|
+
* const audio = AudioSampleUtils.alloc(2, 1024, AV_SAMPLE_FMT_FLTP, 0);
|
|
25
|
+
* console.log(`Allocated ${audio.size} bytes`);
|
|
26
|
+
* console.log(`${audio.data.length} buffers (one per channel)`);
|
|
27
|
+
*
|
|
28
|
+
* // Get buffer size for packed format
|
|
29
|
+
* const size = AudioSampleUtils.getBufferSize(2, 1024, AV_SAMPLE_FMT_S16, 0);
|
|
30
|
+
* console.log(`S16 stereo needs ${size.size} bytes`);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class AudioSampleUtils {
|
|
34
|
+
// Private constructor to prevent instantiation
|
|
35
|
+
constructor() { }
|
|
36
|
+
/**
|
|
37
|
+
* Allocate audio sample buffers.
|
|
38
|
+
*
|
|
39
|
+
* Allocates buffers for audio samples. For planar formats, allocates
|
|
40
|
+
* separate buffers for each channel. For packed formats, allocates
|
|
41
|
+
* a single interleaved buffer.
|
|
42
|
+
* Direct mapping to av_samples_alloc()
|
|
43
|
+
*
|
|
44
|
+
* @param nbChannels - Number of audio channels
|
|
45
|
+
* @param nbSamples - Number of samples per channel
|
|
46
|
+
* @param sampleFmt - Audio sample format
|
|
47
|
+
* @param align - Buffer alignment (0 for default)
|
|
48
|
+
* @returns Allocation result with buffers and size information
|
|
49
|
+
* @throws {FFmpegError} On allocation failure
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { AudioSampleUtils } from 'node-av';
|
|
54
|
+
* import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
55
|
+
*
|
|
56
|
+
* // Allocate for planar format (separate buffer per channel)
|
|
57
|
+
* const planar = AudioSampleUtils.alloc(2, 1024, AV_SAMPLE_FMT_FLTP, 0);
|
|
58
|
+
* console.log(`Planar: ${planar.data.length} buffers`); // 2 buffers
|
|
59
|
+
*
|
|
60
|
+
* // Allocate for packed format (single interleaved buffer)
|
|
61
|
+
* const packed = AudioSampleUtils.alloc(2, 1024, AV_SAMPLE_FMT_S16, 0);
|
|
62
|
+
* console.log(`Packed: ${packed.data.length} buffer`); // 1 buffer
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
static alloc(nbChannels, nbSamples, sampleFmt, align) {
|
|
66
|
+
const result = bindings.avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align);
|
|
67
|
+
if (typeof result === 'number') {
|
|
68
|
+
FFmpegError.throwIfError(result, 'Failed to allocate audio samples');
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get required buffer size for audio samples.
|
|
74
|
+
*
|
|
75
|
+
* Calculates the buffer size needed to store audio samples with the
|
|
76
|
+
* given parameters. Does not allocate any memory.
|
|
77
|
+
* Direct mapping to av_samples_get_buffer_size()
|
|
78
|
+
*
|
|
79
|
+
* @param nbChannels - Number of audio channels
|
|
80
|
+
* @param nbSamples - Number of samples per channel
|
|
81
|
+
* @param sampleFmt - Audio sample format
|
|
82
|
+
* @param align - Buffer alignment (0 for default)
|
|
83
|
+
* @returns Buffer size and line size information
|
|
84
|
+
* @throws {FFmpegError} On invalid parameters
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { AudioSampleUtils } from 'node-av';
|
|
89
|
+
* import { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P } from 'node-av/constants';
|
|
90
|
+
*
|
|
91
|
+
* // Calculate size for packed float (32-bit) stereo
|
|
92
|
+
* const floatSize = AudioSampleUtils.getBufferSize(2, 1024, AV_SAMPLE_FMT_FLT, 0);
|
|
93
|
+
* console.log(`Float stereo: ${floatSize.size} bytes total`);
|
|
94
|
+
* console.log(`Line size: ${floatSize.linesize} bytes`);
|
|
95
|
+
*
|
|
96
|
+
* // Calculate size for planar 16-bit stereo
|
|
97
|
+
* const planarSize = AudioSampleUtils.getBufferSize(2, 1024, AV_SAMPLE_FMT_S16P, 0);
|
|
98
|
+
* console.log(`S16 planar: ${planarSize.size} bytes total`);
|
|
99
|
+
* console.log(`Per channel: ${planarSize.linesize} bytes`);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
static getBufferSize(nbChannels, nbSamples, sampleFmt, align) {
|
|
103
|
+
const result = bindings.avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align);
|
|
104
|
+
if (typeof result === 'number') {
|
|
105
|
+
FFmpegError.throwIfError(result, 'Failed to get audio buffer size');
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=audio-sample.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio-sample.js","sourceRoot":"","sources":["../../../src/api/utilities/audio-sample.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA0BjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,KAAK,CAAC,UAAkB,EAAE,SAAiB,EAAE,SAAyB,EAAE,KAAa;QAC1F,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAChF,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,MAA+B,CAAC;IACzC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,aAAa,CAAC,UAAkB,EAAE,SAAiB,EAAE,SAAyB,EAAE,KAAa;QAClG,MAAM,MAAM,GAAG,QAAQ,CAAC,sBAAsB,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QACxF,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,MAA+B,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel Layout Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with audio channel layouts in FFmpeg.
|
|
5
|
+
* All methods are static and map directly to FFmpeg's libavutil functions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/channel-layout-utils
|
|
8
|
+
*/
|
|
9
|
+
import type { ChannelLayout } from '../../lib/types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Audio channel layout utilities.
|
|
12
|
+
*
|
|
13
|
+
* Provides static methods for describing and working with audio channel layouts.
|
|
14
|
+
* Channel layouts define the arrangement and meaning of audio channels in
|
|
15
|
+
* multi-channel audio.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { ChannelLayoutUtils } from 'node-av';
|
|
20
|
+
* import { AV_CHANNEL_ORDER_NATIVE } from 'node-av/constants';
|
|
21
|
+
*
|
|
22
|
+
* // Describe a stereo layout
|
|
23
|
+
* const stereo: ChannelLayout = {
|
|
24
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
25
|
+
* nb_channels: 2,
|
|
26
|
+
* u: { mask: 0x3n } // FL | FR
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* const description = ChannelLayoutUtils.describe(stereo);
|
|
30
|
+
* console.log(description); // "stereo"
|
|
31
|
+
*
|
|
32
|
+
* // Describe a 5.1 layout
|
|
33
|
+
* const surround: ChannelLayout = {
|
|
34
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
35
|
+
* nb_channels: 6,
|
|
36
|
+
* u: { mask: 0x3Fn } // FL | FR | FC | LFE | BL | BR
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* console.log(ChannelLayoutUtils.describe(surround)); // "5.1"
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class ChannelLayoutUtils {
|
|
43
|
+
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Get string description of channel layout.
|
|
46
|
+
*
|
|
47
|
+
* Returns a human-readable string describing the channel layout.
|
|
48
|
+
* Direct mapping to av_channel_layout_describe()
|
|
49
|
+
*
|
|
50
|
+
* @param channelLayout - Channel layout to describe
|
|
51
|
+
* @returns String description, or null on error
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { ChannelLayoutUtils } from 'node-av';
|
|
56
|
+
* import { AV_CHANNEL_ORDER_NATIVE, AV_CHANNEL_ORDER_CUSTOM } from 'node-av/constants';
|
|
57
|
+
*
|
|
58
|
+
* // Standard layouts
|
|
59
|
+
* const mono: ChannelLayout = {
|
|
60
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
61
|
+
* nb_channels: 1,
|
|
62
|
+
* u: { mask: 0x4n } // FC
|
|
63
|
+
* };
|
|
64
|
+
* console.log(ChannelLayoutUtils.describe(mono)); // "mono"
|
|
65
|
+
*
|
|
66
|
+
* const stereo: ChannelLayout = {
|
|
67
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
68
|
+
* nb_channels: 2,
|
|
69
|
+
* u: { mask: 0x3n } // FL | FR
|
|
70
|
+
* };
|
|
71
|
+
* console.log(ChannelLayoutUtils.describe(stereo)); // "stereo"
|
|
72
|
+
*
|
|
73
|
+
* // Custom layout
|
|
74
|
+
* const custom: ChannelLayout = {
|
|
75
|
+
* order: AV_CHANNEL_ORDER_CUSTOM,
|
|
76
|
+
* nb_channels: 3,
|
|
77
|
+
* u: { map: null }
|
|
78
|
+
* };
|
|
79
|
+
* console.log(ChannelLayoutUtils.describe(custom)); // "3 channels"
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static describe(channelLayout: Partial<ChannelLayout>): string | null;
|
|
83
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel Layout Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with audio channel layouts in FFmpeg.
|
|
5
|
+
* All methods are static and map directly to FFmpeg's libavutil functions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/channel-layout-utils
|
|
8
|
+
*/
|
|
9
|
+
import { bindings } from '../../lib/binding.js';
|
|
10
|
+
/**
|
|
11
|
+
* Audio channel layout utilities.
|
|
12
|
+
*
|
|
13
|
+
* Provides static methods for describing and working with audio channel layouts.
|
|
14
|
+
* Channel layouts define the arrangement and meaning of audio channels in
|
|
15
|
+
* multi-channel audio.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { ChannelLayoutUtils } from 'node-av';
|
|
20
|
+
* import { AV_CHANNEL_ORDER_NATIVE } from 'node-av/constants';
|
|
21
|
+
*
|
|
22
|
+
* // Describe a stereo layout
|
|
23
|
+
* const stereo: ChannelLayout = {
|
|
24
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
25
|
+
* nb_channels: 2,
|
|
26
|
+
* u: { mask: 0x3n } // FL | FR
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* const description = ChannelLayoutUtils.describe(stereo);
|
|
30
|
+
* console.log(description); // "stereo"
|
|
31
|
+
*
|
|
32
|
+
* // Describe a 5.1 layout
|
|
33
|
+
* const surround: ChannelLayout = {
|
|
34
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
35
|
+
* nb_channels: 6,
|
|
36
|
+
* u: { mask: 0x3Fn } // FL | FR | FC | LFE | BL | BR
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* console.log(ChannelLayoutUtils.describe(surround)); // "5.1"
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class ChannelLayoutUtils {
|
|
43
|
+
// Private constructor to prevent instantiation
|
|
44
|
+
constructor() { }
|
|
45
|
+
/**
|
|
46
|
+
* Get string description of channel layout.
|
|
47
|
+
*
|
|
48
|
+
* Returns a human-readable string describing the channel layout.
|
|
49
|
+
* Direct mapping to av_channel_layout_describe()
|
|
50
|
+
*
|
|
51
|
+
* @param channelLayout - Channel layout to describe
|
|
52
|
+
* @returns String description, or null on error
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { ChannelLayoutUtils } from 'node-av';
|
|
57
|
+
* import { AV_CHANNEL_ORDER_NATIVE, AV_CHANNEL_ORDER_CUSTOM } from 'node-av/constants';
|
|
58
|
+
*
|
|
59
|
+
* // Standard layouts
|
|
60
|
+
* const mono: ChannelLayout = {
|
|
61
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
62
|
+
* nb_channels: 1,
|
|
63
|
+
* u: { mask: 0x4n } // FC
|
|
64
|
+
* };
|
|
65
|
+
* console.log(ChannelLayoutUtils.describe(mono)); // "mono"
|
|
66
|
+
*
|
|
67
|
+
* const stereo: ChannelLayout = {
|
|
68
|
+
* order: AV_CHANNEL_ORDER_NATIVE,
|
|
69
|
+
* nb_channels: 2,
|
|
70
|
+
* u: { mask: 0x3n } // FL | FR
|
|
71
|
+
* };
|
|
72
|
+
* console.log(ChannelLayoutUtils.describe(stereo)); // "stereo"
|
|
73
|
+
*
|
|
74
|
+
* // Custom layout
|
|
75
|
+
* const custom: ChannelLayout = {
|
|
76
|
+
* order: AV_CHANNEL_ORDER_CUSTOM,
|
|
77
|
+
* nb_channels: 3,
|
|
78
|
+
* u: { map: null }
|
|
79
|
+
* };
|
|
80
|
+
* console.log(ChannelLayoutUtils.describe(custom)); // "3 channels"
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static describe(channelLayout) {
|
|
84
|
+
return bindings.avChannelLayoutDescribe(channelLayout);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=channel-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-layout.js","sourceRoot":"","sources":["../../../src/api/utilities/channel-layout.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,kBAAkB;IAC7B,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAqC;QACnD,OAAO,QAAQ,CAAC,uBAAuB,CAAC,aAAa,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with image buffers in FFmpeg.
|
|
5
|
+
* All methods are static and map directly to FFmpeg's libavutil functions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/image-utils
|
|
8
|
+
*/
|
|
9
|
+
import type { AVPixelFormat } from '../../lib/constants.js';
|
|
10
|
+
/**
|
|
11
|
+
* Image buffer allocation result.
|
|
12
|
+
*/
|
|
13
|
+
export interface ImageAllocation {
|
|
14
|
+
/** Allocated buffer containing the image data */
|
|
15
|
+
buffer: Buffer;
|
|
16
|
+
/** Total size in bytes */
|
|
17
|
+
size: number;
|
|
18
|
+
/** Line sizes for each plane */
|
|
19
|
+
linesizes: number[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Image buffer utilities.
|
|
23
|
+
*
|
|
24
|
+
* Provides static methods for allocating, copying, and managing image buffers.
|
|
25
|
+
* These utilities handle the low-level memory layout for various pixel formats,
|
|
26
|
+
* including planar formats with multiple buffers.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { ImageUtils } from 'node-av';
|
|
31
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
|
|
32
|
+
*
|
|
33
|
+
* // Allocate image buffer
|
|
34
|
+
* const image = ImageUtils.alloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
|
|
35
|
+
* console.log(`Allocated ${image.size} bytes`);
|
|
36
|
+
*
|
|
37
|
+
* // Get buffer size without allocating
|
|
38
|
+
* const size = ImageUtils.getBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
|
|
39
|
+
* console.log(`RGB24 1080p needs ${size} bytes`);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class ImageUtils {
|
|
43
|
+
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Allocate an image buffer.
|
|
46
|
+
*
|
|
47
|
+
* Allocates a buffer large enough to hold an image with the specified dimensions
|
|
48
|
+
* and pixel format. Returns the buffer along with line sizes for each plane.
|
|
49
|
+
* Direct mapping to av_image_alloc()
|
|
50
|
+
*
|
|
51
|
+
* @param width - Image width in pixels
|
|
52
|
+
* @param height - Image height in pixels
|
|
53
|
+
* @param pixFmt - Pixel format
|
|
54
|
+
* @param align - Buffer alignment (typically 1, 16, or 32)
|
|
55
|
+
* @returns Allocation result with buffer, size, and line sizes
|
|
56
|
+
* @throws {FFmpegError} On allocation failure
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { ImageUtils } from 'node-av';
|
|
61
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
62
|
+
*
|
|
63
|
+
* // Allocate aligned buffer for YUV420P image
|
|
64
|
+
* const image = ImageUtils.alloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
|
|
65
|
+
* console.log(`Buffer size: ${image.size} bytes`);
|
|
66
|
+
* console.log(`Y plane line size: ${image.linesizes[0]}`);
|
|
67
|
+
* console.log(`U plane line size: ${image.linesizes[1]}`);
|
|
68
|
+
* console.log(`V plane line size: ${image.linesizes[2]}`);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
static alloc(width: number, height: number, pixFmt: AVPixelFormat, align: number): ImageAllocation;
|
|
72
|
+
/**
|
|
73
|
+
* Allocate image buffer arrays (alternative interface).
|
|
74
|
+
*
|
|
75
|
+
* Similar to alloc() but with a different return format.
|
|
76
|
+
* This is an alias for compatibility.
|
|
77
|
+
*
|
|
78
|
+
* @param width - Image width in pixels
|
|
79
|
+
* @param height - Image height in pixels
|
|
80
|
+
* @param pixFmt - Pixel format
|
|
81
|
+
* @param align - Buffer alignment
|
|
82
|
+
* @returns Allocation result
|
|
83
|
+
* @throws {FFmpegError} On allocation failure
|
|
84
|
+
*/
|
|
85
|
+
static allocArrays(width: number, height: number, pixFmt: AVPixelFormat, align: number): ImageAllocation;
|
|
86
|
+
/**
|
|
87
|
+
* Copy image data between buffers.
|
|
88
|
+
*
|
|
89
|
+
* Copies image data from source buffers to destination buffers.
|
|
90
|
+
* Direct mapping to av_image_copy2()
|
|
91
|
+
*
|
|
92
|
+
* @param dstData - Destination data buffers (one per plane)
|
|
93
|
+
* @param dstLinesizes - Destination line sizes
|
|
94
|
+
* @param srcData - Source data buffers (one per plane)
|
|
95
|
+
* @param srcLinesizes - Source line sizes
|
|
96
|
+
* @param pixFmt - Pixel format
|
|
97
|
+
* @param width - Image width
|
|
98
|
+
* @param height - Image height
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* import { ImageUtils } from 'node-av';
|
|
103
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
104
|
+
*
|
|
105
|
+
* // Copy between two image buffers
|
|
106
|
+
* ImageUtils.copy(
|
|
107
|
+
* dstBuffers, dstLinesizes,
|
|
108
|
+
* srcBuffers, srcLinesizes,
|
|
109
|
+
* AV_PIX_FMT_YUV420P, 1920, 1080
|
|
110
|
+
* );
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static copy(dstData: Buffer[], dstLinesizes: number[], srcData: Buffer[], srcLinesizes: number[], pixFmt: AVPixelFormat, width: number, height: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Get required buffer size for an image.
|
|
116
|
+
*
|
|
117
|
+
* Calculates the buffer size needed to store an image with the given parameters.
|
|
118
|
+
* Direct mapping to av_image_get_buffer_size()
|
|
119
|
+
*
|
|
120
|
+
* @param pixFmt - Pixel format
|
|
121
|
+
* @param width - Image width
|
|
122
|
+
* @param height - Image height
|
|
123
|
+
* @param align - Buffer alignment
|
|
124
|
+
* @returns Required buffer size in bytes
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { ImageUtils } from 'node-av';
|
|
129
|
+
* import { AV_PIX_FMT_RGB24, AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
130
|
+
*
|
|
131
|
+
* // Calculate buffer sizes for different formats
|
|
132
|
+
* const rgbSize = ImageUtils.getBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
|
|
133
|
+
* const yuvSize = ImageUtils.getBufferSize(AV_PIX_FMT_YUV420P, 1920, 1080, 1);
|
|
134
|
+
*
|
|
135
|
+
* console.log(`RGB24: ${rgbSize} bytes`); // 1920*1080*3
|
|
136
|
+
* console.log(`YUV420P: ${yuvSize} bytes`); // 1920*1080*1.5
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
static getBufferSize(pixFmt: AVPixelFormat, width: number, height: number, align: number): number;
|
|
140
|
+
/**
|
|
141
|
+
* Copy image to a single buffer.
|
|
142
|
+
*
|
|
143
|
+
* Copies image data from multiple plane buffers to a single contiguous buffer.
|
|
144
|
+
* Useful for serialization or when a single buffer is required.
|
|
145
|
+
* Direct mapping to av_image_copy_to_buffer()
|
|
146
|
+
*
|
|
147
|
+
* @param dst - Destination buffer
|
|
148
|
+
* @param dstSize - Destination buffer size
|
|
149
|
+
* @param srcData - Source data buffers (one per plane), or null
|
|
150
|
+
* @param srcLinesize - Source line sizes, or null
|
|
151
|
+
* @param pixFmt - Pixel format
|
|
152
|
+
* @param width - Image width
|
|
153
|
+
* @param height - Image height
|
|
154
|
+
* @param align - Buffer alignment
|
|
155
|
+
* @returns Bytes written, or negative error code
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* import { ImageUtils, FFmpegError } from 'node-av';
|
|
160
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
161
|
+
*
|
|
162
|
+
* // Copy planar data to single buffer
|
|
163
|
+
* const dstSize = ImageUtils.getBufferSize(AV_PIX_FMT_YUV420P, 1920, 1080, 1);
|
|
164
|
+
* const dst = Buffer.alloc(dstSize);
|
|
165
|
+
*
|
|
166
|
+
* const written = ImageUtils.copyToBuffer(
|
|
167
|
+
* dst, dstSize,
|
|
168
|
+
* srcBuffers, srcLinesizes,
|
|
169
|
+
* AV_PIX_FMT_YUV420P, 1920, 1080, 1
|
|
170
|
+
* );
|
|
171
|
+
*
|
|
172
|
+
* FFmpegError.throwIfError(written, 'Failed to copy image to buffer');
|
|
173
|
+
* console.log(`Wrote ${written} bytes`);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
static copyToBuffer(dst: Buffer, dstSize: number, srcData: Buffer[] | null, srcLinesize: number[] | null, pixFmt: AVPixelFormat, width: number, height: number, align: number): number;
|
|
177
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with image buffers in FFmpeg.
|
|
5
|
+
* All methods are static and map directly to FFmpeg's libavutil functions.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/image-utils
|
|
8
|
+
*/
|
|
9
|
+
import { bindings } from '../../lib/binding.js';
|
|
10
|
+
import { FFmpegError } from '../../lib/error.js';
|
|
11
|
+
/**
|
|
12
|
+
* Image buffer utilities.
|
|
13
|
+
*
|
|
14
|
+
* Provides static methods for allocating, copying, and managing image buffers.
|
|
15
|
+
* These utilities handle the low-level memory layout for various pixel formats,
|
|
16
|
+
* including planar formats with multiple buffers.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { ImageUtils } from 'node-av';
|
|
21
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
|
|
22
|
+
*
|
|
23
|
+
* // Allocate image buffer
|
|
24
|
+
* const image = ImageUtils.alloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
|
|
25
|
+
* console.log(`Allocated ${image.size} bytes`);
|
|
26
|
+
*
|
|
27
|
+
* // Get buffer size without allocating
|
|
28
|
+
* const size = ImageUtils.getBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
|
|
29
|
+
* console.log(`RGB24 1080p needs ${size} bytes`);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class ImageUtils {
|
|
33
|
+
// Private constructor to prevent instantiation
|
|
34
|
+
constructor() { }
|
|
35
|
+
/**
|
|
36
|
+
* Allocate an image buffer.
|
|
37
|
+
*
|
|
38
|
+
* Allocates a buffer large enough to hold an image with the specified dimensions
|
|
39
|
+
* and pixel format. Returns the buffer along with line sizes for each plane.
|
|
40
|
+
* Direct mapping to av_image_alloc()
|
|
41
|
+
*
|
|
42
|
+
* @param width - Image width in pixels
|
|
43
|
+
* @param height - Image height in pixels
|
|
44
|
+
* @param pixFmt - Pixel format
|
|
45
|
+
* @param align - Buffer alignment (typically 1, 16, or 32)
|
|
46
|
+
* @returns Allocation result with buffer, size, and line sizes
|
|
47
|
+
* @throws {FFmpegError} On allocation failure
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { ImageUtils } from 'node-av';
|
|
52
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
53
|
+
*
|
|
54
|
+
* // Allocate aligned buffer for YUV420P image
|
|
55
|
+
* const image = ImageUtils.alloc(1920, 1080, AV_PIX_FMT_YUV420P, 32);
|
|
56
|
+
* console.log(`Buffer size: ${image.size} bytes`);
|
|
57
|
+
* console.log(`Y plane line size: ${image.linesizes[0]}`);
|
|
58
|
+
* console.log(`U plane line size: ${image.linesizes[1]}`);
|
|
59
|
+
* console.log(`V plane line size: ${image.linesizes[2]}`);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
static alloc(width, height, pixFmt, align) {
|
|
63
|
+
const result = bindings.avImageAlloc(width, height, pixFmt, align);
|
|
64
|
+
if (typeof result === 'number') {
|
|
65
|
+
FFmpegError.throwIfError(result, 'Failed to allocate image');
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Allocate image buffer arrays (alternative interface).
|
|
71
|
+
*
|
|
72
|
+
* Similar to alloc() but with a different return format.
|
|
73
|
+
* This is an alias for compatibility.
|
|
74
|
+
*
|
|
75
|
+
* @param width - Image width in pixels
|
|
76
|
+
* @param height - Image height in pixels
|
|
77
|
+
* @param pixFmt - Pixel format
|
|
78
|
+
* @param align - Buffer alignment
|
|
79
|
+
* @returns Allocation result
|
|
80
|
+
* @throws {FFmpegError} On allocation failure
|
|
81
|
+
*/
|
|
82
|
+
static allocArrays(width, height, pixFmt, align) {
|
|
83
|
+
return ImageUtils.alloc(width, height, pixFmt, align);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Copy image data between buffers.
|
|
87
|
+
*
|
|
88
|
+
* Copies image data from source buffers to destination buffers.
|
|
89
|
+
* Direct mapping to av_image_copy2()
|
|
90
|
+
*
|
|
91
|
+
* @param dstData - Destination data buffers (one per plane)
|
|
92
|
+
* @param dstLinesizes - Destination line sizes
|
|
93
|
+
* @param srcData - Source data buffers (one per plane)
|
|
94
|
+
* @param srcLinesizes - Source line sizes
|
|
95
|
+
* @param pixFmt - Pixel format
|
|
96
|
+
* @param width - Image width
|
|
97
|
+
* @param height - Image height
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { ImageUtils } from 'node-av';
|
|
102
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
103
|
+
*
|
|
104
|
+
* // Copy between two image buffers
|
|
105
|
+
* ImageUtils.copy(
|
|
106
|
+
* dstBuffers, dstLinesizes,
|
|
107
|
+
* srcBuffers, srcLinesizes,
|
|
108
|
+
* AV_PIX_FMT_YUV420P, 1920, 1080
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
static copy(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height) {
|
|
113
|
+
bindings.avImageCopy2(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get required buffer size for an image.
|
|
117
|
+
*
|
|
118
|
+
* Calculates the buffer size needed to store an image with the given parameters.
|
|
119
|
+
* Direct mapping to av_image_get_buffer_size()
|
|
120
|
+
*
|
|
121
|
+
* @param pixFmt - Pixel format
|
|
122
|
+
* @param width - Image width
|
|
123
|
+
* @param height - Image height
|
|
124
|
+
* @param align - Buffer alignment
|
|
125
|
+
* @returns Required buffer size in bytes
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* import { ImageUtils } from 'node-av';
|
|
130
|
+
* import { AV_PIX_FMT_RGB24, AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
131
|
+
*
|
|
132
|
+
* // Calculate buffer sizes for different formats
|
|
133
|
+
* const rgbSize = ImageUtils.getBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
|
|
134
|
+
* const yuvSize = ImageUtils.getBufferSize(AV_PIX_FMT_YUV420P, 1920, 1080, 1);
|
|
135
|
+
*
|
|
136
|
+
* console.log(`RGB24: ${rgbSize} bytes`); // 1920*1080*3
|
|
137
|
+
* console.log(`YUV420P: ${yuvSize} bytes`); // 1920*1080*1.5
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
static getBufferSize(pixFmt, width, height, align) {
|
|
141
|
+
return bindings.avImageGetBufferSize(pixFmt, width, height, align);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Copy image to a single buffer.
|
|
145
|
+
*
|
|
146
|
+
* Copies image data from multiple plane buffers to a single contiguous buffer.
|
|
147
|
+
* Useful for serialization or when a single buffer is required.
|
|
148
|
+
* Direct mapping to av_image_copy_to_buffer()
|
|
149
|
+
*
|
|
150
|
+
* @param dst - Destination buffer
|
|
151
|
+
* @param dstSize - Destination buffer size
|
|
152
|
+
* @param srcData - Source data buffers (one per plane), or null
|
|
153
|
+
* @param srcLinesize - Source line sizes, or null
|
|
154
|
+
* @param pixFmt - Pixel format
|
|
155
|
+
* @param width - Image width
|
|
156
|
+
* @param height - Image height
|
|
157
|
+
* @param align - Buffer alignment
|
|
158
|
+
* @returns Bytes written, or negative error code
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* import { ImageUtils, FFmpegError } from 'node-av';
|
|
163
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
164
|
+
*
|
|
165
|
+
* // Copy planar data to single buffer
|
|
166
|
+
* const dstSize = ImageUtils.getBufferSize(AV_PIX_FMT_YUV420P, 1920, 1080, 1);
|
|
167
|
+
* const dst = Buffer.alloc(dstSize);
|
|
168
|
+
*
|
|
169
|
+
* const written = ImageUtils.copyToBuffer(
|
|
170
|
+
* dst, dstSize,
|
|
171
|
+
* srcBuffers, srcLinesizes,
|
|
172
|
+
* AV_PIX_FMT_YUV420P, 1920, 1080, 1
|
|
173
|
+
* );
|
|
174
|
+
*
|
|
175
|
+
* FFmpegError.throwIfError(written, 'Failed to copy image to buffer');
|
|
176
|
+
* console.log(`Wrote ${written} bytes`);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
static copyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align) {
|
|
180
|
+
return bindings.avImageCopyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/api/utilities/image.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgBjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,UAAU;IACrB,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,MAAc,EAAE,MAAqB,EAAE,KAAa;QAC9E,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QACnE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,MAAyB,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,WAAW,CAAC,KAAa,EAAE,MAAc,EAAE,MAAqB,EAAE,KAAa;QACpF,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,IAAI,CAAC,OAAiB,EAAE,YAAsB,EAAE,OAAiB,EAAE,YAAsB,EAAE,MAAqB,EAAE,KAAa,EAAE,MAAc;QACpJ,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7F,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,aAAa,CAAC,MAAqB,EAAE,KAAa,EAAE,MAAc,EAAE,KAAa;QACtF,OAAO,QAAQ,CAAC,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,MAAM,CAAC,YAAY,CACjB,GAAW,EACX,OAAe,EACf,OAAwB,EACxB,WAA4B,EAC5B,MAAqB,EACrB,KAAa,EACb,MAAc,EACd,KAAa;QAEb,OAAO,QAAQ,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACxG,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AudioSampleUtils, type AudioSampleAllocation, type AudioSampleBufferSize } from './audio-sample.js';
|
|
2
|
+
export { ChannelLayoutUtils } from './channel-layout.js';
|
|
3
|
+
export { ImageUtils, type ImageAllocation } from './image.js';
|
|
4
|
+
export { MediaType } from './media-type.js';
|
|
5
|
+
export { PixelFormat } from './pixel-format.js';
|
|
6
|
+
export { SampleFormat } from './sample-format.js';
|
|
7
|
+
export { TimestampUtils } from './timestamp.js';
|
|
8
|
+
export { StreamingUtils } from './streaming.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Audio
|
|
2
|
+
export { AudioSampleUtils } from './audio-sample.js';
|
|
3
|
+
// Channel Layouts
|
|
4
|
+
export { ChannelLayoutUtils } from './channel-layout.js';
|
|
5
|
+
// Image
|
|
6
|
+
export { ImageUtils } from './image.js';
|
|
7
|
+
// Media
|
|
8
|
+
export { MediaType } from './media-type.js';
|
|
9
|
+
// Pixel Format
|
|
10
|
+
export { PixelFormat } from './pixel-format.js';
|
|
11
|
+
// Sample Format
|
|
12
|
+
export { SampleFormat } from './sample-format.js';
|
|
13
|
+
// Timestamp
|
|
14
|
+
export { TimestampUtils } from './timestamp.js';
|
|
15
|
+
// Streaming
|
|
16
|
+
export { StreamingUtils } from './streaming.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/utilities/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAA0D,MAAM,mBAAmB,CAAC;AAE7G,kBAAkB;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,QAAQ;AACR,OAAO,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAC;AAE9D,QAAQ;AACR,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|