From 99ae832ec82926539c3f8e48654432e1451a50ac Mon Sep 17 00:00:00 2001 From: daniel-zh23 Date: Tue, 30 Aug 2022 10:29:11 +0300 Subject: [PATCH] Added support for vercel/pkg. Creating temp folder in directory for ffmpeg executable. --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fc4e152..1135627 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,23 @@ const { spawn } = require('child_process'); const ews = require('express-ws'); const ps = require('ps-node'); const { version } = require('./package.json'); +const fs = require('fs'); +const path = require('path'); + +const copy = async (source, target) => { + fs.mkdirSync(process.cwd() + '\\temp'); + await (fs.createReadStream(source).pipe(fs.createWriteStream(target))); +} + +let target; +//@ts-ignore +if (process.pkg) { + target = path.join(process.cwd() + '\\temp' + '\\ffmpeg.exe'); +copy(ffmpegPath, target).then(d => { + fs.chmodSync(target, 0o765); +} +).catch(e => console.log(e.message)); +} /** * @typedef {{ @@ -39,7 +56,8 @@ class InboundStreamWrapper { } this.stream = spawn( - ffmpegPath, + //@ts-ignore + process.pkg ? target : ffmpegPath,, [ ...(transport ? ['-rtsp_transport', transport] : []), // this must come before `-i [url]`, see #82 '-i',