implement merge progress

pull/333/head
Mikael Finstad 6 years ago
parent 0dba7e1faf
commit e67e3bd839

@ -621,12 +621,14 @@ const App = memo(() => {
const outPath = getOutPath(newCustomOutDir, firstPath, `merged${ext}`); const outPath = getOutPath(newCustomOutDir, firstPath, `merged${ext}`);
// console.log('merge', paths); // console.log('merge', paths);
await ffmpegMergeFiles({ paths, outPath, allStreams }); await ffmpegMergeFiles({ paths, outPath, allStreams, onProgress: setCutProgress });
openDirToast({ icon: 'success', dirPath: outputDir, text: i18n.t('Files merged!') });
} catch (err) { } catch (err) {
errorToast(i18n.t('Failed to merge files. Make sure they are all of the exact same codecs')); errorToast(i18n.t('Failed to merge files. Make sure they are all of the exact same codecs'));
console.error('Failed to merge files', err); console.error('Failed to merge files', err);
} finally { } finally {
setWorking(); setWorking();
setCutProgress();
} }
}, [assureOutDirAccess]); }, [assureOutDirAccess]);
@ -997,7 +999,8 @@ const App = memo(() => {
}); });
if (outFiles.length > 1 && autoMerge) { if (outFiles.length > 1 && autoMerge) {
setCutProgress(0); // TODO implement progress setCutProgress(0);
setWorking(i18n.t('Merging'));
await autoMergeSegments({ await autoMergeSegments({
customOutDir, customOutDir,
@ -1005,6 +1008,7 @@ const App = memo(() => {
outFormat: fileFormat, outFormat: fileFormat,
isCustomFormatSelected, isCustomFormatSelected,
segmentPaths: outFiles, segmentPaths: outFiles,
onProgress: setCutProgress,
}); });
} }
@ -1035,6 +1039,7 @@ const App = memo(() => {
showFfmpegFail(err); showFfmpegFail(err);
} finally { } finally {
setWorking(); setWorking();
setCutProgress();
} }
}, [ }, [
effectiveRotation, outSegments, handleCutFailed, isRotationSet, effectiveRotation, outSegments, handleCutFailed, isRotationSet,

@ -422,9 +422,12 @@ export async function html5ifyDummy(filePath, outPath, onProgress) {
await transferTimestamps(filePath, outPath); await transferTimestamps(filePath, outPath);
} }
export async function mergeFiles({ paths, outPath, allStreams, outFormat }) { export async function mergeFiles({ paths, outPath, allStreams, outFormat, onProgress = () => {} }) {
console.log('Merging files', { paths }, 'to', outPath); console.log('Merging files', { paths }, 'to', outPath);
const durations = await pMap(paths, getDuration, { concurrency: 1 });
const totalDuration = sum(durations);
// Keep this similar to cut() // Keep this similar to cut()
const ffmpegArgs = [ const ffmpegArgs = [
'-hide_banner', '-hide_banner',
@ -456,18 +459,20 @@ export async function mergeFiles({ paths, outPath, allStreams, outFormat }) {
const ffmpegPath = getFfmpegPath(); const ffmpegPath = getFfmpegPath();
const process = execa(ffmpegPath, ffmpegArgs); const process = execa(ffmpegPath, ffmpegArgs);
handleProgress(process, totalDuration, onProgress);
stringToStream(concatTxt).pipe(process.stdin); stringToStream(concatTxt).pipe(process.stdin);
const result = await process; const result = await process;
console.log(result.stdout); console.log(result.stdout);
} }
export async function autoMergeSegments({ customOutDir, sourceFile, isCustomFormatSelected, outFormat, segmentPaths }) { export async function autoMergeSegments({ customOutDir, sourceFile, isCustomFormatSelected, outFormat, segmentPaths, onProgress }) {
const ext = getOutFileExtension({ isCustomFormatSelected, outFormat, filePath: sourceFile }); const ext = getOutFileExtension({ isCustomFormatSelected, outFormat, filePath: sourceFile });
const fileName = `cut-merged-${new Date().getTime()}${ext}`; const fileName = `cut-merged-${new Date().getTime()}${ext}`;
const outPath = getOutPath(customOutDir, sourceFile, fileName); const outPath = getOutPath(customOutDir, sourceFile, fileName);
await mergeFiles({ paths: segmentPaths, outPath, outFormat, allStreams: true }); await mergeFiles({ paths: segmentPaths, outPath, outFormat, allStreams: true, onProgress });
await pMap(segmentPaths, path => fs.unlink(path), { concurrency: 5 }); await pMap(segmentPaths, path => fs.unlink(path), { concurrency: 5 });
} }

Loading…
Cancel
Save