last commit was extremely unsafe

This commit is contained in:
wukko 2023-05-13 18:12:09 +06:00
parent 64987c6494
commit de3b0cdfd2
2 changed files with 16 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import { spawn } from "child_process";
import ffmpeg from "ffmpeg-static"; import ffmpeg from "ffmpeg-static";
import got from "got"; import got from "got";
import { ffmpegArgs, genericUserAgent } from "../config.js"; 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) { export function streamDefault(streamInfo, res) {
try { try {
@ -35,10 +35,9 @@ export function streamLiveRender(streamInfo, res) {
return; return;
} }
let audio = got.get(streamInfo.urls[1], { isStream: true }); let audio = got.get(streamInfo.urls[1], { isStream: true });
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [
'-loglevel', '-8', '-loglevel', '-8',
'-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, '-threads', `${getThreads()}`,
'-i', streamInfo.urls[0], '-i', streamInfo.urls[0],
'-i', 'pipe:3', '-i', 'pipe:3',
'-map', '0:v', '-map', '0:v',
@ -96,7 +95,7 @@ export function streamAudioOnly(streamInfo, res) {
try { try {
let args = [ let args = [
'-loglevel', '-8', '-loglevel', '-8',
'-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, '-threads', `${getThreads()}`,
'-i', streamInfo.urls '-i', streamInfo.urls
] ]
if (streamInfo.metadata) { if (streamInfo.metadata) {
@ -143,7 +142,7 @@ export function streamVideoOnly(streamInfo, res) {
try { try {
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [
'-loglevel', '-8', '-loglevel', '-8',
'-threads', `${process.env.ffmpegThreads ? process.env.ffmpegThreads : '0'}`, '-threads', `${getThreads()}`,
'-i', streamInfo.urls, '-i', streamInfo.urls,
'-c', 'copy' '-c', 'copy'
] ]

View file

@ -139,3 +139,15 @@ export function checkJSONPost(obj) {
export function getIP(req) { export function getIP(req) {
return req.header('cf-connecting-ip') ? req.header('cf-connecting-ip') : req.ip; 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'
}
}