mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-24 03:12:41 +01:00
refactor
This commit is contained in:
parent
a5000a8977
commit
0f8ba50d22
@ -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);
|
||||
|
@ -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?
|
||||
|
@ -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, trea
|
||||
return 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 & MediaSource
|
||||
const 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 });
|
||||
|
Loading…
Reference in New Issue
Block a user