From 364ee37b8329814dcc15399ad21280d6d8bb4c8e Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 5 Nov 2022 13:58:50 +0600 Subject: [PATCH] rollback of previous commit + done some changes to piping --- package.json | 2 +- src/modules/stream/types.js | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index e042879..4868f71 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cobalt", "description": "save what you love", - "version": "4.2", + "version": "4.2.1", "author": "wukko", "exports": "./src/cobalt.js", "type": "module", diff --git a/src/modules/stream/types.js b/src/modules/stream/types.js index fb15598..b2d386f 100644 --- a/src/modules/stream/types.js +++ b/src/modules/stream/types.js @@ -28,23 +28,24 @@ export function streamLiveRender(streamInfo, res) { if (streamInfo.urls.length === 2) { let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ '-loglevel', '-8', - '-i', streamInfo.urls[1], '-i', streamInfo.urls[0], - '-map', '0:a', - '-map', '1:v', + '-i', streamInfo.urls[1], + '-map', '0:v', + '-map', '1:a', ]; args = args.concat(ffmpegArgs[format]) if (streamInfo.time) args.push('-t', msToTime(streamInfo.time)); - args.push('-f', format, 'pipe:4'); + args.push('-f', format, 'pipe:3'); const ffmpegProcess = spawn(ffmpeg, args, { windowsHide: true, stdio: [ 'inherit', 'inherit', 'inherit', - 'pipe', 'pipe', + 'pipe' ], }); + res.setHeader('Connection', 'keep-alive'); res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename}"`); - ffmpegProcess.stdio[4].pipe(res); + ffmpegProcess.stdio[3].pipe(res); ffmpegProcess.on('error', (err) => { ffmpegProcess.kill(); @@ -75,21 +76,22 @@ export function streamAudioOnly(streamInfo, res) { args = args.concat(arg) if (streamInfo.metadata.cover) args.push("-c:v", "mjpeg") if (ffmpegArgs[streamInfo.audioFormat]) args = args.concat(ffmpegArgs[streamInfo.audioFormat]); - args.push('-f', streamInfo.audioFormat === "m4a" ? "ipod" : streamInfo.audioFormat, 'pipe:4'); + args.push('-f', streamInfo.audioFormat === "m4a" ? "ipod" : streamInfo.audioFormat, 'pipe:3'); const ffmpegProcess = spawn(ffmpeg, args, { windowsHide: true, stdio: [ 'inherit', 'inherit', 'inherit', - 'pipe', 'pipe' + 'pipe' ], }); + res.setHeader('Connection', 'keep-alive'); + res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename}.${streamInfo.audioFormat}"`); + ffmpegProcess.stdio[3].pipe(res); + ffmpegProcess.on('error', (err) => { ffmpegProcess.kill(); res.end(); }); - res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename}.${streamInfo.audioFormat}"`); - ffmpegProcess.stdio[4].pipe(res); - } catch (e) { res.end(); }