Skip to content

Commit be97fe2

Browse files
committed
Limit FFmpeg thread usage to 16 CPUs in video processing
1 parent 013a739 commit be97fe2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/vmaf.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FastStats } from './stats'
88

99
const log = logger('webrtcperf:vmaf')
1010

11-
const cpus = Math.min(os.cpus().length, 16)
11+
const cpus = os.cpus().length
1212

1313
export interface IvfFrame {
1414
pts: number
@@ -73,7 +73,7 @@ export async function prepareVideo(
7373
const textHeight = Math.round(fontsize * 1.2)
7474
const filter = vmafVideoCrop ? cropFilter(json5.parse(vmafVideoCrop), 0, ',') : ''
7575
await runShellCommand(
76-
`ffmpeg -hide_banner -loglevel warning -threads ${cpus} \
76+
`ffmpeg -hide_banner -loglevel warning -threads ${Math.min(cpus, 16)} \
7777
${videoDuration ? `-t ${videoDuration}` : ''} \
7878
-i ${fpath} \
7979
-filter_complex "[0:v]scale=w=${videoWidth || width}:h=${videoHeight || height},fps=${videoFramerate || frameRate},${filter}\
@@ -104,7 +104,7 @@ export async function convertToIvf(fpath: string, crop?: string, keepSourceFile
104104
await runShellCommand(
105105
`ffmpeg -y -hide_banner -y -loglevel warning -i ${fpath} -map 0:v \
106106
-c:v vp8 -quality best -cpu-used 0 -crf 1 -b:v 20M -qmin 1 -qmax 10 \
107-
-g 1 -threads ${cpus} ${filter} -an \
107+
-g 1 -threads ${Math.min(cpus, 16)} ${filter} -an \
108108
-f ivf ${outputPath}`,
109109
true,
110110
)
@@ -502,7 +502,7 @@ export async function runVmaf(
502502
},
503503
)
504504

505-
const ffmpegCmd = `ffmpeg -hide_banner -loglevel warning -y -threads ${cpus} \
505+
const ffmpegCmd = `ffmpeg -hide_banner -loglevel warning -y -threads ${Math.min(cpus, 16)} \
506506
-i ${degradedPath} \
507507
-i ${referencePath} \
508508
`

0 commit comments

Comments
 (0)