From 9751a5ee592d33c74ea28b6a9e4766b2d6955ff4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Dec 2023 23:56:32 +0100 Subject: [PATCH] nvenc support --- README.md | 5 ++++- src/main.ts | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6f79356..48432a8 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,17 @@ Helper for sharing video captured by NVidia Shadowplay in Discord. "REG ADD 'HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\dsr' /f /v InstallLocation /t REG_SZ /d '%LOCALAPPDATA%\DSR'" ``` - If you have nitro, add `/nitro` flag when running DSR. +> - If you have Discord Nitro: add `/nitro` flag when running DSR. +> - If you have an NVidia GPU with NVenc: add `/nvenc` flag when running DSR. + ## More info - [x] KISS interface - [x] Support drag&drop - [x] Keep the video under 25mb (discord limitation) + - [x] NVenc support - [x] If already under the limit, the file won't be compressed - [x] Nitro suppport via `/nitro` flag - [x] Merge all audio files into one track, while keeping the original ones (keeping track's title too) diff --git a/src/main.ts b/src/main.ts index 00dfa27..e7d3aff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -141,7 +141,7 @@ app.whenReady().then(() => { nbTracks: number ) => { const audioBitrate = 400; // keep some room - const videoBitrate = bitrate - audioBitrate; + let videoBitrate = bitrate - audioBitrate; const finalFile = getNewFilename(file, "Compressed - "); @@ -156,17 +156,30 @@ app.whenReady().then(() => { }) .join(" "); + let codec = "libx264"; + let hwAcc = ""; + + const argv = process.argv; + if (argv.includes("/nvenc")) { + // Use NVenc + codec = "h264_nvenc"; + hwAcc = "-hwaccel cuda"; + + // Increase video bitrate + videoBitrate = Math.floor(videoBitrate * 1.85); + } + // Compress the video // Add metadata to audio's track await execute( - `"${ffmpegPath}" -y \ + `"${ffmpegPath}" -y ${hwAcc} \ -i "${file}" \ - -c:v libx264 -b:v ${videoBitrate}k -pass 1 -an -f mp4 \ + -c:v ${codec} -b:v ${videoBitrate}k -pass 1 -an -f mp4 \ ${nul} \ && \ - "${ffmpegPath}" -y \ + "${ffmpegPath}" -y ${hwAcc} \ -i "${file}" \ - -c:v libx264 -b:v ${videoBitrate}k -pass 2 -c:a copy \ + -c:v ${codec} -b:v ${videoBitrate}k -pass 2 -c:a copy \ ${mappingTracks} -f mp4 \ ${metadataAudio} \ "${finalFile}"`