From de3b0cdfd28a5ef9b7db8cc6b19a2ffa02f0823f Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 13 May 2023 18:12:09 +0600 Subject: [PATCH] last commit was extremely unsafe --- src/modules/stream/types.js | 9 ++++----- src/modules/sub/utils.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/modules/stream/types.js b/src/modules/stream/types.js index 8540dacb..6fee9a43 100644 --- a/src/modules/stream/types.js +++ b/src/modules/stream/types.js @@ -2,7 +2,7 @@ import { spawn } from "child_process"; import ffmpeg from "ffmpeg-static"; import got from "got"; import { ffmpegArgs, genericUserAgent } from "../config.js"; -import { metadataManager, msToTime } from "../sub/utils.js"; +import { getThreads, metadataManager, msToTime } from "../sub/utils.js"; export function streamDefault(streamInfo, res) { try { @@ -35,10 +35,9 @@ export function streamLiveRender(streamInfo, res) { return; } let audio = got.get(streamInfo.urls[1], { isStream: true }); - let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ '-loglevel', '-8', - '-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, + '-threads', `${getThreads()}`, '-i', streamInfo.urls[0], '-i', 'pipe:3', '-map', '0:v', @@ -96,7 +95,7 @@ export function streamAudioOnly(streamInfo, res) { try { let args = [ '-loglevel', '-8', - '-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, + '-threads', `${getThreads()}`, '-i', streamInfo.urls ] if (streamInfo.metadata) { @@ -143,7 +142,7 @@ export function streamVideoOnly(streamInfo, res) { try { let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ '-loglevel', '-8', - '-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, + '-threads', `${getThreads()}`, '-i', streamInfo.urls, '-c', 'copy' ] diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js index 27a17b82..48e6b7c7 100644 --- a/src/modules/sub/utils.js +++ b/src/modules/sub/utils.js @@ -139,3 +139,15 @@ export function checkJSONPost(obj) { export function getIP(req) { return req.header('cf-connecting-ip') ? req.header('cf-connecting-ip') : req.ip; } +export function getThreads() { + try { + if (process.env.ffmpegThreads && process.env.ffmpegThreads.length <= 3 + && (Number(process.env.ffmpegThreads) >= 0 && Number(process.env.ffmpegThreads) <= 256)) { + return process.env.ffmpegThreads + } else { + return '0' + } + } catch (e) { + return '0' + } +}