diff --git a/server/package.json b/server/package.json index 061b2c9..abb34c7 100644 --- a/server/package.json +++ b/server/package.json @@ -4,6 +4,7 @@ "@types/express-ws": "^3.0.1", "@types/fluent-ffmpeg": "^2.1.20", "@types/js-yaml": "^4.0.5", + "@types/mp4frag": "^0.6.1", "@types/node": "^18.11.4", "@types/node-fetch": "^2.6.2", "@types/ws": "^8.5.3", diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index 8cb2abe..dfeca1a 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -5,6 +5,7 @@ specifiers: '@types/express-ws': ^3.0.1 '@types/fluent-ffmpeg': ^2.1.20 '@types/js-yaml': ^4.0.5 + '@types/mp4frag': ^0.6.1 '@types/node': ^18.11.4 '@types/node-fetch': ^2.6.2 '@types/ws': ^8.5.3 @@ -32,6 +33,7 @@ devDependencies: '@types/express-ws': 3.0.1 '@types/fluent-ffmpeg': 2.1.20 '@types/js-yaml': 4.0.5 + '@types/mp4frag': 0.6.1 '@types/node': 18.11.4 '@types/node-fetch': 2.6.2 '@types/ws': 8.5.3 @@ -131,6 +133,12 @@ packages: resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} dev: true + /@types/mp4frag/0.6.1: + resolution: {integrity: sha512-t5VL9dPiMmFwClo4j6tdVUhlflWtC3JKR046u/gOj7cNuCBR2DpmntMteiqOsFK2Ac5pMybShlHrPIPNQTWqKQ==} + dependencies: + '@types/node': 18.11.4 + dev: true + /@types/node-fetch/2.6.2: resolution: {integrity: sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==} dependencies: diff --git a/server/src/mp4frag.d.ts b/server/src/mp4frag.d.ts deleted file mode 100644 index 2e06ff9..0000000 --- a/server/src/mp4frag.d.ts +++ /dev/null @@ -1,155 +0,0 @@ -declare module 'mp4frag' { - import { Transform } from 'stream'; - - namespace Mp4Frag { - interface SegmentObject { - segment: Buffer; - sequence: number; - duration: number; - timestamp: number; - keyframe: number; - } - } - - export = Mp4Frag; - - /** - * @fileOverview - * - * @requires stream.Transform - */ - class Mp4Frag extends Transform { - /** - * @constructor - * @param {Object} [options] - Configuration options. - * @param {String} [options.hlsPlaylistBase] - Base name of files in m3u8 playlist. Affects the generated m3u8 playlist by naming file fragments. Must be set to generate m3u8 playlist. e.g. 'front_door' - * @param {Number} [options.hlsPlaylistSize = 4] - Number of segments to use in m3u8 playlist. Must be an integer ranging from 2 to 20. - * @param {Number} [options.hlsPlaylistExtra = 0] - Number of extra segments to keep in memory. Must be an integer ranging from 0 to 10. - * @param {Boolean} [options.hlsPlaylistInit = true] - Indicates that m3u8 playlist should be generated after [initialization]{@link Mp4Frag#initialization} is created and before media segments are created. - * @param {Number} [options.segmentCount = 2] - Number of segments to keep in memory. Has no effect if using options.hlsPlaylistBase. Must be an integer ranging from 2 to 30. - * @returns {Mp4Frag} this - Returns reference to new instance of Mp4Frag for chaining event listeners. - * @throws Will throw an error if options.hlsPlaylistBase contains characters other than letters(a-zA-Z) and underscores(_). - */ - constructor(options?: { - hlsPlaylistBase?: string; - hlsPlaylistSize?: number; - hlsPlaylistExtra?: number; - hlsPlaylistInit?: boolean; - segmentCount?: number; - }); - /** - * - Returns the audio codec information as a String. - * - * - Returns Null if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get audioCodec(): string | null; - /** - * - Returns the video codec information as a String. - * - * - Returns Null if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get videoCodec(): string | null; - /** - * - Returns the mime type information as a String. - * - * - Returns Null if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get mime(): string | null; - /** - * - Returns the Mp4 initialization fragment as a Buffer. - * - * - Returns Null if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get initialization(): Buffer | null; - /** - * - Returns the latest Mp4 segment as a Buffer. - * - * - Returns Null if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get segment(): Buffer | null; - /** - * - Returns the latest Mp4 segment as an Object. - * - * - {segment, sequence, duration, timestamp, keyframe} - * - * - Returns {segment: null, sequence: -1, duration: -1; timestamp: -1, keyframe: -1} if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get segmentObject(): Mp4Frag.SegmentObject; - /** - * - Returns the timestamp of the latest Mp4 segment as an Integer(milliseconds). - * - * - Returns -1 if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get timestamp(): number; - /** - * - Returns the duration of latest Mp4 segment as a Float(seconds). - * - * - Returns -1 if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get duration(): number; - /** - * - Returns the total duration of all Mp4 segments as a Float(seconds). - * - * - Returns -1 if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get totalDuration(): number; - /** - * - Returns the total byte length of the Mp4 initialization and all Mp4 segments as ant Int(bytes). - * - * - Returns -1 if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get totalByteLength(): number; - /** - * - Returns the fmp4 HLS m3u8 playlist as a String. - * - * - Returns Null if requested before [initialized event]{@link Mp4Frag#event:initialized}. - */ - get m3u8(): string | null; - /** - * - Returns the sequence of the latest Mp4 segment as an Integer. - * - * - Returns -1 if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get sequence(): number; - /** - * - Returns the nal keyframe index of the latest Mp4 segment as an Integer. - * - * - Returns -1 if segment contains no keyframe nal. - */ - get keyframe(): number; - /** - * - Returns a boolean indicating if all segments contain a keyframe. - * - * - Returns false if any segments do not contain a keyframe. - */ - get allKeyframes(): boolean; - /** - * - Returns the Mp4 segments as an Array of Objects - * - * - [{segment, sequence, duration, timestamp, keyframe},...] - * - * - Returns Null if requested before first [segment event]{@link Mp4Frag#event:segment}. - */ - get segmentObjects(): Mp4Frag.SegmentObject[]; - /** - * @param {Number|String} sequence - sequence number - * @returns {Object|null} - * - Returns the Mp4 segment that corresponds to the numbered sequence as an Object. - * - * - {segment, sequence, duration, timestamp, keyframe} - * - * - Returns Null if there is no segment that corresponds to sequence number. - */ - getSegmentObject(sequence: number | string): Mp4Frag.SegmentObject | null; - /** - * Clear cached values - */ - resetCache(): void; - } -}