linting
This commit is contained in:
parent
807e50388a
commit
832189a346
10 changed files with 518 additions and 299 deletions
|
@ -1,9 +1,13 @@
|
|||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import ffmpegInstaller from '@ffmpeg-installer/ffmpeg';
|
||||
import ffprobeInstaller from '@ffprobe-installer/ffprobe';
|
||||
import which from 'which';
|
||||
import ffmpeg from "fluent-ffmpeg";
|
||||
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
|
||||
import ffprobeInstaller from "@ffprobe-installer/ffprobe";
|
||||
import which from "which";
|
||||
|
||||
const getExecutablePath = (envVar: string, executable: string, installer: { path: string }) => {
|
||||
const getExecutablePath = (
|
||||
envVar: string,
|
||||
executable: string,
|
||||
installer: { path: string },
|
||||
) => {
|
||||
if (process.env[envVar]) {
|
||||
return process.env[envVar];
|
||||
}
|
||||
|
@ -15,8 +19,16 @@ const getExecutablePath = (envVar: string, executable: string, installer: { path
|
|||
}
|
||||
};
|
||||
|
||||
const ffmpegPath = getExecutablePath('EB_FFMPEG_PATH', 'ffmpeg', ffmpegInstaller);
|
||||
const ffprobePath = getExecutablePath('EB_FFPROBE_PATH', 'ffprobe', ffprobeInstaller);
|
||||
const ffmpegPath = getExecutablePath(
|
||||
"EB_FFMPEG_PATH",
|
||||
"ffmpeg",
|
||||
ffmpegInstaller,
|
||||
);
|
||||
const ffprobePath = getExecutablePath(
|
||||
"EB_FFPROBE_PATH",
|
||||
"ffprobe",
|
||||
ffprobeInstaller,
|
||||
);
|
||||
|
||||
console.log(`Using ffmpeg from path: ${ffmpegPath}`);
|
||||
console.log(`Using ffprobe from path: ${ffprobePath}`);
|
||||
|
@ -25,65 +37,76 @@ ffmpeg.setFfmpegPath(ffmpegPath!);
|
|||
ffmpeg.setFfprobePath(ffprobePath!);
|
||||
|
||||
export enum EncodingType {
|
||||
CPU = 'libx264',
|
||||
NVIDIA = 'h264_nvenc',
|
||||
AMD = 'h264_amf',
|
||||
INTEL = 'h264_qsv',
|
||||
APPLE = 'h264_videotoolbox',
|
||||
CPU = "libx264",
|
||||
NVIDIA = "h264_nvenc",
|
||||
AMD = "h264_amf",
|
||||
INTEL = "h264_qsv",
|
||||
APPLE = "h264_videotoolbox",
|
||||
}
|
||||
|
||||
export const generateTestVideo = async (encodingType: EncodingType): Promise<void> => {
|
||||
export const generateTestVideo = async (
|
||||
encodingType: EncodingType,
|
||||
): Promise<void> => {
|
||||
console.log(`Generating test video using ${encodingType}...`);
|
||||
|
||||
const startTime = Date.now();
|
||||
let totalFrames = 0;
|
||||
|
||||
const outputOptions = [
|
||||
'-vf', 'scale=-2:720',
|
||||
'-vcodec', encodingType,
|
||||
'-c:a', 'copy',
|
||||
'-b:v', '5000k',
|
||||
'-pix_fmt', 'yuv420p',
|
||||
"-vf",
|
||||
"scale=-2:720",
|
||||
"-vcodec",
|
||||
encodingType,
|
||||
"-c:a",
|
||||
"copy",
|
||||
"-b:v",
|
||||
"5000k",
|
||||
"-pix_fmt",
|
||||
"yuv420p",
|
||||
];
|
||||
|
||||
// Adjust output options based on encoder for maximum quality
|
||||
switch(encodingType) {
|
||||
switch (encodingType) {
|
||||
case EncodingType.CPU:
|
||||
//outputOptions.push('-crf', '0');
|
||||
break;
|
||||
case EncodingType.NVIDIA:
|
||||
outputOptions.push('-rc', 'cqp', '-qp', '0');
|
||||
outputOptions.push("-rc", "cqp", "-qp", "0");
|
||||
break;
|
||||
case EncodingType.AMD:
|
||||
outputOptions.push('-qp_i', '0', '-qp_p', '0', '-qp_b', '0');
|
||||
outputOptions.push("-qp_i", "0", "-qp_p", "0", "-qp_b", "0");
|
||||
break;
|
||||
case EncodingType.INTEL:
|
||||
outputOptions.push('-global_quality', '1'); // Intel QSV specific setting for high quality
|
||||
outputOptions.push("-global_quality", "1"); // Intel QSV specific setting for high quality
|
||||
break;
|
||||
case EncodingType.APPLE:
|
||||
outputOptions.push('-global_quality', '1');
|
||||
outputOptions.push("-global_quality", "1");
|
||||
break;
|
||||
}
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
ffmpeg()
|
||||
.input('unknown_replay_2023.10.29-22.57-00.00.38.103-00.01.00.016.mp4')
|
||||
.inputFormat('mp4')
|
||||
.input("unknown_replay_2023.10.29-22.57-00.00.38.103-00.01.00.016.mp4")
|
||||
.inputFormat("mp4")
|
||||
.outputOptions(outputOptions)
|
||||
.output(`720p-test-${encodingType}.mp4`)
|
||||
.on('progress', (progress) => {
|
||||
.on("progress", (progress) => {
|
||||
totalFrames = progress.frames;
|
||||
})
|
||||
.on('end', () => {
|
||||
const elapsedTime = (Date.now() - startTime) / 1000; // Convert to seconds
|
||||
.on("end", () => {
|
||||
const elapsedTime = (Date.now() - startTime) / 1000; // Convert to seconds
|
||||
const avgFps = totalFrames / elapsedTime;
|
||||
|
||||
console.log(`720p copy complete using ${encodingType}, took ${Date.now() - startTime}ms to complete`);
|
||||
|
||||
console.log(
|
||||
`720p copy complete using ${encodingType}, took ${
|
||||
Date.now() - startTime
|
||||
}ms to complete`,
|
||||
);
|
||||
console.log(`Average FPS for the entire process: ${avgFps.toFixed(2)}`);
|
||||
|
||||
|
||||
resolve();
|
||||
})
|
||||
.on('error', (e) => reject(new Error(e)))
|
||||
.on("error", (e) => reject(new Error(e)))
|
||||
.run();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import readline from 'readline';
|
||||
import readline from "readline";
|
||||
import { generateTestVideo, EncodingType } from "./ffmpeg";
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
const questionAsync = (query: string) => {
|
||||
return new Promise<string>(resolve => {
|
||||
return new Promise<string>((resolve) => {
|
||||
rl.question(query, resolve);
|
||||
});
|
||||
};
|
||||
|
@ -16,27 +16,31 @@ const main = async () => {
|
|||
console.log("Testing software encoder: ");
|
||||
await generateTestVideo(EncodingType.CPU).catch(console.error);
|
||||
|
||||
const answer = await questionAsync('Would you like to test other hardware encoders? (yes/no): ');
|
||||
const answer = await questionAsync(
|
||||
"Would you like to test other hardware encoders? (yes/no): ",
|
||||
);
|
||||
|
||||
if (answer.toLowerCase() === 'yes') {
|
||||
const encoder = await questionAsync('Which hardware encoder would you like to test? (INTEL/NVIDIA/AMD/APPLE): ');
|
||||
if (answer.toLowerCase() === "yes") {
|
||||
const encoder = await questionAsync(
|
||||
"Which hardware encoder would you like to test? (INTEL/NVIDIA/AMD/APPLE): ",
|
||||
);
|
||||
let selectedEncoder: EncodingType;
|
||||
|
||||
switch (encoder.toUpperCase()) {
|
||||
case 'INTEL':
|
||||
case "INTEL":
|
||||
selectedEncoder = EncodingType.INTEL;
|
||||
break;
|
||||
case 'NVIDIA':
|
||||
case "NVIDIA":
|
||||
selectedEncoder = EncodingType.NVIDIA;
|
||||
break;
|
||||
case 'AMD':
|
||||
case "AMD":
|
||||
selectedEncoder = EncodingType.AMD;
|
||||
break;
|
||||
case 'APPLE':
|
||||
case "APPLE":
|
||||
selectedEncoder = EncodingType.APPLE;
|
||||
break;
|
||||
default:
|
||||
console.log('Invalid choice. Exiting.');
|
||||
console.log("Invalid choice. Exiting.");
|
||||
rl.close();
|
||||
return;
|
||||
}
|
||||
|
@ -46,11 +50,11 @@ const main = async () => {
|
|||
} else {
|
||||
console.log("Exiting.");
|
||||
}
|
||||
|
||||
|
||||
rl.close();
|
||||
};
|
||||
|
||||
main().catch(err => {
|
||||
main().catch((err) => {
|
||||
console.error("An error occurred:", err);
|
||||
rl.close();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue