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,104 @@
1
+ /**
2
+ * Streaming Utilities
3
+ *
4
+ * Provides utilities for working with streaming protocols in FFmpeg.
5
+ * Includes SDP generation for RTP/RTSP streaming and helper methods.
6
+ *
7
+ * @module api/utilities/streaming
8
+ */
9
+ import type { MediaInput } from '../media-input.js';
10
+ import type { MediaOutput } from '../media-output.js';
11
+ /**
12
+ * Streaming protocol utilities.
13
+ *
14
+ * Provides static methods for SDP generation, RTP URL building, and
15
+ * network streaming helpers for RTP/RTSP protocols.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { StreamingUtils, MediaOutput } from 'node-av/api';
20
+ *
21
+ * // Create RTP outputs
22
+ * const videoOutput = await MediaOutput.create('rtp://127.0.0.1:5004');
23
+ * const audioOutput = await MediaOutput.create('rtp://127.0.0.1:5006');
24
+ *
25
+ * // Generate SDP for streaming
26
+ * const sdp = StreamingUtils.createSdp([videoOutput, audioOutput]);
27
+ * if (sdp) {
28
+ * console.log('SDP for streaming:', sdp);
29
+ * // Save to .sdp file or serve via RTSP server
30
+ * }
31
+ * ```
32
+ */
33
+ export declare class StreamingUtils {
34
+ /**
35
+ * Create an SDP (Session Description Protocol) string from media inputs/outputs
36
+ *
37
+ * Generates an SDP description for RTP/RTSP streaming from one or more
38
+ * configured media inputs/outputs. The inputs/outputs should be configured with RTP
39
+ * format and have their streams set up before calling this method.
40
+ *
41
+ * @param inouts - Array of MediaInput or MediaOutput objects configured for RTP
42
+ * @returns SDP string if successful, null if failed
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // Set up RTP outputs with streams
47
+ * const output1 = await MediaOutput.create('rtp://239.0.0.1:5004');
48
+ * await output1.addVideoStream(encoder1);
49
+ *
50
+ * const output2 = await MediaOutput.create('rtp://239.0.0.1:5006');
51
+ * await output2.addAudioStream(encoder2);
52
+ *
53
+ * // Generate SDP for multicast streaming
54
+ * const sdp = StreamingUtils.createSdp([output1, output2]);
55
+ * if (sdp) {
56
+ * // Write to file for VLC or other players
57
+ * await fs.writeFile('stream.sdp', sdp);
58
+ * }
59
+ * ```
60
+ */
61
+ static createSdp(inouts: MediaInput[] | MediaOutput[]): string | null;
62
+ /**
63
+ * Validate if an output is configured for RTP streaming
64
+ *
65
+ * @param output - MediaOutput to check
66
+ * @returns true if configured for RTP
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const output = await MediaOutput.create('rtp://127.0.0.1:5004');
71
+ * if (StreamingUtils.isRtpOutput(output)) {
72
+ * const sdp = StreamingUtils.createSdpForOutput(output);
73
+ * }
74
+ * ```
75
+ */
76
+ static isRtpOutput(output: MediaOutput): boolean;
77
+ /**
78
+ * Build RTP URL from components
79
+ *
80
+ * Helper to construct RTP URLs with proper formatting.
81
+ *
82
+ * @param host - IP address or hostname
83
+ * @param port - Port number
84
+ * @param options - Additional options
85
+ * @returns Formatted RTP URL
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Unicast
90
+ * const url1 = StreamingUtils.buildRtpUrl('127.0.0.1', 5004);
91
+ * // 'rtp://127.0.0.1:5004'
92
+ *
93
+ * // Multicast
94
+ * const url2 = StreamingUtils.buildRtpUrl('239.0.0.1', 5004, { ttl: 64 });
95
+ * // 'rtp://239.0.0.1:5004?ttl=64'
96
+ * ```
97
+ */
98
+ static buildRtpUrl(host: string, port: number, options?: {
99
+ ttl?: number;
100
+ localrtpport?: number;
101
+ localrtcpport?: number;
102
+ pkt_size?: number;
103
+ }): string;
104
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Streaming Utilities
3
+ *
4
+ * Provides utilities for working with streaming protocols in FFmpeg.
5
+ * Includes SDP generation for RTP/RTSP streaming and helper methods.
6
+ *
7
+ * @module api/utilities/streaming
8
+ */
9
+ import { avSdpCreate } from '../../lib/utilities.js';
10
+ /**
11
+ * Streaming protocol utilities.
12
+ *
13
+ * Provides static methods for SDP generation, RTP URL building, and
14
+ * network streaming helpers for RTP/RTSP protocols.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { StreamingUtils, MediaOutput } from 'node-av/api';
19
+ *
20
+ * // Create RTP outputs
21
+ * const videoOutput = await MediaOutput.create('rtp://127.0.0.1:5004');
22
+ * const audioOutput = await MediaOutput.create('rtp://127.0.0.1:5006');
23
+ *
24
+ * // Generate SDP for streaming
25
+ * const sdp = StreamingUtils.createSdp([videoOutput, audioOutput]);
26
+ * if (sdp) {
27
+ * console.log('SDP for streaming:', sdp);
28
+ * // Save to .sdp file or serve via RTSP server
29
+ * }
30
+ * ```
31
+ */
32
+ export class StreamingUtils {
33
+ /**
34
+ * Create an SDP (Session Description Protocol) string from media inputs/outputs
35
+ *
36
+ * Generates an SDP description for RTP/RTSP streaming from one or more
37
+ * configured media inputs/outputs. The inputs/outputs should be configured with RTP
38
+ * format and have their streams set up before calling this method.
39
+ *
40
+ * @param inouts - Array of MediaInput or MediaOutput objects configured for RTP
41
+ * @returns SDP string if successful, null if failed
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Set up RTP outputs with streams
46
+ * const output1 = await MediaOutput.create('rtp://239.0.0.1:5004');
47
+ * await output1.addVideoStream(encoder1);
48
+ *
49
+ * const output2 = await MediaOutput.create('rtp://239.0.0.1:5006');
50
+ * await output2.addAudioStream(encoder2);
51
+ *
52
+ * // Generate SDP for multicast streaming
53
+ * const sdp = StreamingUtils.createSdp([output1, output2]);
54
+ * if (sdp) {
55
+ * // Write to file for VLC or other players
56
+ * await fs.writeFile('stream.sdp', sdp);
57
+ * }
58
+ * ```
59
+ */
60
+ static createSdp(inouts) {
61
+ if (!inouts || inouts.length === 0) {
62
+ return null;
63
+ }
64
+ // Extract FormatContext from each MediaOutput
65
+ const contexts = inouts
66
+ .map((inout) => {
67
+ return inout.getFormatContext();
68
+ })
69
+ .filter((ctx) => ctx != null);
70
+ if (contexts.length === 0) {
71
+ return null;
72
+ }
73
+ return avSdpCreate(contexts);
74
+ }
75
+ /**
76
+ * Validate if an output is configured for RTP streaming
77
+ *
78
+ * @param output - MediaOutput to check
79
+ * @returns true if configured for RTP
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const output = await MediaOutput.create('rtp://127.0.0.1:5004');
84
+ * if (StreamingUtils.isRtpOutput(output)) {
85
+ * const sdp = StreamingUtils.createSdpForOutput(output);
86
+ * }
87
+ * ```
88
+ */
89
+ static isRtpOutput(output) {
90
+ // Check if the output format is RTP
91
+ const formatContext = output.getFormatContext();
92
+ const oformat = formatContext?.oformat;
93
+ if (oformat) {
94
+ const name = oformat.name;
95
+ return name === 'rtp' || name === 'rtp_mpegts';
96
+ }
97
+ return false;
98
+ }
99
+ /**
100
+ * Build RTP URL from components
101
+ *
102
+ * Helper to construct RTP URLs with proper formatting.
103
+ *
104
+ * @param host - IP address or hostname
105
+ * @param port - Port number
106
+ * @param options - Additional options
107
+ * @returns Formatted RTP URL
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // Unicast
112
+ * const url1 = StreamingUtils.buildRtpUrl('127.0.0.1', 5004);
113
+ * // 'rtp://127.0.0.1:5004'
114
+ *
115
+ * // Multicast
116
+ * const url2 = StreamingUtils.buildRtpUrl('239.0.0.1', 5004, { ttl: 64 });
117
+ * // 'rtp://239.0.0.1:5004?ttl=64'
118
+ * ```
119
+ */
120
+ static buildRtpUrl(host, port, options) {
121
+ let url = `rtp://${host}:${port}`;
122
+ if (options && Object.keys(options).length > 0) {
123
+ const params = new URLSearchParams();
124
+ for (const [key, value] of Object.entries(options)) {
125
+ if (value !== undefined) {
126
+ params.append(key, String(value));
127
+ }
128
+ }
129
+ const queryString = params.toString();
130
+ if (queryString) {
131
+ url += `?${queryString}`;
132
+ }
133
+ }
134
+ return url;
135
+ }
136
+ }
137
+ //# sourceMappingURL=streaming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/api/utilities/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,cAAc;IACzB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,SAAS,CAAC,MAAoC;QACnD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,MAAM;aACpB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,OAAO,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAClC,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QAEhC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,WAAW,CAAC,MAAmB;QACpC,oCAAoC;QACpC,MAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAChD,MAAM,OAAO,GAAG,aAAa,EAAE,OAAO,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,OAAO,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,YAAY,CAAC;QACjD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,WAAW,CAChB,IAAY,EACZ,IAAY,EACZ,OAKC;QAED,IAAI,GAAG,GAAG,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC;QAElC,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/C,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACxB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;YACtC,IAAI,WAAW,EAAE,CAAC;gBAChB,GAAG,IAAI,IAAI,WAAW,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Timestamp Utilities
3
+ *
4
+ * Provides utilities for working with timestamps in FFmpeg.
5
+ * All methods are static and map directly to FFmpeg's libavutil functions.
6
+ *
7
+ * @module lib/timestamp-utils
8
+ */
9
+ import type { AVRounding } from '../../lib/constants.js';
10
+ import type { IRational } from '../../lib/types.js';
11
+ /**
12
+ * Timestamp and time base utilities.
13
+ *
14
+ * Provides static methods for converting, rescaling, and comparing timestamps.
15
+ * These utilities are essential for working with different time bases in
16
+ * multimedia streams.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { TimestampUtils } from 'node-av';
21
+ * import { AV_ROUND_NEAR_INF } from 'node-av/constants';
22
+ *
23
+ * // Convert timestamp to string representations
24
+ * const pts = 450000n;
25
+ * console.log(TimestampUtils.toString(pts)); // "450000"
26
+ *
27
+ * const timebase = { num: 1, den: 90000 };
28
+ * console.log(TimestampUtils.toTimeString(pts, timebase)); // "5.000000"
29
+ *
30
+ * // Rescale between time bases
31
+ * const srcTb = { num: 1, den: 90000 };
32
+ * const dstTb = { num: 1, den: 1000 };
33
+ * const rescaled = TimestampUtils.rescale(pts, srcTb, dstTb);
34
+ * console.log(rescaled); // 5000n
35
+ * ```
36
+ */
37
+ export declare class TimestampUtils {
38
+ private constructor();
39
+ /**
40
+ * Convert timestamp to string.
41
+ *
42
+ * Converts a timestamp value to its string representation.
43
+ * Handles special values like AV_NOPTS_VALUE.
44
+ * Direct mapping to av_ts2str()
45
+ *
46
+ * @param ts - Timestamp value (bigint or number), or null
47
+ * @returns String representation
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { TimestampUtils } from 'node-av';
52
+ * import { AV_NOPTS_VALUE } from 'node-av/constants';
53
+ *
54
+ * console.log(TimestampUtils.toString(12345n)); // "12345"
55
+ * console.log(TimestampUtils.toString(AV_NOPTS_VALUE)); // "NOPTS"
56
+ * console.log(TimestampUtils.toString(null)); // "NOPTS"
57
+ * ```
58
+ */
59
+ static toString(ts: bigint | number | null): string;
60
+ /**
61
+ * Convert timestamp to time string.
62
+ *
63
+ * Converts a timestamp to a time string in seconds using the provided time base.
64
+ * Direct mapping to av_ts2timestr()
65
+ *
66
+ * @param ts - Timestamp value
67
+ * @param timeBase - Time base for conversion
68
+ * @returns Time string in seconds with decimal places
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { TimestampUtils } from 'node-av';
73
+ *
74
+ * const pts = 450000n;
75
+ * const timebase = { num: 1, den: 90000 }; // 90kHz
76
+ *
77
+ * console.log(TimestampUtils.toTimeString(pts, timebase)); // "5.000000"
78
+ * console.log(TimestampUtils.toTimeString(90000n, timebase)); // "1.000000"
79
+ * ```
80
+ */
81
+ static toTimeString(ts: bigint | number | null, timeBase: IRational): string;
82
+ /**
83
+ * Compare timestamps from different time bases.
84
+ *
85
+ * Compares two timestamps that may have different time bases.
86
+ * Direct mapping to av_compare_ts()
87
+ *
88
+ * @param tsA - First timestamp
89
+ * @param tbA - Time base of first timestamp
90
+ * @param tsB - Second timestamp
91
+ * @param tbB - Time base of second timestamp
92
+ * @returns -1 if tsA < tsB, 0 if equal, 1 if tsA > tsB
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { TimestampUtils } from 'node-av';
97
+ *
98
+ * // Compare timestamps from different time bases
99
+ * const pts1 = 90000n;
100
+ * const tb1 = { num: 1, den: 90000 }; // 1 second in 90kHz
101
+ *
102
+ * const pts2 = 1000n;
103
+ * const tb2 = { num: 1, den: 1000 }; // 1 second in 1kHz
104
+ *
105
+ * const result = TimestampUtils.compare(pts1, tb1, pts2, tb2);
106
+ * console.log(result); // 0 (equal - both represent 1 second)
107
+ * ```
108
+ */
109
+ static compare(tsA: bigint | number | null, tbA: IRational, tsB: bigint | number | null, tbB: IRational): number;
110
+ /**
111
+ * Rescale timestamp from one time base to another.
112
+ *
113
+ * Converts a timestamp from source time base to destination time base.
114
+ * Uses AV_ROUND_NEAR_INF rounding.
115
+ * Direct mapping to av_rescale_q()
116
+ *
117
+ * @param a - Timestamp to rescale
118
+ * @param bq - Source time base
119
+ * @param cq - Destination time base
120
+ * @returns Rescaled timestamp
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { TimestampUtils } from 'node-av';
125
+ *
126
+ * // Convert from 90kHz to milliseconds
127
+ * const pts = 450000n;
128
+ * const srcTb = { num: 1, den: 90000 };
129
+ * const dstTb = { num: 1, den: 1000 };
130
+ *
131
+ * const rescaled = TimestampUtils.rescale(pts, srcTb, dstTb);
132
+ * console.log(rescaled); // 5000n (5000 milliseconds = 5 seconds)
133
+ * ```
134
+ */
135
+ static rescale(a: bigint | number | null, bq: IRational, cq: IRational): bigint;
136
+ /**
137
+ * Rescale with specified rounding.
138
+ *
139
+ * Rescales a value with explicit rounding mode.
140
+ * More general than rescale() as it doesn't use time bases.
141
+ * Direct mapping to av_rescale_rnd()
142
+ *
143
+ * @param a - Value to rescale
144
+ * @param b - Multiplier
145
+ * @param c - Divisor
146
+ * @param rnd - Rounding mode
147
+ * @returns Rescaled value: a * b / c
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { TimestampUtils } from 'node-av';
152
+ * import { AV_ROUND_UP, AV_ROUND_DOWN } from 'node-av/constants';
153
+ *
154
+ * // Scale with different rounding modes
155
+ * const value = 100n;
156
+ * const mul = 3n;
157
+ * const div = 7n;
158
+ *
159
+ * const roundUp = TimestampUtils.rescaleRounded(value, mul, div, AV_ROUND_UP);
160
+ * const roundDown = TimestampUtils.rescaleRounded(value, mul, div, AV_ROUND_DOWN);
161
+ *
162
+ * console.log(roundUp); // 43n (rounds up)
163
+ * console.log(roundDown); // 42n (rounds down)
164
+ * ```
165
+ */
166
+ static rescaleRounded(a: bigint | number, b: bigint | number, c: bigint | number, rnd: AVRounding): bigint;
167
+ /**
168
+ * Sleep for specified microseconds.
169
+ *
170
+ * Sleeps for the specified number of microseconds.
171
+ * Direct mapping to av_usleep()
172
+ *
173
+ * @param usec - Microseconds to sleep
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * import { TimestampUtils } from 'node-av';
178
+ *
179
+ * // Sleep for 100 milliseconds
180
+ * TimestampUtils.sleep(100000);
181
+ *
182
+ * // Sleep for 1 second
183
+ * TimestampUtils.sleep(1000000);
184
+ * ```
185
+ */
186
+ static sleep(usec: number): void;
187
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Timestamp Utilities
3
+ *
4
+ * Provides utilities for working with timestamps in FFmpeg.
5
+ * All methods are static and map directly to FFmpeg's libavutil functions.
6
+ *
7
+ * @module lib/timestamp-utils
8
+ */
9
+ import { bindings } from '../../lib/binding.js';
10
+ /**
11
+ * Timestamp and time base utilities.
12
+ *
13
+ * Provides static methods for converting, rescaling, and comparing timestamps.
14
+ * These utilities are essential for working with different time bases in
15
+ * multimedia streams.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { TimestampUtils } from 'node-av';
20
+ * import { AV_ROUND_NEAR_INF } from 'node-av/constants';
21
+ *
22
+ * // Convert timestamp to string representations
23
+ * const pts = 450000n;
24
+ * console.log(TimestampUtils.toString(pts)); // "450000"
25
+ *
26
+ * const timebase = { num: 1, den: 90000 };
27
+ * console.log(TimestampUtils.toTimeString(pts, timebase)); // "5.000000"
28
+ *
29
+ * // Rescale between time bases
30
+ * const srcTb = { num: 1, den: 90000 };
31
+ * const dstTb = { num: 1, den: 1000 };
32
+ * const rescaled = TimestampUtils.rescale(pts, srcTb, dstTb);
33
+ * console.log(rescaled); // 5000n
34
+ * ```
35
+ */
36
+ export class TimestampUtils {
37
+ // Private constructor to prevent instantiation
38
+ constructor() { }
39
+ /**
40
+ * Convert timestamp to string.
41
+ *
42
+ * Converts a timestamp value to its string representation.
43
+ * Handles special values like AV_NOPTS_VALUE.
44
+ * Direct mapping to av_ts2str()
45
+ *
46
+ * @param ts - Timestamp value (bigint or number), or null
47
+ * @returns String representation
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { TimestampUtils } from 'node-av';
52
+ * import { AV_NOPTS_VALUE } from 'node-av/constants';
53
+ *
54
+ * console.log(TimestampUtils.toString(12345n)); // "12345"
55
+ * console.log(TimestampUtils.toString(AV_NOPTS_VALUE)); // "NOPTS"
56
+ * console.log(TimestampUtils.toString(null)); // "NOPTS"
57
+ * ```
58
+ */
59
+ static toString(ts) {
60
+ return bindings.avTs2Str(ts);
61
+ }
62
+ /**
63
+ * Convert timestamp to time string.
64
+ *
65
+ * Converts a timestamp to a time string in seconds using the provided time base.
66
+ * Direct mapping to av_ts2timestr()
67
+ *
68
+ * @param ts - Timestamp value
69
+ * @param timeBase - Time base for conversion
70
+ * @returns Time string in seconds with decimal places
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * import { TimestampUtils } from 'node-av';
75
+ *
76
+ * const pts = 450000n;
77
+ * const timebase = { num: 1, den: 90000 }; // 90kHz
78
+ *
79
+ * console.log(TimestampUtils.toTimeString(pts, timebase)); // "5.000000"
80
+ * console.log(TimestampUtils.toTimeString(90000n, timebase)); // "1.000000"
81
+ * ```
82
+ */
83
+ static toTimeString(ts, timeBase) {
84
+ return bindings.avTs2TimeStr(ts, timeBase);
85
+ }
86
+ /**
87
+ * Compare timestamps from different time bases.
88
+ *
89
+ * Compares two timestamps that may have different time bases.
90
+ * Direct mapping to av_compare_ts()
91
+ *
92
+ * @param tsA - First timestamp
93
+ * @param tbA - Time base of first timestamp
94
+ * @param tsB - Second timestamp
95
+ * @param tbB - Time base of second timestamp
96
+ * @returns -1 if tsA < tsB, 0 if equal, 1 if tsA > tsB
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * import { TimestampUtils } from 'node-av';
101
+ *
102
+ * // Compare timestamps from different time bases
103
+ * const pts1 = 90000n;
104
+ * const tb1 = { num: 1, den: 90000 }; // 1 second in 90kHz
105
+ *
106
+ * const pts2 = 1000n;
107
+ * const tb2 = { num: 1, den: 1000 }; // 1 second in 1kHz
108
+ *
109
+ * const result = TimestampUtils.compare(pts1, tb1, pts2, tb2);
110
+ * console.log(result); // 0 (equal - both represent 1 second)
111
+ * ```
112
+ */
113
+ static compare(tsA, tbA, tsB, tbB) {
114
+ return bindings.avCompareTs(tsA, tbA, tsB, tbB);
115
+ }
116
+ /**
117
+ * Rescale timestamp from one time base to another.
118
+ *
119
+ * Converts a timestamp from source time base to destination time base.
120
+ * Uses AV_ROUND_NEAR_INF rounding.
121
+ * Direct mapping to av_rescale_q()
122
+ *
123
+ * @param a - Timestamp to rescale
124
+ * @param bq - Source time base
125
+ * @param cq - Destination time base
126
+ * @returns Rescaled timestamp
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { TimestampUtils } from 'node-av';
131
+ *
132
+ * // Convert from 90kHz to milliseconds
133
+ * const pts = 450000n;
134
+ * const srcTb = { num: 1, den: 90000 };
135
+ * const dstTb = { num: 1, den: 1000 };
136
+ *
137
+ * const rescaled = TimestampUtils.rescale(pts, srcTb, dstTb);
138
+ * console.log(rescaled); // 5000n (5000 milliseconds = 5 seconds)
139
+ * ```
140
+ */
141
+ static rescale(a, bq, cq) {
142
+ return bindings.avRescaleQ(a, bq, cq);
143
+ }
144
+ /**
145
+ * Rescale with specified rounding.
146
+ *
147
+ * Rescales a value with explicit rounding mode.
148
+ * More general than rescale() as it doesn't use time bases.
149
+ * Direct mapping to av_rescale_rnd()
150
+ *
151
+ * @param a - Value to rescale
152
+ * @param b - Multiplier
153
+ * @param c - Divisor
154
+ * @param rnd - Rounding mode
155
+ * @returns Rescaled value: a * b / c
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * import { TimestampUtils } from 'node-av';
160
+ * import { AV_ROUND_UP, AV_ROUND_DOWN } from 'node-av/constants';
161
+ *
162
+ * // Scale with different rounding modes
163
+ * const value = 100n;
164
+ * const mul = 3n;
165
+ * const div = 7n;
166
+ *
167
+ * const roundUp = TimestampUtils.rescaleRounded(value, mul, div, AV_ROUND_UP);
168
+ * const roundDown = TimestampUtils.rescaleRounded(value, mul, div, AV_ROUND_DOWN);
169
+ *
170
+ * console.log(roundUp); // 43n (rounds up)
171
+ * console.log(roundDown); // 42n (rounds down)
172
+ * ```
173
+ */
174
+ static rescaleRounded(a, b, c, rnd) {
175
+ return bindings.avRescaleRnd(a, b, c, rnd);
176
+ }
177
+ /**
178
+ * Sleep for specified microseconds.
179
+ *
180
+ * Sleeps for the specified number of microseconds.
181
+ * Direct mapping to av_usleep()
182
+ *
183
+ * @param usec - Microseconds to sleep
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * import { TimestampUtils } from 'node-av';
188
+ *
189
+ * // Sleep for 100 milliseconds
190
+ * TimestampUtils.sleep(100000);
191
+ *
192
+ * // Sleep for 1 second
193
+ * TimestampUtils.sleep(1000000);
194
+ * ```
195
+ */
196
+ static sleep(usec) {
197
+ bindings.avUsleep(usec);
198
+ }
199
+ }
200
+ //# sourceMappingURL=timestamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../../src/api/utilities/timestamp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,cAAc;IACzB,+CAA+C;IAC/C,gBAAuB,CAAC;IAExB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,QAAQ,CAAC,EAA0B;QACxC,OAAO,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,YAAY,CAAC,EAA0B,EAAE,QAAmB;QACjE,OAAO,QAAQ,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,OAAO,CAAC,GAA2B,EAAE,GAAc,EAAE,GAA2B,EAAE,GAAc;QACrG,OAAO,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,OAAO,CAAC,CAAyB,EAAE,EAAa,EAAE,EAAa;QACpE,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,cAAc,CAAC,CAAkB,EAAE,CAAkB,EAAE,CAAkB,EAAE,GAAe;QAC/F,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Parse bitrate string to bigint.
3
+ *
4
+ * Supports suffixes: K (kilo), M (mega), G (giga).
5
+ *
6
+ * Converts human-readable bitrate strings to numeric values.
7
+ *
8
+ * @param str - Bitrate string (e.g., '5M', '192k')
9
+ *
10
+ * @returns Bitrate as bigint
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * parseBitrate('5M') // 5000000n
15
+ * parseBitrate('192k') // 192000n
16
+ * parseBitrate('1.5G') // 1500000000n
17
+ * ```
18
+ */
19
+ export declare function parseBitrate(str: string): bigint;
20
+ export interface Extension {
21
+ id: number;
22
+ payload: Buffer;
23
+ }
24
+ export declare const ExtensionProfiles: {
25
+ readonly OneByte: 48862;
26
+ readonly TwoByte: 4096;
27
+ };
28
+ type ExtensionProfile = (typeof ExtensionProfiles)[keyof typeof ExtensionProfiles];
29
+ export declare class RtpHeader {
30
+ version: number;
31
+ padding: boolean;
32
+ paddingSize: number;
33
+ extension: boolean;
34
+ marker: boolean;
35
+ payloadOffset: number;
36
+ payloadType: number;
37
+ sequenceNumber: number;
38
+ timestamp: number;
39
+ ssrc: number;
40
+ csrcLength: number;
41
+ csrc: number[];
42
+ extensionProfile: ExtensionProfile;
43
+ /** deserialize only */
44
+ extensionLength?: number;
45
+ extensions: Extension[];
46
+ constructor(props?: Partial<RtpHeader>);
47
+ static deSerialize(rawPacket: Buffer): RtpHeader;
48
+ get serializeSize(): number;
49
+ serialize(size: number): Buffer<ArrayBuffer>;
50
+ }
51
+ export declare class RtpPacket {
52
+ header: RtpHeader;
53
+ payload: Buffer;
54
+ constructor(header: RtpHeader, payload: Buffer);
55
+ get serializeSize(): number;
56
+ clone(): RtpPacket;
57
+ serialize(): Buffer<ArrayBuffer>;
58
+ static deSerialize(buf: Buffer): RtpPacket;
59
+ clear(): void;
60
+ }
61
+ export {};