Compare commits

..

No commits in common. "main" and "1.9.2" have entirely different histories.
main ... 1.9.2

8 changed files with 524 additions and 368 deletions

View file

@ -25,4 +25,3 @@ jobs:
with:
token: ${{ secrets.TOKEN }}
files: out/make/zip/win32/x64/dsr-win32-x64-${{ github.ref_name }}.zip
draft: true

View file

@ -1,10 +1,10 @@
# Discord Video Sharing [![status-badge](https://git.mylloon.fr/Anri/dsr/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/dsr/actions?workflow=release.yml)
# Discord Video Sharing ![status-badge](https://git.mylloon.fr/Anri/dsr/badges/workflows/release.yml/badge.svg)
Tool for sharing video to Discord.
> This tool was primarily made for video captured by NVidia Shadowplay.
## Download/Install/Update
## Download/Install
2 choices :
@ -15,36 +15,22 @@ Tool for sharing video to Discord.
irm https://git.mylloon.fr/Anri/dsr/raw/branch/main/install.ps1 | iex
```
## Available flags
You can add thoses flags in the `Target` field of your Windows shortcut.
| | |
| ------------- | ----------------------------------------------------- |
| `/nitro` | Increase the file limit to 500Mo |
| `/nitrobasic` | Increase the file limit to 50Mo |
| | |
| `/nvenc_h264` | Enable NVenc with H.264 encoder (NVidia GPU required) |
| `/nvenc_h265` | Enable NVenc with H.265 encoder (NVidia GPU required) |
| `/h265` | Enable the H.265 CPU encoder (slow compression) |
> NVenc support is experimental, but faster than CPU counterparts.
> - 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 into the icon
- [x] Keep the video under discord limitation
- [x] Defaults to H.264 CPU encoder
- [x] If already under the limit, the file won't be compressed
- [x] Keep the video under 25mb (discord limitation)
- [x] NVenc support
- [x] Nitro suppport
- [x] Merge 2 audio files into one track when recorded with system audio and microphone
split up, while keeping the original ones (with conveniant metadata)
- [x] Works also with file with only one or more than 2 audio track, by doing
nothing
- [x] If already under the limit, the file won't be compressed
- [x] Nitro suppport via `/nitro` flag
- [x] Merge audio files into one track when recorded with system audio and microphone
split up, while keeping the original ones (with conveninant metadata)
- [x] Works also with file with only one audio track
- [x] Support multiples files at once
- [x] Always optimize for video streaming
- [x] Optimize for video streaming
## Package the app for Windows

665
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "dsr",
"version": "1.11.2",
"version": "1.9.2",
"description": "Discord Video Sharing",
"main": "./dist/main.js",
"scripts": {
@ -18,23 +18,21 @@
"author": "Mylloon",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@electron-forge/maker-zip": "^7.5",
"@electron-forge/maker-zip": "^7.4",
"ffmpeg-static": "^5.2",
"ffprobe-static": "^3.1",
"typescript": "^5.6"
"terminate": "^2.8",
"typescript": "^5.5"
},
"devDependencies": {
"@electron-forge/cli": "^7.5",
"@electron-forge/cli": "^7.4",
"@types/ffprobe-static": "^2.0",
"electron": "^33.0"
"electron": "^32.0"
},
"config": {
"forge": {
"packagerConfig": {
"icon": "./image/icon.ico",
"asar": {
"unpack": "**/node_modules/*-static/**"
}
"icon": "./image/icon.ico"
},
"makers": [
{

View file

@ -11,9 +11,9 @@ import {
processes,
} from "./utils/misc";
import path = require("path");
import ffmpegPath = require("ffmpeg-static");
import ffmpeg = require("ffmpeg-static");
const ffmpegPath = `${ffmpeg}`.replace("app.asar", "app.asar.unpacked");
const kill = require("terminate");
let error = false;
@ -22,7 +22,6 @@ const moviesFilter = {
extensions: ["mp4", "mkv"],
};
const metadataAudioSize = 3;
const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \
-metadata:s:a:1 title="System sounds" \
-metadata:s:a:2 title="Microphone"`;
@ -90,9 +89,9 @@ app.whenReady().then(() => {
const tmpFile = getNewFilename(file, "TMP_");
let outFile;
let audioTracks = getNumberOfAudioTracks(file);
const nbTracks = getNumberOfAudioTracks(file);
switch (audioTracks.length) {
switch (nbTracks) {
case 2:
// Merge 2 audio
// See: https://trac.ffmpeg.org/wiki/AudioChannelManipulation#a2stereostereo
@ -121,8 +120,6 @@ app.whenReady().then(() => {
// Delete the temporary video file
deleteFile(tmpFile);
audioTracks = getNumberOfAudioTracks(outFile);
break;
default:
// Other cases: no merge needed
@ -140,63 +137,49 @@ app.whenReady().then(() => {
title: outFile,
size: stats.size / 1024 / 1024,
duration,
audioTracks,
nbTracks,
};
};
/** 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,
audioTracks: number[]
nbTracks: number
) => {
const audioBitrate = Math.ceil(
audioTracks.reduce((sum, current) => current + sum, 50) // initial value > 0 for extra room
);
const videoBitrate = bitrate - audioBitrate;
let finalFile;
const audioBitrate = 500; // keep some room
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(nbTracks + 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")) {
// Use NVenc
codec = "h264_nvenc";
hwAcc = "-hwaccel cuda";
if (argv.includes("/nvenc_h265")) {
// Use NVenc H.265
codec = "hevc_nvenc";
hwAcc = "-hwaccel cuda";
}
// Increase video bitrate
videoBitrate = Math.floor(videoBitrate * 1.7);
}
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} \
@ -205,26 +188,22 @@ app.whenReady().then(() => {
-i "${file}" \
-c:v ${codec} -b:v ${videoBitrate}k -pass 2 -c:a copy \
${mappingTracks} -f mp4 \
-profile:v main \
${audioTracks.length === metadataAudioSize ? metadataAudio : ""} \
${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;
};
/** Move metadata at the begenning of the file */
const moveMetadata = async (file: string, nbTracks: number) => {
const moveMetadata = async (file: string) => {
const finalFile = getNewFilename(file, "Broadcastable - ");
// Optimize for streaming
@ -233,7 +212,6 @@ app.whenReady().then(() => {
-i "${file}" \
-map 0 -codec copy \
${shareOpt} \
${nbTracks === metadataAudioSize ? metadataAudio : ""} \
"${finalFile}"`
).catch((e) => registerError(win, e));
@ -251,19 +229,17 @@ app.whenReady().then(() => {
ipcMain.handle("mergeAudio", (_, file: string) => mergeAudio(file));
ipcMain.handle(
"reduceSize",
(_, file: string, bitrate: number, audioTracks: number[]) =>
reduceSize(file, bitrate, audioTracks)
);
ipcMain.handle("moveMetadata", (_, file: string, nbTracks: number) =>
moveMetadata(file, nbTracks)
(_, file: string, bitrate: number, nbTracks: number) =>
reduceSize(file, bitrate, nbTracks)
);
ipcMain.handle("moveMetadata", (_, file: string) => moveMetadata(file));
ipcMain.handle("exit", () => (error ? {} : app.quit()));
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
});
app.on("window-all-closed", () => {
processes.forEach((process) => {
process.stdin.write("q");
kill(process.pid);
});
app.quit();

View file

@ -13,10 +13,9 @@ contextBridge.exposeInMainWorld("internals", {
ipcRenderer.invoke("getFilename", filepath),
askFiles: () => ipcRenderer.invoke("askFiles"),
mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file),
reduceSize: (file: string, bitrate: number, audioTracks: number[]) =>
ipcRenderer.invoke("reduceSize", file, bitrate, audioTracks),
moveMetadata: (file: string, nbTracks: number) =>
ipcRenderer.invoke("moveMetadata", file, nbTracks),
reduceSize: (file: string, bitrate: number, nbTracks: number) =>
ipcRenderer.invoke("reduceSize", file, bitrate, nbTracks),
moveMetadata: (file: string) => ipcRenderer.invoke("moveMetadata", file),
exit: () => ipcRenderer.invoke("exit"),
confirmation: (text: string) => ipcRenderer.invoke("confirmation", text),
});

View file

@ -11,14 +11,14 @@ let internals: {
title: string;
duration: number;
size: number;
audioTracks: number[];
nbTracks: number;
}>;
reduceSize: (
file: string,
bitrate: number,
audioTracks: number[]
nbTracks: number
) => Promise<string>;
moveMetadata: (file: string, nbTracks: number) => Promise<string>;
moveMetadata: (file: string) => Promise<string>;
confirmation: (text: string) => Promise<void>;
};
@ -56,16 +56,13 @@ const getFiles = async () => {
/** Returns maximum allowed size for files in MB */
const fetchMaxSize = async () => {
const argv = await internals.argv();
if (argv.includes("/nitrobasic")) {
// Nitro Basic user
return 50;
} else if (argv.includes("/nitro")) {
if (argv.includes("/nitro")) {
// Nitro user
return 500;
} else {
// Free user
return 10;
}
// Free user
return 25;
};
/** Either replace the message, or add some info */
@ -103,7 +100,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()) {
@ -136,39 +132,24 @@ const main = async () => {
finalTitle = await internals.reduceSize(
newFile.title,
bitrate,
newFile.audioTracks
newFile.nbTracks
);
} else {
updateMessage(`\nPréparation pour le partage...`, true, Mode.Append);
// Move the metadata to make it playable before everything is downloaded
finalTitle = await internals.moveMetadata(
newFile.title,
newFile.audioTracks.length
);
finalTitle = await internals.moveMetadata(newFile.title);
}
// 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();
};

View file

@ -1,11 +1,9 @@
import ffprobe = require("ffprobe-static");
import child_process = require("child_process");
import path = require("path");
import { BrowserWindow } from "electron";
import { existsSync, unlink } from "fs";
import ffprobe = require("ffprobe-static");
const ffprobePath = ffprobe.path.replace("app.asar", "app.asar.unpacked");
export const processes: child_process.ChildProcess[] = [];
/** Create a new filename from the OG one */
@ -16,18 +14,16 @@ export const getNewFilename = (ogFile: string, part: string) => {
/** Return the duration of a video in second */
export const getVideoDuration = (file: string) => {
const command = `"${ffprobePath}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`;
const command = `"${ffprobe.path}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`;
const durationString = child_process.execSync(command).toString().trim();
return parseFloat(durationString);
};
/** Return the number of audio tracks */
export const getNumberOfAudioTracks = (file: string): number[] => {
const command = `"${ffprobePath}" -v error -show_entries stream=bit_rate -select_streams a -of json "${file}"`;
export const getNumberOfAudioTracks = (file: string) => {
const command = `"${ffprobe.path}" -v error -show_entries stream=index -select_streams a -of json "${file}"`;
const result = child_process.execSync(command, { encoding: "utf8" });
return JSON.parse(result).streams.map(
(v: { bit_rate: string }) => Number(v.bit_rate) / 1000
);
return JSON.parse(result).streams.length;
};
/** Print an error to the console and open the dev tool panel */