This commit is contained in:
fanxb 2024-03-27 21:12:10 +08:00
parent 1baeb09d5c
commit 523ed2fad1

View File

@ -4,6 +4,8 @@ const crypto = require('crypto');
const cmd = require('shelljs'); const cmd = require('shelljs');
const videoPath = "Z:\\";
const ignoreName = ["download", "冰海战记 (2019)"];
const cachePath = './cache.json'; const cachePath = './cache.json';
const hardTypeSet = new Set(["none", "qsv", "cuda"]); const hardTypeSet = new Set(["none", "qsv", "cuda"]);
const supportVideoTypeSet = new Set(["mkv", "mp4"]); const supportVideoTypeSet = new Set(["mkv", "mp4"]);
@ -21,7 +23,7 @@ function saveFile () {
if (fs.existsSync(cachePath)) { if (fs.existsSync(cachePath)) {
cache = JSON.parse(fs.readFileSync(cachePath, 'utf-8')); cache = JSON.parse(fs.readFileSync(cachePath, 'utf-8'));
} }
await deal("Z:\\userData\\视频", 3000, true, "cuda"); await deal(videoPath, 5000, true, "cuda");
if (timer) { if (timer) {
clearInterval(timer); clearInterval(timer);
} }
@ -47,6 +49,9 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType)
let fileList = fs.readdirSync(basePath); let fileList = fs.readdirSync(basePath);
for (let i in fileList) { for (let i in fileList) {
let name = fileList[i]; let name = fileList[i];
if (ignoreName.includes(name)) {
continue;
}
let filePath = path.join(basePath, name); let filePath = path.join(basePath, name);
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
continue; continue;
@ -81,8 +86,8 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType)
continue; continue;
} }
let is10Bit = res.streams.filter(item => item.bits_per_raw_sample === '10').length > 0; let is10Bit = res.streams.filter(item => item.bits_per_raw_sample === '10').length > 0;
let originBitRate = Math.round(parseInt(bitRate) / 1000); let originBitRate = Math.round(parseInt(bitRate) / 1000) * 0.7;
bitRate = originBitRate > maxBitRate ? maxBitRate : originBitRate * 0.7; bitRate = originBitRate > maxBitRate ? maxBitRate : originBitRate;
let newName = null; let newName = null;
replaceTextArr.forEach(item => { replaceTextArr.forEach(item => {
@ -105,7 +110,9 @@ async function deal (basePath, maxBitRate = 2500, changeName = false, hardType)
console.log("转换倍率:" + cmdRes.stderr.substring(index - 20)); console.log("转换倍率:" + cmdRes.stderr.substring(index - 20));
} }
if (!fs.existsSync(newFilePath) || fs.statSync(newFilePath).size <= 10000 || cmdRes.stderr.indexOf('Error') > -1) { if (!fs.existsSync(newFilePath) || fs.statSync(newFilePath).size <= 10000 || cmdRes.stderr.indexOf('Error') > -1) {
throw new Error("未知错误,文件转换失败"); console.error("未知错误,文件转换失败");
fs.removeSync(newFilePath);
continue;
} }
if (changeName) { if (changeName) {
//字幕nfo文件重命名 //字幕nfo文件重命名