From 612677195e7b8ca1c1b2b86ccd2fda691caf5b7f Mon Sep 17 00:00:00 2001 From: fanxb Date: Sun, 6 Nov 2022 19:50:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 43bd11b..a9f7e89 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ async function deal (basePath) { continue; } console.log("---------开始处理:" + name); - let filePath = path.join(basePath, 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)); @@ -38,10 +38,15 @@ async function deal (basePath) { 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)}"`; + let newFilePath = path.join(basePath, newName); + let cmdStr = `ffmpeg.exe -hwaccel cuda -c:v h264_cuvid -i "${filePath}" -c:v hevc_nvenc -maxrate ${bitRate}K -c:a copy "${newFilePath}"`; console.log(cmdStr); let changeRes = cmd.execSync(cmdStr, { encoding: 'utf-8' }); console.log(changeRes); + if (!fs.existsSync(newFilePath)) { + console.log("未知错误,文件转换失败"); + return; + } //字幕,nfo文件重命名 let namePart1 = name.substr(0, name.lastIndexOf('.')); let newNamePart1 = newName.substr(0, newName.lastIndexOf('.'));