Compare commits
96 commits
Author | SHA1 | Date | |
---|---|---|---|
f590f77bca | |||
ecb03ded2a | |||
21b39e80bf | |||
55b94d0021 | |||
4f34191d2f | |||
7c4bd84486 | |||
e34712976b | |||
dc190ab807 | |||
21050bb0b7 | |||
482caad25f | |||
5841006f15 | |||
ee64d06e0a | |||
2ef8bda147 | |||
b6d6b84839 | |||
f2b04f0cea | |||
c22a9c295d | |||
b391e05ed3 | |||
a74bb33967 | |||
8d34199ae0 | |||
b894fd0856 | |||
39d84c9b57 | |||
981f95c40d | |||
c8538f5d03 | |||
2c2f469cc5 | |||
7973a02603 | |||
a6fe54fd9c | |||
20052ed7d6 | |||
4223ede10a | |||
877021ee0d | |||
fce9bce308 | |||
0ed6407315 | |||
af921925af | |||
cb9de1b856 | |||
1d1c0f78bc | |||
6fffd19278 | |||
bfa1f94a43 | |||
ebbca9b6aa | |||
fc7782a982 | |||
440fcf2334 | |||
d93b0d148b | |||
0399080d6e | |||
d4bb073218 | |||
b35635daf0 | |||
cdf2e678c3 | |||
2fe6f6aece | |||
d9c21876e8 | |||
0047664616 | |||
d6880ab85c | |||
0b85415c1d | |||
04b4138b46 | |||
8fb8f24625 | |||
80dca39b8c | |||
de983c8802 | |||
a202996c11 | |||
65339d4592 | |||
e0076c7705 | |||
ede370763f | |||
4890ee40a2 | |||
f93673ce68 | |||
ed6f0a2b49 | |||
eb84c48b3c | |||
ba533ea3b6 | |||
e942e807d6 | |||
20bf0c1d67 | |||
dd62f81e35 | |||
05de7dc801 | |||
f9d812f9b2 | |||
e108ae3097 | |||
ca9fe8ed36 | |||
4275cb5528 | |||
dfb049f1fb | |||
b577987efd | |||
85cabf536c | |||
6c0f8e70d8 | |||
d4e4bd9ec3 | |||
740b258ce1 | |||
a3f4c077ef | |||
274e67ff45 | |||
3e57b75145 | |||
9ce7aeeae6 | |||
3be79cfc0f | |||
5f8eaf36fb | |||
067ca081b7 | |||
5a5fe09a93 | |||
ab170b0cda | |||
d509d31a1b | |||
2c19f71614 | |||
e2df3da0a8 | |||
22d8c76bfa | |||
9751a5ee59 | |||
40654c0581 | |||
e244e78b2f | |||
1a41e1bd72 | |||
f27f8b01aa | |||
99e68b4db1 | |||
b363d47200 |
9 changed files with 1720 additions and 801 deletions
28
.forgejo/workflows/release.yml
Normal file
28
.forgejo/workflows/release.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
name: Upload release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
npm install --platform=win32 &&
|
||||||
|
apt-get update &&
|
||||||
|
apt-get install -y zip
|
||||||
|
|
||||||
|
- name: Build the app
|
||||||
|
run: npm run make -- --platform=win32
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
uses: akkuman/gitea-release-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.TOKEN }}
|
||||||
|
files: out/make/zip/win32/x64/dsr-win32-x64-${{ github.ref_name }}.zip
|
||||||
|
draft: true
|
64
README.md
64
README.md
|
@ -1,48 +1,50 @@
|
||||||
# Discord Video Sharing
|
# 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)
|
||||||
|
|
||||||
Helper for sharing video captured by NVidia Shadowplay in Discord.
|
Tool for sharing video to Discord.
|
||||||
|
|
||||||
## Download/Install
|
> This tool was primarily made for video captured by NVidia Shadowplay.
|
||||||
|
|
||||||
|
## Download/Install/Update
|
||||||
|
|
||||||
2 choices :
|
2 choices :
|
||||||
|
|
||||||
- Manually head to [the release page](https://git.mylloon.fr/Anri/dsr/releases/latest).
|
- Manually head to [the release page](https://git.mylloon.fr/Anri/dsr/releases/latest).
|
||||||
- <details>
|
- Download it via PowerShell:
|
||||||
<summary>Download it via command lines</summary>
|
|
||||||
|
|
||||||
Copy and paste this snippet into the windows command prompt:
|
```powershell
|
||||||
|
irm https://git.mylloon.fr/Anri/dsr/raw/branch/main/install.ps1 | iex
|
||||||
```bash
|
|
||||||
PowerShell -Command "" ^
|
|
||||||
"$releases = 'https://git.mylloon.fr/api/v1/repos/Anri/dsr/releases/latest';" ^
|
|
||||||
"$link = (Invoke-WebRequest $releases | ConvertFrom-Json)[0].assets.browser_download_url;" ^
|
|
||||||
"$archive = 'dsr.zip';" ^
|
|
||||||
"$outfile = Join-Path -Path $env:TEMP -ChildPath $archive;" ^
|
|
||||||
"Invoke-WebRequest -Uri $link -OutFile $outfile;" ^
|
|
||||||
"cd $env:TEMP;" ^
|
|
||||||
"Expand-Archive -Path $archive -DestinationPath '%LOCALAPPDATA%\DSR' -Force;" ^
|
|
||||||
"Move-Item -Path '%LOCALAPPDATA%\DSR\dsr-win32-x64\*' -Destination '%LOCALAPPDATA%\DSR' -Force;" ^
|
|
||||||
"Remove-Item '%LOCALAPPDATA%\DSR\dsr-win32-x64';'" ^
|
|
||||||
"$WshShell = New-Object -comObject WScript.Shell;" ^
|
|
||||||
"$Shortcut = $WshShell.CreateShortcut('%APPDATA%\Microsoft\Windows\Start Menu\Programs\DSR.lnk');" ^
|
|
||||||
"$Shortcut.TargetPath = '%LOCALAPPDATA%\DSR\dsr.exe';" ^
|
|
||||||
"$Shortcut.Save();" ^
|
|
||||||
"REG ADD 'HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\dsr' /f /v DisplayName /t REG_SZ /d 'DSR';" ^
|
|
||||||
"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.
|
## Available flags
|
||||||
</details>
|
|
||||||
|
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.
|
||||||
|
|
||||||
## More info
|
## More info
|
||||||
|
|
||||||
- [x] KISS interface
|
- [x] KISS interface
|
||||||
- [x] Support drag&drop
|
- [x] Support drag&drop into the icon
|
||||||
- [x] Keep the video under 25mb (discord limitation)
|
- [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] If already under the limit, the file won't be compressed
|
||||||
- [x] Nitro suppport via `/nitro` flag
|
- [x] NVenc support
|
||||||
- [x] Merge all audio files into one track, while keeping the original ones (keeping track's title too)
|
- [x] Nitro suppport
|
||||||
- [x] Support multiples files
|
- [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] Support multiples files at once
|
||||||
|
- [x] Always optimize for video streaming
|
||||||
|
|
||||||
## Package the app for Windows
|
## Package the app for Windows
|
||||||
|
|
||||||
|
|
51
install.ps1
Normal file
51
install.ps1
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
param (
|
||||||
|
[switch]$Force
|
||||||
|
)
|
||||||
|
|
||||||
|
# Enable TLSv1.2 for compatibility with older windows versions
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
|
$path = "$env:LOCALAPPDATA\DSR"
|
||||||
|
$update = Test-Path -Path $path\*
|
||||||
|
|
||||||
|
# Download
|
||||||
|
$releases = "https://git.mylloon.fr/api/v1/repos/Anri/dsr/releases/latest"
|
||||||
|
$link = (Invoke-WebRequest $releases | ConvertFrom-Json)[0].assets.browser_download_url
|
||||||
|
$archive = "$env:TEMP\dsr.zip"
|
||||||
|
Invoke-WebRequest -Uri $link -OutFile $archive
|
||||||
|
Remove-Item "$path" -Recurse -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
# Close running DSR
|
||||||
|
Stop-Process -Name "DSR" -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
Expand-Archive -Path $archive -DestinationPath "$path" -Force
|
||||||
|
Move-Item -Path "$path\dsr-win32-x64\*" -Destination "$path" -Force
|
||||||
|
Remove-Item "$path\dsr-win32-x64"
|
||||||
|
|
||||||
|
# Ask user to add a shortcut to the desktop
|
||||||
|
if (-not $update -Or $Force) {
|
||||||
|
# Add shortcut
|
||||||
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
|
$Shortcut = $WshShell.CreateShortcut("$env:APPDATA\Microsoft\Windows\Start Menu\Programs\DSR.lnk")
|
||||||
|
$Shortcut.TargetPath = "$path\dsr.exe"
|
||||||
|
$Shortcut.Save()
|
||||||
|
|
||||||
|
# Add new app to registry
|
||||||
|
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\dsr" /f /v DisplayName /t REG_SZ /d "DSR"
|
||||||
|
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\dsr" /f /v InstallLocation /t REG_SZ /d "$path"
|
||||||
|
|
||||||
|
if ($Host.UI.PromptForChoice(
|
||||||
|
"***********************",
|
||||||
|
"Add a desktop shortcut?",
|
||||||
|
@(
|
||||||
|
[System.Management.Automation.Host.ChoiceDescription]::new("&Yes", "Add a shortcut to your desktop.")
|
||||||
|
[System.Management.Automation.Host.ChoiceDescription]::new("&No", "Skip the shortcut creation.")
|
||||||
|
), 1) -eq 0) {
|
||||||
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
|
$Desktop = [Environment]::GetFolderPath("Desktop")
|
||||||
|
$Shortcut = $WshShell.CreateShortcut("$Desktop\DSR.lnk")
|
||||||
|
$Shortcut.TargetPath = "$path\dsr.exe"
|
||||||
|
$Shortcut.Save()
|
||||||
|
}
|
||||||
|
}
|
2035
package-lock.json
generated
2035
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dsr",
|
"name": "dsr",
|
||||||
"version": "1.5.1",
|
"version": "1.11.2",
|
||||||
"description": "Discord Video Sharing",
|
"description": "Discord Video Sharing",
|
||||||
"main": "./dist/main.js",
|
"main": "./dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -18,20 +18,23 @@
|
||||||
"author": "Mylloon",
|
"author": "Mylloon",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-forge/maker-zip": "^6.4",
|
"@electron-forge/maker-zip": "^7.5",
|
||||||
"ffmpeg-static": "^5.2",
|
"ffmpeg-static": "^5.2",
|
||||||
"ffprobe-static": "^3.1",
|
"ffprobe-static": "^3.1",
|
||||||
"typescript": "^5.2"
|
"typescript": "^5.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-forge/cli": "^6.4",
|
"@electron-forge/cli": "^7.5",
|
||||||
"@types/ffprobe-static": "^2.0",
|
"@types/ffprobe-static": "^2.0",
|
||||||
"electron": "^27.0"
|
"electron": "^33.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"forge": {
|
"forge": {
|
||||||
"packagerConfig": {
|
"packagerConfig": {
|
||||||
"icon": "./image/icon.ico"
|
"icon": "./image/icon.ico",
|
||||||
|
"asar": {
|
||||||
|
"unpack": "**/node_modules/*-static/**"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"makers": [
|
"makers": [
|
||||||
{
|
{
|
||||||
|
|
176
src/main.ts
176
src/main.ts
|
@ -1,25 +1,40 @@
|
||||||
import { BrowserWindow, app, dialog, ipcMain } from "electron";
|
import { app, BrowserWindow, dialog, ipcMain, Notification } from "electron";
|
||||||
import { statSync } from "fs";
|
import { statSync, copyFileSync } from "fs";
|
||||||
import {
|
import {
|
||||||
deleteFile,
|
deleteFile,
|
||||||
deleteTwoPassFiles,
|
deleteTwoPassFiles,
|
||||||
execute,
|
execute,
|
||||||
getNewFilename,
|
getNewFilename,
|
||||||
getVideoDuration,
|
getVideoDuration,
|
||||||
|
getNumberOfAudioTracks,
|
||||||
printAndDevTool,
|
printAndDevTool,
|
||||||
|
processes,
|
||||||
} from "./utils/misc";
|
} from "./utils/misc";
|
||||||
import path = require("path");
|
import path = require("path");
|
||||||
import ffmpegPath = require("ffmpeg-static");
|
|
||||||
|
import ffmpeg = require("ffmpeg-static");
|
||||||
|
const ffmpegPath = `${ffmpeg}`.replace("app.asar", "app.asar.unpacked");
|
||||||
|
|
||||||
|
let error = false;
|
||||||
|
|
||||||
const moviesFilter = {
|
const moviesFilter = {
|
||||||
name: "Videos",
|
name: "Videos",
|
||||||
extensions: ["mp4", "mkv"],
|
extensions: ["mp4", "mkv"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const metadataAudioSize = 3;
|
||||||
const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \
|
const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \
|
||||||
-metadata:s:a:1 title="System sounds" \
|
-metadata:s:a:1 title="System sounds" \
|
||||||
-metadata:s:a:2 title="Microphone"`;
|
-metadata:s:a:2 title="Microphone"`;
|
||||||
|
|
||||||
|
const shareOpt = "-movflags +faststart";
|
||||||
|
|
||||||
|
/** Register a new error */
|
||||||
|
const registerError = (win: BrowserWindow, err: string) => {
|
||||||
|
error = true;
|
||||||
|
printAndDevTool(win, err);
|
||||||
|
};
|
||||||
|
|
||||||
/** Create a new window */
|
/** Create a new window */
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
|
@ -37,6 +52,11 @@ const createWindow = () => {
|
||||||
return win;
|
return win;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// For notification on Windows
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
app.setAppUserModelId(app.name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Ready to create the window */
|
/* Ready to create the window */
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
const win = createWindow();
|
const win = createWindow();
|
||||||
|
@ -51,17 +71,29 @@ app.whenReady().then(() => {
|
||||||
|
|
||||||
/** Send confirmation to user */
|
/** Send confirmation to user */
|
||||||
const confirmation = async (message: string) => {
|
const confirmation = async (message: string) => {
|
||||||
|
// Send notification
|
||||||
|
new Notification({
|
||||||
|
title: "Status",
|
||||||
|
body: message,
|
||||||
|
}).show();
|
||||||
|
|
||||||
|
// Open dialog
|
||||||
await dialog.showMessageBox(win, { message });
|
await dialog.showMessageBox(win, { message });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Get filename of a path */
|
/** Get filename of a path */
|
||||||
const getFilename = (filepath: string) => path.parse(filepath).base;
|
const getFilename = (filepath: string) => path.parse(filepath).base;
|
||||||
|
|
||||||
/** Merge all audios track of a video into one */
|
/** Merge all audios track of a video into one
|
||||||
|
* In case video doesn't have exactly two audio streams, silently pass */
|
||||||
const mergeAudio = async (file: string) => {
|
const mergeAudio = async (file: string) => {
|
||||||
const tmpFile = getNewFilename(file, "TMP_");
|
const tmpFile = getNewFilename(file, "TMP_");
|
||||||
const outFile = getNewFilename(file, "(merged audio) ");
|
let outFile;
|
||||||
|
|
||||||
|
let audioTracks = getNumberOfAudioTracks(file);
|
||||||
|
|
||||||
|
switch (audioTracks.length) {
|
||||||
|
case 2:
|
||||||
// Merge 2 audio
|
// Merge 2 audio
|
||||||
// See: https://trac.ffmpeg.org/wiki/AudioChannelManipulation#a2stereostereo
|
// See: https://trac.ffmpeg.org/wiki/AudioChannelManipulation#a2stereostereo
|
||||||
await execute(
|
await execute(
|
||||||
|
@ -70,7 +102,9 @@ app.whenReady().then(() => {
|
||||||
-filter_complex "[0:a]amerge=inputs=2[a]" -ac 2 -map 0:v -map "[a]" \
|
-filter_complex "[0:a]amerge=inputs=2[a]" -ac 2 -map 0:v -map "[a]" \
|
||||||
-c:v copy \
|
-c:v copy \
|
||||||
"${tmpFile}"`
|
"${tmpFile}"`
|
||||||
).catch((e) => printAndDevTool(win, e));
|
);
|
||||||
|
|
||||||
|
outFile = getNewFilename(file, "(merged audio) ");
|
||||||
|
|
||||||
// Add merged audio as first position to original video and make it default
|
// Add merged audio as first position to original video and make it default
|
||||||
// About disposition: https://ffmpeg.org/ffmpeg.html#Main-options
|
// About disposition: https://ffmpeg.org/ffmpeg.html#Main-options
|
||||||
|
@ -82,48 +116,129 @@ app.whenReady().then(() => {
|
||||||
-disposition:a 0 -disposition:a:0 default \
|
-disposition:a 0 -disposition:a:0 default \
|
||||||
${metadataAudio} \
|
${metadataAudio} \
|
||||||
"${outFile}"`
|
"${outFile}"`
|
||||||
).catch((e) => printAndDevTool(win, e));
|
).catch((e) => registerError(win, e));
|
||||||
|
|
||||||
// Delete the temporary video file
|
// Delete the temporary video file
|
||||||
deleteFile(tmpFile);
|
deleteFile(tmpFile);
|
||||||
|
|
||||||
|
audioTracks = getNumberOfAudioTracks(outFile);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Other cases: no merge needed
|
||||||
|
outFile = getNewFilename(file, "(nomerge) ");
|
||||||
|
|
||||||
|
// Do a copy
|
||||||
|
copyFileSync(file, outFile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const duration = getVideoDuration(outFile);
|
const duration = getVideoDuration(outFile);
|
||||||
const stats = statSync(outFile);
|
const stats = statSync(outFile);
|
||||||
|
|
||||||
return { title: outFile, size: stats.size / 1024 / 1024, duration };
|
return {
|
||||||
|
title: outFile,
|
||||||
|
size: stats.size / 1024 / 1024,
|
||||||
|
duration,
|
||||||
|
audioTracks,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Reduce size of a file */
|
/** Reduce size of a file
|
||||||
const reduceSize = async (file: string, bitrate: number) => {
|
* Returns an empty string in case of failing
|
||||||
const audioBitrate = 400; // keep some room
|
*/
|
||||||
|
const reduceSize = async (
|
||||||
|
file: string,
|
||||||
|
bitrate: number,
|
||||||
|
audioTracks: number[]
|
||||||
|
) => {
|
||||||
|
const audioBitrate = Math.ceil(
|
||||||
|
audioTracks.reduce((sum, current) => current + sum, 50) // initial value > 0 for extra room
|
||||||
|
);
|
||||||
const videoBitrate = bitrate - audioBitrate;
|
const videoBitrate = bitrate - audioBitrate;
|
||||||
|
let finalFile;
|
||||||
|
|
||||||
const finalFile = getNewFilename(file, "Compressed - ");
|
if (videoBitrate > 0) {
|
||||||
|
finalFile = getNewFilename(file, "Compressed - ");
|
||||||
|
|
||||||
// Trash the output, depends on the platform
|
// Trash the output, depends on the platform
|
||||||
const nul = process.platform === "win32" ? "NUL" : "/dev/null";
|
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(" ");
|
||||||
|
|
||||||
|
let codec = "libx264";
|
||||||
|
let hwAcc = "";
|
||||||
|
|
||||||
|
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("/h265")) {
|
||||||
|
// Use H.265 encoder
|
||||||
|
codec = "libx265";
|
||||||
|
}
|
||||||
|
|
||||||
// Compress the video
|
// Compress the video
|
||||||
// Add metadata to audio's track
|
// Add metadata to audio's track
|
||||||
await execute(
|
await execute(
|
||||||
`"${ffmpegPath}" -y \
|
`"${ffmpegPath}" -y ${hwAcc} \
|
||||||
-i "${file}" \
|
-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} \
|
${nul} \
|
||||||
&& \
|
&& \
|
||||||
"${ffmpegPath}" -y \
|
"${ffmpegPath}" -y ${hwAcc} \
|
||||||
-i "${file}" \
|
-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 \
|
||||||
-map 0:0 -map 0:1 -map 0:2 -map 0:3 -f mp4 \
|
${mappingTracks} -f mp4 \
|
||||||
${metadataAudio} \
|
-profile:v main \
|
||||||
|
${audioTracks.length === metadataAudioSize ? metadataAudio : ""} \
|
||||||
|
${shareOpt} \
|
||||||
"${finalFile}"`
|
"${finalFile}"`
|
||||||
).catch((e) => printAndDevTool(win, e));
|
).catch((e) => registerError(win, e));
|
||||||
|
|
||||||
|
// Delete the 2 pass temporary files
|
||||||
|
deleteTwoPassFiles(process.cwd());
|
||||||
|
} else {
|
||||||
|
finalFile = "";
|
||||||
|
}
|
||||||
|
|
||||||
// Delete the old video file
|
// Delete the old video file
|
||||||
deleteFile(file);
|
deleteFile(file);
|
||||||
|
|
||||||
// Delete the 2 pass temporary files
|
return finalFile;
|
||||||
deleteTwoPassFiles(file);
|
};
|
||||||
|
|
||||||
|
/** Move metadata at the begenning of the file */
|
||||||
|
const moveMetadata = async (file: string, nbTracks: number) => {
|
||||||
|
const finalFile = getNewFilename(file, "Broadcastable - ");
|
||||||
|
|
||||||
|
// Optimize for streaming
|
||||||
|
await execute(
|
||||||
|
`"${ffmpegPath}" -y \
|
||||||
|
-i "${file}" \
|
||||||
|
-map 0 -codec copy \
|
||||||
|
${shareOpt} \
|
||||||
|
${nbTracks === metadataAudioSize ? metadataAudio : ""} \
|
||||||
|
"${finalFile}"`
|
||||||
|
).catch((e) => registerError(win, e));
|
||||||
|
|
||||||
|
// Delete the old video file
|
||||||
|
deleteFile(file);
|
||||||
|
|
||||||
return finalFile;
|
return finalFile;
|
||||||
};
|
};
|
||||||
|
@ -134,9 +249,22 @@ app.whenReady().then(() => {
|
||||||
ipcMain.handle("getFilename", (_, filepath: string) => getFilename(filepath));
|
ipcMain.handle("getFilename", (_, filepath: string) => getFilename(filepath));
|
||||||
ipcMain.handle("askFiles", () => askFiles());
|
ipcMain.handle("askFiles", () => askFiles());
|
||||||
ipcMain.handle("mergeAudio", (_, file: string) => mergeAudio(file));
|
ipcMain.handle("mergeAudio", (_, file: string) => mergeAudio(file));
|
||||||
ipcMain.handle("reduceSize", (_, file: string, bitrate: number) =>
|
ipcMain.handle(
|
||||||
reduceSize(file, bitrate)
|
"reduceSize",
|
||||||
|
(_, file: string, bitrate: number, audioTracks: number[]) =>
|
||||||
|
reduceSize(file, bitrate, audioTracks)
|
||||||
);
|
);
|
||||||
ipcMain.handle("exit", () => app.quit());
|
ipcMain.handle("moveMetadata", (_, file: string, nbTracks: number) =>
|
||||||
|
moveMetadata(file, nbTracks)
|
||||||
|
);
|
||||||
|
ipcMain.handle("exit", () => (error ? {} : app.quit()));
|
||||||
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
|
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on("window-all-closed", () => {
|
||||||
|
processes.forEach((process) => {
|
||||||
|
process.stdin.write("q");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.quit();
|
||||||
|
});
|
||||||
|
|
|
@ -13,8 +13,10 @@ contextBridge.exposeInMainWorld("internals", {
|
||||||
ipcRenderer.invoke("getFilename", filepath),
|
ipcRenderer.invoke("getFilename", filepath),
|
||||||
askFiles: () => ipcRenderer.invoke("askFiles"),
|
askFiles: () => ipcRenderer.invoke("askFiles"),
|
||||||
mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file),
|
mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file),
|
||||||
reduceSize: (file: string, bitrate: number) =>
|
reduceSize: (file: string, bitrate: number, audioTracks: number[]) =>
|
||||||
ipcRenderer.invoke("reduceSize", file, bitrate),
|
ipcRenderer.invoke("reduceSize", file, bitrate, audioTracks),
|
||||||
|
moveMetadata: (file: string, nbTracks: number) =>
|
||||||
|
ipcRenderer.invoke("moveMetadata", file, nbTracks),
|
||||||
exit: () => ipcRenderer.invoke("exit"),
|
exit: () => ipcRenderer.invoke("exit"),
|
||||||
confirmation: (text: string) => ipcRenderer.invoke("confirmation", text),
|
confirmation: (text: string) => ipcRenderer.invoke("confirmation", text),
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,10 +7,18 @@ let internals: {
|
||||||
getFilename: (filepath: string) => Promise<string>;
|
getFilename: (filepath: string) => Promise<string>;
|
||||||
askFiles: () => Promise<string[] | undefined>;
|
askFiles: () => Promise<string[] | undefined>;
|
||||||
exit: () => Promise<void>;
|
exit: () => Promise<void>;
|
||||||
mergeAudio: (
|
mergeAudio: (filename: string) => Promise<{
|
||||||
filename: string
|
title: string;
|
||||||
) => Promise<{ title: string; duration: number; size: number }>;
|
duration: number;
|
||||||
reduceSize: (file: string, bitrate: number) => Promise<string>;
|
size: number;
|
||||||
|
audioTracks: number[];
|
||||||
|
}>;
|
||||||
|
reduceSize: (
|
||||||
|
file: string,
|
||||||
|
bitrate: number,
|
||||||
|
audioTracks: number[]
|
||||||
|
) => Promise<string>;
|
||||||
|
moveMetadata: (file: string, nbTracks: number) => Promise<string>;
|
||||||
confirmation: (text: string) => Promise<void>;
|
confirmation: (text: string) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +35,9 @@ const getFiles = async () => {
|
||||||
// Exit if a file isn't supported in the list
|
// Exit if a file isn't supported in the list
|
||||||
if (
|
if (
|
||||||
files.filter((file) =>
|
files.filter((file) =>
|
||||||
allowedExtensions.some((ext) => file.endsWith(ext))
|
allowedExtensions.some((ext) =>
|
||||||
|
file.toLowerCase().endsWith(ext.toLowerCase())
|
||||||
|
)
|
||||||
).length !== files.length
|
).length !== files.length
|
||||||
) {
|
) {
|
||||||
await internals.exit();
|
await internals.exit();
|
||||||
|
@ -46,13 +56,16 @@ const getFiles = async () => {
|
||||||
/** Returns maximum allowed size for files in MB */
|
/** Returns maximum allowed size for files in MB */
|
||||||
const fetchMaxSize = async () => {
|
const fetchMaxSize = async () => {
|
||||||
const argv = await internals.argv();
|
const argv = await internals.argv();
|
||||||
if (argv.includes("/nitro")) {
|
if (argv.includes("/nitrobasic")) {
|
||||||
|
// Nitro Basic user
|
||||||
|
return 50;
|
||||||
|
} else if (argv.includes("/nitro")) {
|
||||||
// Nitro user
|
// Nitro user
|
||||||
return 500;
|
return 500;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Free user
|
// Free user
|
||||||
return 25;
|
return 10;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Either replace the message, or add some info */
|
/** Either replace the message, or add some info */
|
||||||
|
@ -90,6 +103,7 @@ const main = async () => {
|
||||||
updateMessage("Récupération des fichiers...");
|
updateMessage("Récupération des fichiers...");
|
||||||
const files = await getFiles();
|
const files = await getFiles();
|
||||||
let processedFiles = "";
|
let processedFiles = "";
|
||||||
|
let numberOfUncompressableFiles = 0;
|
||||||
|
|
||||||
// Iterate over all the retrieved files
|
// Iterate over all the retrieved files
|
||||||
for (const [idx, file] of files.entries()) {
|
for (const [idx, file] of files.entries()) {
|
||||||
|
@ -119,18 +133,43 @@ const main = async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compress the video and change the title to the new one
|
// Compress the video and change the title to the new one
|
||||||
finalTitle = await internals.reduceSize(newFile.title, bitrate);
|
finalTitle = await internals.reduceSize(
|
||||||
|
newFile.title,
|
||||||
|
bitrate,
|
||||||
|
newFile.audioTracks
|
||||||
|
);
|
||||||
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append title to the list of processed files
|
// Append title to the list of processed files
|
||||||
|
if (finalTitle.length > 0) {
|
||||||
processedFiles += `\n- ${finalTitle}`;
|
processedFiles += `\n- ${finalTitle}`;
|
||||||
updateMessage(`Fichier ${counter} traités.`);
|
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}.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send confirmation to the user that we're done
|
// Send confirmation to the user that we're done
|
||||||
await internals.confirmation(
|
await internals.confirmation(
|
||||||
`${files.length} fichiers traités : ${processedFiles}`
|
`${files.length} fichiers traités : ${processedFiles}` + errorMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
await internals.exit();
|
await internals.exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import ffprobe = require("ffprobe-static");
|
|
||||||
import child_process = require("child_process");
|
import child_process = require("child_process");
|
||||||
import path = require("path");
|
import path = require("path");
|
||||||
import { BrowserWindow } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import { existsSync, unlink } from "fs";
|
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 */
|
/** Create a new filename from the OG one */
|
||||||
export const getNewFilename = (ogFile: string, part: string) => {
|
export const getNewFilename = (ogFile: string, part: string) => {
|
||||||
const oldFile = path.parse(ogFile);
|
const oldFile = path.parse(ogFile);
|
||||||
|
@ -12,11 +16,20 @@ export const getNewFilename = (ogFile: string, part: string) => {
|
||||||
|
|
||||||
/** Return the duration of a video in second */
|
/** Return the duration of a video in second */
|
||||||
export const getVideoDuration = (file: string) => {
|
export const getVideoDuration = (file: string) => {
|
||||||
const command = `"${ffprobe.path}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`;
|
const command = `"${ffprobePath}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`;
|
||||||
const durationString = child_process.execSync(command).toString().trim();
|
const durationString = child_process.execSync(command).toString().trim();
|
||||||
return parseFloat(durationString);
|
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}"`;
|
||||||
|
const result = child_process.execSync(command, { encoding: "utf8" });
|
||||||
|
return JSON.parse(result).streams.map(
|
||||||
|
(v: { bit_rate: string }) => Number(v.bit_rate) / 1000
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/** Print an error to the console and open the dev tool panel */
|
/** Print an error to the console and open the dev tool panel */
|
||||||
export const printAndDevTool = (win: BrowserWindow, err: string) => {
|
export const printAndDevTool = (win: BrowserWindow, err: string) => {
|
||||||
win.webContents.openDevTools();
|
win.webContents.openDevTools();
|
||||||
|
@ -28,13 +41,18 @@ export const execute = (
|
||||||
command: string
|
command: string
|
||||||
): Promise<{ stdout: string; stderr: string }> => {
|
): Promise<{ stdout: string; stderr: string }> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
child_process.exec(command, (error, stdout, stderr) => {
|
const process = child_process.exec(command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
resolve({ stdout, stderr });
|
resolve({ stdout, stderr });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
processes.push(process);
|
||||||
|
process.on("exit", () => {
|
||||||
|
processes.splice(processes.indexOf(process), 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,11 +65,8 @@ export const deleteFile = (file: string) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Delete the 2pass files generated by ffmpeg, we're using
|
/** Delete the 2pass files generated by ffmpeg */
|
||||||
* the file location to know in which directory they are.
|
export const deleteTwoPassFiles = (directory: string) => {
|
||||||
* We're checking first if they exists where we are looking at. */
|
|
||||||
export const deleteTwoPassFiles = (file: string) => {
|
|
||||||
const directory = path.parse(file).dir;
|
|
||||||
const logFile = path.join(directory, "ffmpeg2pass-0.log");
|
const logFile = path.join(directory, "ffmpeg2pass-0.log");
|
||||||
|
|
||||||
if (existsSync(logFile)) {
|
if (existsSync(logFile)) {
|
||||||
|
|
Loading…
Reference in a new issue