The swiss army knife of lossless video/audio editing
refactor
Mikael Finstad0f8ba50d2295
diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.tsindex d3a195ff..f05fd736 100644--- a/src/main/ffmpeg.ts+++ b/src/main/ffmpeg.ts@@ -125,7 +125,9 @@ export async function runFfmpegConcat({ ffmpegArgs, concatTxt, totalDuration, on}export async function runFfmpegWithProgress({ ffmpegArgs, duration, onProgress }: {- ffmpegArgs: string[], duration: number | undefined, onProgress: (a: number) => void,+ ffmpegArgs: string[],+ duration?: number | undefined,+ onProgress: (a: number) => void,}) {const process = runFfmpegProcess(ffmpegArgs);assert(process.stderr != null);diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsxindex e7b7b656..e5890115 100644--- a/src/renderer/src/App.tsx+++ b/src/renderer/src/App.tsx@@ -1608,7 +1608,7 @@ function App() {setWorking({ text: i18n.t('Fixing file duration') });setCutProgress(0);invariant(fileFormat != null);- const path = await fixInvalidDuration({ fileFormat, customOutDir, duration, onProgress: setCutProgress });+ const path = await fixInvalidDuration({ fileFormat, customOutDir, onProgress: setCutProgress });showNotification({ icon: 'info', text: i18n.t('Duration has been fixed') });await loadMedia({ filePath: path });@@ -1619,7 +1619,7 @@ function App() {setWorking(undefined);setCutProgress(undefined);}- }, [checkFileOpened, customOutDir, duration, fileFormat, fixInvalidDuration, loadMedia, setWorking, showNotification, workingRef]);+ }, [checkFileOpened, customOutDir, fileFormat, fixInvalidDuration, loadMedia, setWorking, showNotification, workingRef]);const addStreamSourceFile = useCallback(async (path: string) => {if (allFilesMeta[path]) return undefined; // Already added?diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.tsindex fa1dc69e..9035adf5 100644--- a/src/renderer/src/hooks/useFfmpegOperations.ts+++ b/src/renderer/src/hooks/useFfmpegOperations.ts@@ -379,7 +379,6 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea];appendFfmpegCommandLog(ffmpegArgs);-const result = await runFfmpegWithProgress({ ffmpegArgs, duration: cutDuration, onProgress });logStdoutStderr(result);@@ -579,8 +578,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, treareturn outPath;}, [treatOutputFileModifiedTimeAsStart]);- // This is just used to load something into the player with correct length,- // so user can seek and then we render frames using ffmpeg & MediaSource+ // This is just used to load something into the player with correct duration,+ // so that the user can seek and then we render frames using ffmpeg & MediaSourceconst html5ifyDummy = useCallback(async ({ filePath: filePathArg, outPath, onProgress }) => {console.log('Making ffmpeg-assisted dummy file', { filePathArg, outPath });@@ -603,11 +602,14 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea}, [treatOutputFileModifiedTimeAsStart]);// https://stackoverflow.com/questions/34118013/how-to-determine-webm-duration-using-ffprobe- const fixInvalidDuration = useCallback(async ({ fileFormat, customOutDir, duration, onProgress }: { fileFormat: string, customOutDir?: string | undefined, duration: number | undefined, onProgress }) => {+ const fixInvalidDuration = useCallback(async ({ fileFormat, customOutDir, onProgress }: {+ fileFormat: string,+ customOutDir?: string | undefined,+ onProgress: (a: number) => void,+ }) => {invariant(filePath != null);const ext = getOutFileExtension({ outFormat: fileFormat, filePath });const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `reformatted${ext}` });- invariant(outPath != null);const ffmpegArgs = ['-hide_banner',@@ -624,8 +626,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea];appendFfmpegCommandLog(ffmpegArgs);-- const result = await runFfmpegWithProgress({ ffmpegArgs, duration, onProgress });+ const result = await runFfmpegWithProgress({ ffmpegArgs, onProgress });logStdoutStderr(result);await transferTimestamps({ inPath: filePath, outPath, treatOutputFileModifiedTimeAsStart });