if no compression is needed, optimize for streaming

This commit is contained in:
Mylloon 2024-08-22 17:47:21 +02:00
parent d4bb073218
commit 0399080d6e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 29 additions and 3 deletions

View file

@ -26,7 +26,7 @@ const metadataAudio = `-metadata:s:a:0 title="System sounds and microphone" \
-metadata:s:a:1 title="System sounds" \
-metadata:s:a:2 title="Microphone"`;
const extraArgs = "-movflags +faststart";
const shareOpt = "-movflags +faststart";
/** Register a new error */
const registerError = (win: BrowserWindow, err: string) => {
@ -109,7 +109,6 @@ app.whenReady().then(() => {
-map 0 -map 1:a -c:v copy \
-disposition:a 0 -disposition:a:0 default \
${metadataAudio} \
${extraArgs} \
"${outFile}"`
).catch((e) => registerError(win, e));
@ -185,7 +184,7 @@ app.whenReady().then(() => {
-c:v ${codec} -b:v ${videoBitrate}k -pass 2 -c:a copy \
${mappingTracks} -f mp4 \
${metadataAudio} \
${extraArgs} \
${shareOpt} \
"${finalFile}"`
).catch((e) => registerError(win, e));
@ -198,6 +197,25 @@ app.whenReady().then(() => {
return finalFile;
};
/** Move metadata at the begenning of the file */
const moveMetadata = async (file: string) => {
const finalFile = getNewFilename(file, "Shareable - ");
// Optimize for streaming
await execute(
`"${ffmpegPath}" -y \
-i "${file}" \
-map 0 -codec copy \
${shareOpt} \
"${finalFile}"`
).catch((e) => registerError(win, e));
// Delete the old video file
deleteFile(file);
return finalFile;
};
/* Context bridge */
ipcMain.handle("argv", () => process.argv);
ipcMain.handle("allowedExtensions", () => moviesFilter);
@ -209,6 +227,7 @@ app.whenReady().then(() => {
(_, 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));
});

View file

@ -15,6 +15,7 @@ contextBridge.exposeInMainWorld("internals", {
mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file),
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

@ -18,6 +18,7 @@ let internals: {
bitrate: number,
nbTracks: number
) => Promise<string>;
moveMetadata: (file: string) => Promise<string>;
confirmation: (text: string) => Promise<void>;
};
@ -133,6 +134,11 @@ const main = async () => {
bitrate,
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);
}
// Append title to the list of processed files