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.
Files changed (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Native bindings loader
3
+ *
4
+ * This module loads the native C++ bindings compiled by node-gyp.
5
+ * All native classes are accessed through this single entry point.
6
+ */
7
+ import type { AVHWDeviceType, AVLogLevel, AVMediaType, AVOptionSearchFlags, AVPixelFormat, AVSampleFormat } from './constants.js';
8
+ import type { NativeAudioFifo, NativeBitStreamFilter, NativeBitStreamFilterContext, NativeCodec, NativeCodecContext, NativeCodecParameters, NativeCodecParser, NativeDictionary, NativeFFmpegError, NativeFilter, NativeFilterContext, NativeFilterGraph, NativeFilterInOut, NativeFormatContext, NativeFrame, NativeHardwareDeviceContext, NativeHardwareFramesContext, NativeInputFormat, NativeIOContext, NativeLog, NativeOption, NativeOutputFormat, NativePacket, NativeSoftwareResampleContext, NativeSoftwareScaleContext, NativeStream } from './native-types.js';
9
+ import type { ChannelLayout, IRational } from './types.js';
10
+ type NativePacketConstructor = new () => NativePacket;
11
+ type NativeFrameConstructor = new () => NativeFrame;
12
+ interface NativeCodecConstructor {
13
+ new (): NativeCodec;
14
+ findDecoder(id: number): NativeCodec | null;
15
+ findEncoder(id: number): NativeCodec | null;
16
+ findDecoderByName(name: string): NativeCodec | null;
17
+ findEncoderByName(name: string): NativeCodec | null;
18
+ getCodecList(): NativeCodec[];
19
+ iterateCodecs(opaque?: bigint | null): {
20
+ codec: NativeCodec;
21
+ opaque: bigint;
22
+ } | null;
23
+ }
24
+ type NativeCodecContextConstructor = new () => NativeCodecContext;
25
+ type NativeCodecParametersConstructor = new () => NativeCodecParameters;
26
+ type NativeCodecParserConstructor = new () => NativeCodecParser;
27
+ type NativeFormatContextConstructor = new () => NativeFormatContext;
28
+ type NativeStreamConstructor = new () => NativeStream;
29
+ interface NativeInputFormatConstructor {
30
+ new (): NativeInputFormat;
31
+ findInputFormat(shortName: string): NativeInputFormat | null;
32
+ probe(buffer: Buffer, filename?: string): NativeInputFormat | null;
33
+ probeBuffer(ioContext: NativeIOContext, maxProbeSize?: number): Promise<NativeInputFormat | null>;
34
+ }
35
+ interface NativeOutputFormatConstructor {
36
+ new (): NativeOutputFormat;
37
+ guessFormat(shortName: string | null, filename: string | null, mimeType: string | null): NativeOutputFormat | null;
38
+ }
39
+ type NativeIOContextConstructor = new () => NativeIOContext;
40
+ type NativeDictionaryConstructor = new () => NativeDictionary;
41
+ interface NativeFFmpegErrorConstructor {
42
+ new (code?: number): NativeFFmpegError;
43
+ strerror(errnum: number): string;
44
+ makeError(posixError: number): number;
45
+ isError(code: number): boolean;
46
+ }
47
+ interface NativeFilterConstructor {
48
+ new (): NativeFilter;
49
+ getByName(name: string): NativeFilter | null;
50
+ getList(): NativeFilter[];
51
+ }
52
+ type NativeFilterContextConstructor = new () => NativeFilterContext;
53
+ type NativeFilterGraphConstructor = new () => NativeFilterGraph;
54
+ type NativeFilterInOutConstructor = new () => NativeFilterInOut;
55
+ interface NativeBitStreamFilterConstructor {
56
+ new (): NativeBitStreamFilter;
57
+ getByName(name: string): NativeBitStreamFilter | null;
58
+ iterate(): NativeBitStreamFilter[];
59
+ }
60
+ type NativeBitStreamFilterContextConstructor = new () => NativeBitStreamFilterContext;
61
+ type NativeAudioFifoConstructor = new () => NativeAudioFifo;
62
+ type NativeSoftwareScaleContextConstructor = new () => NativeSoftwareScaleContext;
63
+ type NativeSoftwareResampleContextConstructor = new () => NativeSoftwareResampleContext;
64
+ interface NativeHardwareDeviceContextConstructor {
65
+ new (): NativeHardwareDeviceContext;
66
+ getTypeName(type: AVHWDeviceType): string | null;
67
+ iterateTypes(): AVHWDeviceType[];
68
+ findTypeByName(name: string): AVHWDeviceType;
69
+ }
70
+ type NativeHardwareFramesContextConstructor = new () => NativeHardwareFramesContext;
71
+ interface NativeLogConstructor {
72
+ new (): NativeLog;
73
+ setLevel(level: AVLogLevel): void;
74
+ getLevel(): AVLogLevel;
75
+ log(level: AVLogLevel, message: string): void;
76
+ setCallback(callback: ((level: AVLogLevel, message: string) => void) | null, options?: any): void;
77
+ resetCallback(): void;
78
+ }
79
+ interface NativeOptionStatic {
80
+ next(obj: OptionCapableObject, prev?: NativeOption): NativeOption | null;
81
+ find(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): NativeOption | null;
82
+ find2(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): {
83
+ option: NativeOption;
84
+ isDifferentTarget: boolean;
85
+ } | null;
86
+ get(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): string | null;
87
+ getInt(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): number | null;
88
+ getDouble(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): number | null;
89
+ getRational(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): IRational | null;
90
+ getPixelFormat(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): AVPixelFormat | null;
91
+ getSampleFormat(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): AVSampleFormat | null;
92
+ getImageSize(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): {
93
+ width: number;
94
+ height: number;
95
+ } | null;
96
+ getChannelLayout(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): ChannelLayout | null;
97
+ getDict(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): NativeDictionary | null;
98
+ set(obj: OptionCapableObject, name: string, value: string, searchFlags?: AVOptionSearchFlags): number;
99
+ setInt(obj: OptionCapableObject, name: string, value: number | bigint, searchFlags?: AVOptionSearchFlags): number;
100
+ setDouble(obj: OptionCapableObject, name: string, value: number, searchFlags?: AVOptionSearchFlags): number;
101
+ setRational(obj: OptionCapableObject, name: string, value: {
102
+ num: number;
103
+ den: number;
104
+ }, searchFlags?: AVOptionSearchFlags): number;
105
+ setPixelFormat(obj: OptionCapableObject, name: string, value: number, searchFlags?: AVOptionSearchFlags): number;
106
+ setSampleFormat(obj: OptionCapableObject, name: string, value: number, searchFlags?: AVOptionSearchFlags): number;
107
+ setImageSize(obj: OptionCapableObject, name: string, width: number, height: number, searchFlags?: AVOptionSearchFlags): number;
108
+ setChannelLayout(obj: OptionCapableObject, name: string, value: number, searchFlags?: AVOptionSearchFlags): number;
109
+ setDict(obj: OptionCapableObject, name: string, value: NativeDictionary, searchFlags?: AVOptionSearchFlags): number;
110
+ setBin(obj: OptionCapableObject, name: string, value: Buffer, searchFlags?: AVOptionSearchFlags): number;
111
+ setDefaults(obj: OptionCapableObject): void;
112
+ copy(dest: OptionCapableObject, src: OptionCapableObject): number;
113
+ isSetToDefault(obj: OptionCapableObject, name: string, searchFlags?: AVOptionSearchFlags): boolean | null;
114
+ serialize(obj: OptionCapableObject, optFlags?: number, flags?: number, keyValSep?: string, pairsSep?: string): string | null;
115
+ free(obj: OptionCapableObject): void;
116
+ show(obj: OptionCapableObject, reqFlags?: number, rejFlags?: number): number;
117
+ }
118
+ /**
119
+ * The complete native binding interface
120
+ */
121
+ export interface NativeBinding {
122
+ Packet: NativePacketConstructor;
123
+ Frame: NativeFrameConstructor;
124
+ Codec: NativeCodecConstructor;
125
+ CodecContext: NativeCodecContextConstructor;
126
+ CodecParameters: NativeCodecParametersConstructor;
127
+ CodecParser: NativeCodecParserConstructor;
128
+ FormatContext: NativeFormatContextConstructor;
129
+ Stream: NativeStreamConstructor;
130
+ InputFormat: NativeInputFormatConstructor;
131
+ OutputFormat: NativeOutputFormatConstructor;
132
+ IOContext: NativeIOContextConstructor;
133
+ Filter: NativeFilterConstructor;
134
+ FilterContext: NativeFilterContextConstructor;
135
+ FilterGraph: NativeFilterGraphConstructor;
136
+ FilterInOut: NativeFilterInOutConstructor;
137
+ BitStreamFilter: NativeBitStreamFilterConstructor;
138
+ BitStreamFilterContext: NativeBitStreamFilterContextConstructor;
139
+ AudioFifo: NativeAudioFifoConstructor;
140
+ SoftwareScaleContext: NativeSoftwareScaleContextConstructor;
141
+ SoftwareResampleContext: NativeSoftwareResampleContextConstructor;
142
+ HardwareDeviceContext: NativeHardwareDeviceContextConstructor;
143
+ HardwareFramesContext: NativeHardwareFramesContextConstructor;
144
+ Dictionary: NativeDictionaryConstructor;
145
+ FFmpegError: NativeFFmpegErrorConstructor;
146
+ Log: NativeLogConstructor;
147
+ Option: NativeOptionStatic;
148
+ getVersion: () => string;
149
+ avGetBytesPerSample: (sampleFmt: AVSampleFormat) => number;
150
+ avGetSampleFmtName: (sampleFmt: AVSampleFormat) => string | null;
151
+ avGetPackedSampleFmt: (sampleFmt: AVSampleFormat) => AVSampleFormat;
152
+ avGetPlanarSampleFmt: (sampleFmt: AVSampleFormat) => AVSampleFormat;
153
+ avSampleFmtIsPlanar: (sampleFmt: AVSampleFormat) => boolean;
154
+ avGetPixFmtName: (pixFmt: AVPixelFormat) => string | null;
155
+ avGetPixFmtFromName: (name: string) => AVPixelFormat;
156
+ avIsHardwarePixelFormat: (pixFmt: AVPixelFormat) => boolean;
157
+ avGetMediaTypeString: (mediaType: AVMediaType) => string | null;
158
+ avImageAlloc: (width: number, height: number, pixFmt: AVPixelFormat, align: number) => {
159
+ buffer: Buffer;
160
+ size: number;
161
+ linesizes: number[];
162
+ } | number;
163
+ avImageCopy2: (dstData: Buffer[], dstLinesizes: number[], srcData: Buffer[], srcLinesizes: number[], pixFmt: AVPixelFormat, width: number, height: number) => void;
164
+ avImageGetBufferSize: (pixFmt: AVPixelFormat, width: number, height: number, align: number) => number;
165
+ avImageCopyToBuffer: (dst: Buffer, dstSize: number, srcData: Buffer[] | null, srcLinesize: number[] | null, pixFmt: AVPixelFormat, width: number, height: number, align: number) => number;
166
+ avTs2Str: (ts: bigint | number | null) => string;
167
+ avTs2TimeStr: (ts: bigint | number | null, timeBase: IRational) => string;
168
+ avCompareTs: (tsA: bigint | number | null, tbA: IRational, tsB: bigint | number | null, tbB: IRational) => number;
169
+ avRescaleQ: (a: bigint | number | null, bq: IRational, cq: IRational) => bigint;
170
+ avRescaleRnd: (a: bigint | number, b: bigint | number, c: bigint | number, rnd: number) => bigint;
171
+ avUsleep: (usec: number) => void;
172
+ avSamplesAlloc: (nbChannels: number, nbSamples: number, sampleFmt: AVSampleFormat, align: number) => {
173
+ data: Buffer[];
174
+ linesize: number;
175
+ size: number;
176
+ } | number;
177
+ avSamplesGetBufferSize: (nbChannels: number, nbSamples: number, sampleFmt: AVSampleFormat, align: number) => {
178
+ size: number;
179
+ linesize: number;
180
+ } | number;
181
+ avChannelLayoutDescribe: (channelLayout: Partial<ChannelLayout>) => string | null;
182
+ avSdpCreate: (contexts: NativeFormatContext[]) => string | null;
183
+ }
184
+ /**
185
+ * Union type for all native FFmpeg objects that support AVOptions.
186
+ *
187
+ * These objects have an AVClass structure as their first member,
188
+ * which enables the AVOption API for runtime configuration.
189
+ */
190
+ export type OptionCapableObject = NativeCodecContext | NativeFormatContext | NativeFilterContext | NativeFilterGraph | NativeSoftwareScaleContext | NativeSoftwareResampleContext | NativeIOContext | NativeBitStreamFilterContext;
191
+ declare const bindings: NativeBinding;
192
+ export { bindings };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Native bindings loader
3
+ *
4
+ * This module loads the native C++ bindings compiled by node-gyp.
5
+ * All native classes are accessed through this single entry point.
6
+ */
7
+ import { existsSync } from 'fs';
8
+ import { createRequire } from 'module';
9
+ import { join } from 'path';
10
+ function loadBinding() {
11
+ const require = createRequire(import.meta.url);
12
+ const errors = [];
13
+ // Detect platform
14
+ const platform = process.platform;
15
+ const arch = process.arch;
16
+ const platformArch = `${platform}-${arch}`;
17
+ // Try 1: Platform-specific package (optionalDependencies)
18
+ try {
19
+ const packageName = `@seydx/node-av-${platformArch}`;
20
+ return require(`${packageName}/node-av.node`);
21
+ }
22
+ catch (err) {
23
+ errors.push(new Error(`Platform package not found: ${err}`));
24
+ }
25
+ // Try 2: Local build directory (development)
26
+ try {
27
+ const localPath = join(process.cwd(), 'build', 'Release', 'node-av.node');
28
+ if (existsSync(localPath)) {
29
+ return require(localPath);
30
+ }
31
+ }
32
+ catch (err) {
33
+ errors.push(new Error(`Local build not found: ${err}`));
34
+ }
35
+ // Try 3: Binary directory (postinstall)
36
+ try {
37
+ const binaryPath = join(process.cwd(), 'binary', 'node-av.node');
38
+ if (existsSync(binaryPath)) {
39
+ return require(binaryPath);
40
+ }
41
+ }
42
+ catch (err) {
43
+ errors.push(new Error(`Binary directory not found: ${err}`));
44
+ }
45
+ // Try 4: node-gyp-build style paths
46
+ try {
47
+ const gypBuildPath = join(process.cwd(), 'build', 'node-av.node');
48
+ if (existsSync(gypBuildPath)) {
49
+ return require(gypBuildPath);
50
+ }
51
+ }
52
+ catch (err) {
53
+ errors.push(new Error(`node-gyp build not found: ${err}`));
54
+ }
55
+ // All attempts failed
56
+ const errorMessages = errors.map((e) => e.message).join('\n ');
57
+ // prettier-ignore
58
+ throw new Error(`Could not load the node-av native binding for ${platformArch}.\n` +
59
+ `Attempted locations:\n ${errorMessages}\n\n` +
60
+ 'Possible solutions:\n' +
61
+ "1. Run 'npm install' to download the prebuilt binary\n" +
62
+ "2. Run 'npm install --build-from-source' to compile from source\n" +
63
+ '3. Ensure you have the required dependencies for your platform\n' +
64
+ '\n' +
65
+ 'See https://github.com/seydx/av for more information.');
66
+ }
67
+ // Load the native binding with fallback logic
68
+ const bindings = loadBinding();
69
+ export { bindings };
70
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/lib/binding.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA+Q5B,SAAS,WAAW;IAClB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,kBAAkB;IAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,MAAM,YAAY,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;IAE3C,0DAA0D;IAC1D,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,kBAAkB,YAAY,EAAE,CAAC;QACrD,OAAO,OAAO,CAAC,GAAG,WAAW,eAAe,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,6CAA6C;IAC7C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;QAC1E,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QACjE,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3B,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,oCAAoC;IACpC,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;QAClE,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,sBAAsB;IACtB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChE,kBAAkB;IAClB,MAAM,IAAI,KAAK,CACb,iDAAiD,YAAY,KAAK;QAClE,2BAA2B,aAAa,MAAM;QAC9C,uBAAuB;QACvB,wDAAwD;QACxD,mEAAmE;QACnE,kEAAkE;QAClE,IAAI;QACJ,uDAAuD,CACxD,CAAC;AACJ,CAAC;AAED,8CAA8C;AAC9C,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,345 @@
1
+ import { BitStreamFilter } from './bitstream-filter.js';
2
+ import { CodecParameters } from './codec-parameters.js';
3
+ import { OptionMember } from './option.js';
4
+ import { Rational } from './rational.js';
5
+ import type { NativeBitStreamFilterContext, NativeWrapper } from './native-types.js';
6
+ import type { Packet } from './packet.js';
7
+ /**
8
+ * Bitstream filter context for processing packets.
9
+ *
10
+ * Manages the state for bitstream filtering operations.
11
+ * Processes packets through a bitstream filter without decoding.
12
+ * Supports packet-by-packet filtering with internal buffering.
13
+ *
14
+ * Direct mapping to FFmpeg's AVBSFContext.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { BitStreamFilter, BitStreamFilterContext, Packet, FFmpegError } from 'node-av';
19
+ * import { AVERROR_EOF, AVERROR } from 'node-av/constants';
20
+ *
21
+ * // Create and initialize filter context
22
+ * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
23
+ * const ctx = new BitStreamFilterContext();
24
+ *
25
+ * // Allocate and configure
26
+ * let ret = ctx.alloc(filter);
27
+ * FFmpegError.throwIfError(ret, 'alloc');
28
+ *
29
+ * // Copy input parameters from stream to BSF context
30
+ * stream.codecpar.copy(ctx.inputCodecParameters);
31
+ * ctx.inputTimeBase = stream.timeBase;
32
+ *
33
+ * // Initialize filter
34
+ * ret = ctx.init();
35
+ * FFmpegError.throwIfError(ret, 'init');
36
+ *
37
+ * // Process packets
38
+ * while (hasMorePackets) {
39
+ * const inputPacket = getNextPacket();
40
+ *
41
+ * // Send packet to filter
42
+ * ret = await ctx.sendPacket(inputPacket);
43
+ * FFmpegError.throwIfError(ret, 'sendPacket');
44
+ *
45
+ * // Receive filtered packets
46
+ * while (true) {
47
+ * const outputPacket = new Packet();
48
+ * const result = await ctx.receivePacket(outputPacket);
49
+ *
50
+ * if (result.eagain || result.eof) break;
51
+ * FFmpegError.throwIfError(result.ret || result, 'receivePacket');
52
+ *
53
+ * // Process filtered packet
54
+ * processPacket(outputPacket);
55
+ * outputPacket.unref();
56
+ * }
57
+ * }
58
+ *
59
+ * // Send EOF
60
+ * await ctx.sendPacket(null);
61
+ *
62
+ * // Drain remaining packets
63
+ * while (true) {
64
+ * const outputPacket = new Packet();
65
+ * const result = await ctx.receivePacket(outputPacket);
66
+ * if (result.eof) break;
67
+ * // Process remaining packets
68
+ * }
69
+ *
70
+ * // Cleanup
71
+ * ctx.free();
72
+ * ```
73
+ */
74
+ export declare class BitStreamFilterContext extends OptionMember<NativeBitStreamFilterContext> implements Disposable, NativeWrapper<NativeBitStreamFilterContext> {
75
+ private _filter?;
76
+ /**
77
+ * Create a new bitstream filter context.
78
+ *
79
+ * The context is uninitialized - you must call alloc() and init() before use.
80
+ * No FFmpeg resources are allocated until initialization.
81
+ *
82
+ * Direct wrapper around AVBSFContext.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const ctx = new BitStreamFilterContext();
87
+ * ctx.alloc(filter);
88
+ * ctx.init();
89
+ * // Context is now ready for filtering
90
+ * ```
91
+ */
92
+ constructor();
93
+ /**
94
+ * Check if the context is initialized.
95
+ *
96
+ * Returns true if init() has been called successfully.
97
+ *
98
+ * @returns True if initialized, false otherwise
99
+ */
100
+ get isInitialized(): boolean;
101
+ /**
102
+ * Input codec parameters (read-only reference, mutable contents).
103
+ *
104
+ * Returns a reference to the BSF context's internal codec parameters.
105
+ * While you cannot replace this object (no setter), you can modify its contents
106
+ * or use it as a destination for copy operations.
107
+ *
108
+ * You must configure these parameters before calling init().
109
+ *
110
+ * Maps to AVBSFContext->par_in.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * // Copy parameters from input stream to BSF context
115
+ * if (ctx.inputCodecParameters) {
116
+ * stream.codecpar.copy(ctx.inputCodecParameters);
117
+ *
118
+ * // Or set individual properties
119
+ * ctx.inputCodecParameters.codecType = AVMEDIA_TYPE_VIDEO;
120
+ * ctx.inputCodecParameters.codecId = AV_CODEC_ID_H264;
121
+ * }
122
+ * ```
123
+ */
124
+ get inputCodecParameters(): CodecParameters | null;
125
+ /**
126
+ * Output codec parameters (read-only reference, read-only contents).
127
+ *
128
+ * Returns a reference to the BSF context's output codec parameters.
129
+ * These are automatically configured by the filter during init().
130
+ * You should not modify these parameters.
131
+ *
132
+ * Maps to AVBSFContext->par_out.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * // After initialization, read the output parameters
137
+ * console.log(`Output codec: ${ctx.outputCodecParameters?.codecId}`);
138
+ *
139
+ * // Use them to configure downstream components
140
+ * if (ctx.outputCodecParameters) {
141
+ * ctx.outputCodecParameters.copy(nextStream.codecpar);
142
+ * }
143
+ * ```
144
+ */
145
+ get outputCodecParameters(): CodecParameters | null;
146
+ /**
147
+ * Input time base.
148
+ *
149
+ * Time base for input packet timestamps.
150
+ * Must be set before calling init().
151
+ *
152
+ * Maps to AVBSFContext->time_base_in.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * ctx.inputTimeBase = new Rational(1, 1000); // 1ms time base
157
+ * ```
158
+ */
159
+ get inputTimeBase(): Rational;
160
+ set inputTimeBase(value: Rational);
161
+ /**
162
+ * Output time base.
163
+ *
164
+ * Time base for output packet timestamps.
165
+ * Set by the filter during init().
166
+ *
167
+ * Maps to AVBSFContext->time_base_out.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // After initialization
172
+ * console.log(`Output time base: ${ctx.outputTimeBase.num}/${ctx.outputTimeBase.den}`);
173
+ * ```
174
+ */
175
+ get outputTimeBase(): Rational | null;
176
+ /**
177
+ * The bitstream filter being used.
178
+ *
179
+ * Reference to the filter this context was allocated with.
180
+ *
181
+ * Maps to AVBSFContext->filter.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * console.log(`Using filter: ${ctx.filter?.name}`);
186
+ * ```
187
+ */
188
+ get filter(): BitStreamFilter | null;
189
+ /**
190
+ * Allocate the bitstream filter context.
191
+ *
192
+ * Allocates the context for the specified filter.
193
+ * Must be called before any other operations.
194
+ * After allocation, configure input parameters before calling init().
195
+ *
196
+ * Calls av_bsf_alloc() internally.
197
+ *
198
+ * @param filter - The bitstream filter to use
199
+ * @returns 0 on success, negative error code on failure
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
204
+ * const ctx = new BitStreamFilterContext();
205
+ * const ret = ctx.alloc(filter);
206
+ * FFmpegError.throwIfError(ret, 'alloc');
207
+ * ```
208
+ */
209
+ alloc(filter: BitStreamFilter): number;
210
+ /**
211
+ * Initialize the bitstream filter context.
212
+ *
213
+ * Prepares the filter for use after parameters have been set.
214
+ * Sets up output parameters based on input and filter configuration.
215
+ * Must be called after alloc() and parameter configuration.
216
+ *
217
+ * Calls av_bsf_init() internally.
218
+ *
219
+ * @returns 0 on success, negative error code on failure
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * // After allocation and parameter setup
224
+ * const ret = ctx.init();
225
+ * FFmpegError.throwIfError(ret, 'init');
226
+ * ```
227
+ */
228
+ init(): number;
229
+ /**
230
+ * Free the bitstream filter context.
231
+ *
232
+ * Releases all resources associated with the context.
233
+ * The context cannot be used after calling this method.
234
+ *
235
+ * Calls av_bsf_free() internally.
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * ctx.free();
240
+ * // Context is now freed and unusable
241
+ * ```
242
+ */
243
+ free(): void;
244
+ /**
245
+ * Flush the bitstream filter.
246
+ *
247
+ * Resets the internal filter state.
248
+ * Should be called when seeking or switching streams.
249
+ *
250
+ * Calls av_bsf_flush() internally.
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * // When seeking
255
+ * ctx.flush();
256
+ * // Filter is reset and ready for new packets
257
+ * ```
258
+ */
259
+ flush(): void;
260
+ /**
261
+ * Send a packet to the filter.
262
+ *
263
+ * Submits a packet for filtering.
264
+ * The filter takes ownership of the packet.
265
+ * Pass null to signal end of stream.
266
+ *
267
+ * After sending a packet, call receivePacket() repeatedly
268
+ * until it returns EAGAIN or EOF.
269
+ *
270
+ * Calls av_bsf_send_packet() internally.
271
+ *
272
+ * @param packet - Packet to filter, or null for EOF
273
+ * @returns Promise resolving to 0 on success, error code on failure
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Send packet
278
+ * const ret = await ctx.sendPacket(inputPacket);
279
+ * if (ret < 0 && ret !== AVERROR_EAGAIN) {
280
+ * throw new Error('Failed to send packet');
281
+ * }
282
+ *
283
+ * // Send EOF
284
+ * await ctx.sendPacket(null);
285
+ * ```
286
+ */
287
+ sendPacket(packet: Packet | null): Promise<number>;
288
+ /**
289
+ * Receive a filtered packet.
290
+ *
291
+ * Gets a filtered packet from the filter.
292
+ * Must be called repeatedly after sendPacket() until EAGAIN or EOF.
293
+ * One input packet may produce multiple output packets.
294
+ *
295
+ * Calls av_bsf_receive_packet() internally.
296
+ *
297
+ * @param packet - Packet to receive filtered data into
298
+ * @returns Promise resolving to 0 on success, negative error code on failure
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
303
+ *
304
+ * const packet = new Packet();
305
+ * const ret = await ctx.receivePacket(packet);
306
+ *
307
+ * if (ret === AVERROR_EAGAIN) {
308
+ * // Need to send more packets
309
+ * } else if (ret === AVERROR_EOF) {
310
+ * // No more packets
311
+ * } else if (ret < 0) {
312
+ * // Error occurred
313
+ * } else {
314
+ * // Got a packet successfully
315
+ * processPacket(packet);
316
+ * }
317
+ * ```
318
+ */
319
+ receivePacket(packet: Packet): Promise<number>;
320
+ /**
321
+ * Get the underlying native object.
322
+ *
323
+ * For advanced use cases that need direct access to the native bindings.
324
+ *
325
+ * @returns Native BitStreamFilterContext object
326
+ * @internal
327
+ */
328
+ getNative(): NativeBitStreamFilterContext;
329
+ /**
330
+ * Dispose of the context resources.
331
+ *
332
+ * Automatically called when using the `using` statement.
333
+ * Frees all associated FFmpeg resources.
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * {
338
+ * using ctx = new BitStreamFilterContext();
339
+ * ctx.alloc(filter);
340
+ * // ... use context
341
+ * } // Automatically freed when leaving scope
342
+ * ```
343
+ */
344
+ [Symbol.dispose](): void;
345
+ }