This commit is contained in:
fanxb 2022-11-06 19:48:32 +08:00
parent 0f1ebb43d9
commit 10d1755437
5 changed files with 166 additions and 0 deletions

64
index.js Normal file
View File

@ -0,0 +1,64 @@
const fs = require('fs-extra');
const path = require('path');
const cmd = require('child_process');
async function deal (basePath) {
let fileList = fs.readdirSync(basePath);
for (let i in fileList) {
let name = fileList[i];
if (!name.endsWith('.mkv') && !name.endsWith('.mp4')) {
continue;
}
console.log("---------开始处理:" + name);
let filePath = path.join(basePath, name);
let res = JSON.parse(cmd.execSync(`ffprobe.exe "${filePath}" -show_streams -select_streams v -show_format -print_format json`, { encoding: 'utf-8' }));
if (!res.format || !res.streams || res.streams.length == 0) {
console.log("无法识别的格式:" + JSON.stringify(res));
continue;
}
let isH264 = res.streams.filter(item => item.codec_name === 'h264').length > 0;
if (!isH264) {
console.log("非h264,不处理");
continue;
}
let bitRate = res.format.bit_rate;
if (!bitRate) {
console.log("未获取到帧率,不处理", JSON.stringify(res));
continue;
}
bitRate = Math.round(parseInt(bitRate) / 1000);
bitRate = bitRate > 2500 ? 2500 : bitRate;
let newName;
if (name.indexOf("h264") > -1) {
newName = name.replace('h264', 'h265');
} else if (name.indexOf('H264') > -1) {
newName = name.replace('H264', 'H265');
} else {
let index = name.lastIndexOf('.');
newName = name.substr(0, index) + ".h265" + name.substr(index);
}
let cmdStr = `ffmpeg.exe -hwaccel cuda -c:v h264_cuvid -i "${filePath}" -c:v hevc_nvenc -maxrate ${bitRate}K -c:a copy "${path.join(basePath, newName)}"`;
console.log(cmdStr);
let changeRes = cmd.execSync(cmdStr, { encoding: 'utf-8' });
console.log(changeRes);
//字幕nfo文件重命名
let namePart1 = name.substr(0, name.lastIndexOf('.'));
let newNamePart1 = newName.substr(0, newName.lastIndexOf('.'));
fileList.forEach(item => {
if (item.startsWith(namePart1) && (item.endsWith('.nfo') || item.endsWith('.srt') || item.endsWith('.ass'))) {
let temp = item.replace(namePart1, newNamePart1);
if (item != temp) {
fs.renameSync(path.join(basePath, item), path.join(basePath, temp));
}
}
})
fs.removeSync(filePath);
}
}
(async () => {
await deal("Z:/无耻之徒.Shameless.美版/season 09");
await deal("Z:/无耻之徒.Shameless.美版/season 10");
await deal("Z:/无耻之徒.Shameless.美版/season 11");
})();

84
package-lock.json generated Normal file
View File

@ -0,0 +1,84 @@
{
"name": "ffmpeg-video",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ffmpeg-video",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"fs-extra": "^10.1.0"
}
},
"node_modules/fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/graceful-fs": {
"version": "4.2.10",
"resolved": "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
},
"node_modules/jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmmirror.com/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
"engines": {
"node": ">= 10.0.0"
}
}
},
"dependencies": {
"fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
}
},
"graceful-fs": {
"version": "4.2.10",
"resolved": "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA=="
},
"jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmmirror.com/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"requires": {
"graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
}
},
"universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
}
}
}

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "ffmpeg-video",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"fs-extra": "^10.1.0"
}
}

2
run.bat Normal file
View File

@ -0,0 +1,2 @@
@REM 核显解码nv独显编码,平均码率2.5m
ffmpeg.exe -hwaccel cuda -c:v h264_cuvid -i ./Shameless.1080p.h264.s11e01.mkv -c:v hevc_nvenc -maxrate 2500K -c:a copy ./newShameless1.1080p.h264.s11e01.mkv

2
runqsv.bat Normal file
View File

@ -0,0 +1,2 @@
ffmpeg.exe -i "./Shameless.1080p.h264.s11e01.mkv" -c:v hevc_qsv -c:a copy "./newQsvShameless.1080p.h264.s11e01.mkv" -x265-params lossless=1
ffmpeg.exe -hwaccel cuvid -c:v h263_cuvid -i ./Shameless.1080p.h264.s11e01.mkv -c:v hevc_nvenc -b:v 2548k ./newShameless.1080p.h264.s11e01.mkv