diff --git a/plugins/ffmpeg-camera/package-lock.json b/plugins/ffmpeg-camera/package-lock.json index df9072591..2ad3b4d73 100644 --- a/plugins/ffmpeg-camera/package-lock.json +++ b/plugins/ffmpeg-camera/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/ffmpeg-camera", - "version": "0.0.15", + "version": "0.0.16", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/ffmpeg-camera", - "version": "0.0.15", + "version": "0.0.16", "hasInstallScript": true, "license": "Apache", "dependencies": { diff --git a/plugins/ffmpeg-camera/package.json b/plugins/ffmpeg-camera/package.json index 6fe21be5a..2dd5e56e6 100644 --- a/plugins/ffmpeg-camera/package.json +++ b/plugins/ffmpeg-camera/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/ffmpeg-camera", - "version": "0.0.15", + "version": "0.0.16", "description": "FFmpeg Camera Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/ffmpeg-camera/src/main.ts b/plugins/ffmpeg-camera/src/main.ts index b98fd6a07..ddf329b41 100644 --- a/plugins/ffmpeg-camera/src/main.ts +++ b/plugins/ffmpeg-camera/src/main.ts @@ -6,7 +6,17 @@ import child_process, { ChildProcess } from "child_process"; const { mediaManager } = sdk; -class FFmpegCamera extends CameraBase implements Intercom { +function parseDoubleQuotedArguments(input: string) { + const regex = new RegExp('"[^"]+"|[\\S]+', 'g'); + const parsed: string[] = []; + input.match(regex).forEach(element => { + if (!element) return; + return parsed.push(element.replace(/"/g, '')); + }); + return parsed; +} + +class FFmpegCamera extends CameraBase { takePictureThrottled(option?: PictureOptions): Promise { throw new Error("The RTSP Camera does not provide snapshots. Install the Snapshot Plugin if snapshots are available via an URL."); } @@ -18,39 +28,39 @@ class FFmpegCamera extends CameraBase implements Intercom placeholder: '-i rtmp://[user:password@]192.168.1.100[:1935]/channel/101', multiple: true, }, - ffmpegOutput: { - title: 'FFmpeg Output Stream Arguments', - description: 'Optional (two way audio): FFmpeg output arguments passed to the command line ffmpeg tool to play back an audio stream.', - placeholder: '-vn -acodec copy -f adts udp://192.168.1.101:1234', - onPut: (_, newValue) => { - let interfaces = this.providedInterfaces; - if (!newValue) - interfaces = interfaces.filter(iface => iface !== ScryptedInterface.Intercom); - else - interfaces.push(ScryptedInterface.Intercom); - this.provider.updateDevice(this.nativeId, this.providedName, interfaces); - }, - }, + // ffmpegOutput: { + // title: 'FFmpeg Output Stream Arguments', + // description: 'Optional (two way audio): FFmpeg output arguments passed to the command line ffmpeg tool to play back an audio stream.', + // placeholder: '-vn -acodec copy -f adts udp://192.168.1.101:1234', + // onPut: (_, newValue) => { + // let interfaces = this.providedInterfaces; + // if (!newValue) + // interfaces = interfaces.filter(iface => iface !== ScryptedInterface.Intercom); + // else + // interfaces.push(ScryptedInterface.Intercom); + // this.provider.updateDevice(this.nativeId, this.providedName, interfaces); + // }, + // }, }) - twoway: ChildProcess; + // twoway: ChildProcess; - async startIntercom(media: MediaObject): Promise { - const buffer = await mediaManager.convertMediaObjectToBuffer(media, ScryptedMimeTypes.FFmpegInput); - const ffmpegInput: FFmpegInput = JSON.parse(buffer.toString()); + // async startIntercom(media: MediaObject): Promise { + // const buffer = await mediaManager.convertMediaObjectToBuffer(media, ScryptedMimeTypes.FFmpegInput); + // const ffmpegInput: FFmpegInput = JSON.parse(buffer.toString()); - const args = ffmpegInput.inputArguments.slice(); - args.push(...this.storageSettings.values.ffmpegOutput.split(' ')); - this.console.log('starting intercom', safePrintFFmpegArguments(this.console, args)); - this.stopIntercom(); - this.twoway = child_process.spawn(await mediaManager.getFFmpegPath(), args); - ffmpegLogInitialOutput(this.console, this.twoway); - } + // const args = ffmpegInput.inputArguments.slice(); + // args.push(...this.storageSettings.values.ffmpegOutput.split(' ')); + // this.console.log('starting intercom', safePrintFFmpegArguments(this.console, args)); + // this.stopIntercom(); + // this.twoway = child_process.spawn(await mediaManager.getFFmpegPath(), args); + // ffmpegLogInitialOutput(this.console, this.twoway); + // } - async stopIntercom(): Promise { - this.twoway?.kill('SIGKILL'); - this.twoway = undefined; - } + // async stopIntercom(): Promise { + // this.twoway?.kill('SIGKILL'); + // this.twoway = undefined; + // } createFFmpegMediaStreamOptions(ffmpegInput: string, index: number) { // this might be usable as a url so check that. @@ -71,7 +81,7 @@ class FFmpegCamera extends CameraBase implements Intercom } getRawVideoStreamOptions(): UrlMediaStreamOptions[] { - const ffmpegInputs = this.storageSettings.values.ffmpegInputs; + const ffmpegInputs = this.storageSettings.values.ffmpegInputs as string[]; // filter out empty strings. const ret = ffmpegInputs @@ -105,7 +115,7 @@ class FFmpegCamera extends CameraBase implements Intercom async createVideoStream(options?: UrlMediaStreamOptions): Promise { const index = this.getRawVideoStreamOptions()?.findIndex(vso => vso.id === options.id); - const ffmpegInputs = this.storageSettings.values.ffmpegInputs; + const ffmpegInputs = this.storageSettings.values.ffmpegInputs as string[]; const ffmpegInput = ffmpegInputs[index]; if (!ffmpegInput) @@ -113,7 +123,7 @@ class FFmpegCamera extends CameraBase implements Intercom const ret: FFmpegInput = { url: options.url, - inputArguments: ffmpegInput.split(' '), + inputArguments: parseDoubleQuotedArguments(ffmpegInput), mediaStreamOptions: options, };