nvenc support

This commit is contained in:
Mylloon 2023-12-02 23:56:32 +01:00
parent 40654c0581
commit 9751a5ee59
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 22 additions and 6 deletions

View file

@ -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.
</details>
> - 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)

View file

@ -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}"`