Compare commits
No commits in common. "55b94d0021d4b7d4f5d2ffba9aab2ffbe599e99b" and "7c4bd844862fb9300185527d8a5dd99221dd4e45" have entirely different histories.
55b94d0021
...
7c4bd84486
3 changed files with 41 additions and 61 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsr",
|
||||
"version": "1.11.1",
|
||||
"version": "1.11.0",
|
||||
"description": "Discord Video Sharing",
|
||||
"main": "./dist/main.js",
|
||||
"scripts": {
|
||||
|
|
81
src/main.ts
81
src/main.ts
|
@ -144,9 +144,7 @@ app.whenReady().then(() => {
|
|||
};
|
||||
};
|
||||
|
||||
/** Reduce size of a file
|
||||
* Returns an empty string in case of failing
|
||||
*/
|
||||
/** Reduce size of a file */
|
||||
const reduceSize = async (
|
||||
file: string,
|
||||
bitrate: number,
|
||||
|
@ -155,48 +153,46 @@ app.whenReady().then(() => {
|
|||
const audioBitrate = Math.ceil(
|
||||
audioTracks.reduce((sum, current) => current + sum, 0)
|
||||
);
|
||||
const videoBitrate = bitrate - audioBitrate;
|
||||
let finalFile;
|
||||
let videoBitrate = bitrate - audioBitrate;
|
||||
|
||||
if (videoBitrate > 0) {
|
||||
finalFile = getNewFilename(file, "Compressed - ");
|
||||
const finalFile = getNewFilename(file, "Compressed - ");
|
||||
|
||||
// Trash the output, depends on the platform
|
||||
const nul = process.platform === "win32" ? "NUL" : "/dev/null";
|
||||
// Trash the output, depends on the platform
|
||||
const nul = process.platform === "win32" ? "NUL" : "/dev/null";
|
||||
|
||||
// Mapping of tracks for FFMPEG, adding 1 for the video stream
|
||||
const mappingTracks = Array(audioTracks.length + 1)
|
||||
.fill("-map 0:")
|
||||
.map((str, index) => {
|
||||
return str + index;
|
||||
})
|
||||
.join(" ");
|
||||
// Mapping of tracks for FFMPEG, adding 1 for the video stream
|
||||
const mappingTracks = Array(audioTracks.length + 1)
|
||||
.fill("-map 0:")
|
||||
.map((str, index) => {
|
||||
return str + index;
|
||||
})
|
||||
.join(" ");
|
||||
|
||||
let codec = "libx264";
|
||||
let hwAcc = "";
|
||||
let codec = "libx264";
|
||||
let hwAcc = "";
|
||||
|
||||
const argv = process.argv;
|
||||
if (argv.includes("/nvenc_h264")) {
|
||||
// Use NVenc H.264
|
||||
codec = "h264_nvenc";
|
||||
hwAcc = "-hwaccel cuda";
|
||||
}
|
||||
const argv = process.argv;
|
||||
if (argv.includes("/nvenc_h264")) {
|
||||
// Use NVenc H.264
|
||||
codec = "h264_nvenc";
|
||||
hwAcc = "-hwaccel cuda";
|
||||
}
|
||||
|
||||
if (argv.includes("/nvenc_h265")) {
|
||||
// Use NVenc H.265
|
||||
codec = "hevc_nvenc";
|
||||
hwAcc = "-hwaccel cuda";
|
||||
}
|
||||
if (argv.includes("/nvenc_h265")) {
|
||||
// Use NVenc H.265
|
||||
codec = "hevc_nvenc";
|
||||
hwAcc = "-hwaccel cuda";
|
||||
}
|
||||
|
||||
if (argv.includes("/h265")) {
|
||||
// Use H.265 encoder
|
||||
codec = "libx265";
|
||||
}
|
||||
if (argv.includes("/h265")) {
|
||||
// Use H.265 encoder
|
||||
codec = "libx265";
|
||||
}
|
||||
|
||||
// Compress the video
|
||||
// Add metadata to audio's track
|
||||
await execute(
|
||||
`"${ffmpegPath}" -y ${hwAcc} \
|
||||
// Compress the video
|
||||
// Add metadata to audio's track
|
||||
await execute(
|
||||
`"${ffmpegPath}" -y ${hwAcc} \
|
||||
-i "${file}" \
|
||||
-c:v ${codec} -b:v ${videoBitrate}k -pass 1 -an -f mp4 \
|
||||
${nul} \
|
||||
|
@ -209,17 +205,14 @@ app.whenReady().then(() => {
|
|||
${audioTracks.length === metadataAudioSize ? metadataAudio : ""} \
|
||||
${shareOpt} \
|
||||
"${finalFile}"`
|
||||
).catch((e) => registerError(win, e));
|
||||
|
||||
// Delete the 2 pass temporary files
|
||||
deleteTwoPassFiles(process.cwd());
|
||||
} else {
|
||||
finalFile = "";
|
||||
}
|
||||
).catch((e) => registerError(win, e));
|
||||
|
||||
// Delete the old video file
|
||||
deleteFile(file);
|
||||
|
||||
// Delete the 2 pass temporary files
|
||||
deleteTwoPassFiles(process.cwd());
|
||||
|
||||
return finalFile;
|
||||
};
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ const main = async () => {
|
|||
updateMessage("Récupération des fichiers...");
|
||||
const files = await getFiles();
|
||||
let processedFiles = "";
|
||||
let numberOfUncompressableFiles = 0;
|
||||
|
||||
// Iterate over all the retrieved files
|
||||
for (const [idx, file] of files.entries()) {
|
||||
|
@ -149,26 +148,14 @@ const main = async () => {
|
|||
}
|
||||
|
||||
// Append title to the list of processed files
|
||||
if (finalTitle.length > 0) {
|
||||
processedFiles += `\n- ${finalTitle}`;
|
||||
updateMessage(`Fichier ${counter} traités.`);
|
||||
} else {
|
||||
processedFiles += `\n- ${file} [incompressable]`;
|
||||
updateMessage(`Fichier ${counter} trop large pour être compressé.`);
|
||||
numberOfUncompressableFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
let errorMessage = "";
|
||||
if (numberOfUncompressableFiles > 0) {
|
||||
errorMessage += `\nNombre de fichier incompressable : ${numberOfUncompressableFiles}.`;
|
||||
processedFiles += `\n- ${finalTitle}`;
|
||||
updateMessage(`Fichier ${counter} traités.`);
|
||||
}
|
||||
|
||||
// Send confirmation to the user that we're done
|
||||
await internals.confirmation(
|
||||
`${files.length} fichiers traités : ${processedFiles}` + errorMessage
|
||||
`${files.length} fichiers traités : ${processedFiles}`
|
||||
);
|
||||
|
||||
await internals.exit();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue