fix broken merge in MAS

pull/304/head
Mikael Finstad 6 years ago
parent 75157b8e6c
commit 19cb1e9944

@ -38,7 +38,7 @@ import allOutFormats from './outFormats';
import { captureFrameFromTag, captureFrameFfmpeg } from './capture-frame';
import {
defaultProcessedCodecTypes, getStreamFps, isCuttingStart, isCuttingEnd,
getDefaultOutFormat, getFormatData, renderFrame, mergeAnyFiles, renderThumbnails as ffmpegRenderThumbnails,
getDefaultOutFormat, getFormatData, renderFrame, mergeFiles as ffmpegMergeFiles, renderThumbnails as ffmpegRenderThumbnails,
readFrames, renderWaveformPng, html5ifyDummy, cutMultiple, extractStreams, autoMergeSegments, getAllStreams,
findNearestKeyFrameTime, html5ify as ffmpegHtml5ify,
} from './ffmpeg';
@ -57,6 +57,7 @@ import loadingLottie from './7077-magic-flow.json';
const electron = window.require('electron'); // eslint-disable-line
const trash = window.require('trash');
const { unlink, exists } = window.require('fs-extra');
const { extname } = window.require('path');
const { dialog, app } = electron.remote;
@ -585,21 +586,47 @@ const App = memo(() => {
setRotationPreviewRequested(true);
}, []);
const assureOutDirAccess = useCallback(async (outFilePath) => {
const customOutDirExists = await dirExists(customOutDir);
if (!customOutDirExists) setCustomOutDir(undefined);
const newCustomOutDir = customOutDirExists ? customOutDir : undefined;
const outDirPath = getOutDir(newCustomOutDir, outFilePath);
const hasDirWriteAccess = await checkDirWriteAccess(outDirPath);
if (!hasDirWriteAccess) {
if (isMasBuild) {
const newOutDir = await askForOutDir(outDirPath);
// User cancelled open dialog. Refuse to continue, because we will get permission denied error from MAS sandbox
if (!newOutDir) return { cancel: true };
setCustomOutDir(newOutDir);
} else {
errorToast(i18n.t('You have no write access to the directory of this file, please select a custom working dir'));
}
}
return { cancel: false, newCustomOutDir };
}, [askForOutDir, customOutDir]);
const mergeFiles = useCallback(async ({ paths, allStreams }) => {
try {
setWorking(true);
const firstPath = paths[0];
const { newCustomOutDir, cancel } = await assureOutDirAccess(firstPath);
if (cancel) return;
const ext = extname(firstPath);
const outPath = getOutPath(newCustomOutDir, firstPath, `merged${ext}`);
// console.log('merge', paths);
await mergeAnyFiles({
customOutDir, paths, allStreams,
});
await ffmpegMergeFiles({ paths, outPath, allStreams });
} catch (err) {
errorToast(i18n.t('Failed to merge files. Make sure they are all of the exact same format and codecs'));
console.error('Failed to merge files', err);
} finally {
setWorking(false);
}
}, [customOutDir]);
}, [assureOutDirAccess]);
const toggleCaptureFormat = useCallback(() => setCaptureFormat(f => (f === 'png' ? 'jpeg' : 'png')), []);
const toggleKeyframeCut = useCallback(() => setKeyframeCut(val => !val), []);
@ -1180,22 +1207,8 @@ const App = memo(() => {
const firstFile = filePaths[0];
const customOutDirExists = await dirExists(customOutDir);
if (!customOutDirExists) setCustomOutDir(undefined);
const newCustomOutDir = customOutDirExists ? customOutDir : undefined;
const outDirPath = getOutDir(newCustomOutDir, firstFile);
const hasDirWriteAccess = await checkDirWriteAccess(outDirPath);
if (!hasDirWriteAccess) {
if (isMasBuild) {
const newOutDir = await askForOutDir(outDirPath);
// User cancelled open dialog, refuse to open file, because we will get permission denied from sandbox
if (!newOutDir) return;
setCustomOutDir(newOutDir);
} else {
errorToast(i18n.t('You have no write access to the directory of this file, please select a custom working dir'));
}
}
const { newCustomOutDir, cancel } = await assureOutDirAccess(firstFile);
if (cancel) return;
if (!isFileOpened) {
load({ filePath: firstFile, customOutDir: newCustomOutDir });
@ -1221,7 +1234,7 @@ const App = memo(() => {
addStreamSourceFile(firstFile);
setStreamsSelectorShown(true);
}
}, [addStreamSourceFile, isFileOpened, load, mergeFiles, customOutDir, askForOutDir]);
}, [addStreamSourceFile, isFileOpened, load, mergeFiles, assureOutDirAccess]);
const onDrop = useCallback(async (ev) => {
ev.preventDefault();

@ -37,17 +37,17 @@ const TopMenu = memo(({
<div style={{ flexGrow: 1 }} />
<Button
iconBefore={customOutDir ? 'folder-open' : undefined}
height={20}
onClick={withBlur(changeOutDir)}
title={customOutDir}
>
{customOutDir ? t('Working dir set') : t('Working dir unset')}
</Button>
{filePath && (
<Fragment>
<Button
iconBefore={customOutDir ? 'folder-open' : undefined}
height={20}
onClick={withBlur(changeOutDir)}
title={customOutDir}
>
{customOutDir ? t('Working dir set') : t('Working dir unset')}
</Button>
<div style={{ width: 60 }}>{renderOutFmt({ height: 20 })}</div>
<Button

@ -364,7 +364,7 @@ export async function html5ifyDummy(filePath, outPath) {
await transferTimestamps(filePath, outPath);
}
async function mergeFiles({ paths, outPath, allStreams }) {
export async function mergeFiles({ paths, outPath, allStreams }) {
console.log('Merging files', { paths }, 'to', outPath);
// https://blog.yo1.dog/fix-for-ffmpeg-protocol-not-on-whitelist-error-for-urls/
@ -399,13 +399,6 @@ async function mergeFiles({ paths, outPath, allStreams }) {
console.log(result.stdout);
}
export async function mergeAnyFiles({ customOutDir, paths, allStreams }) {
const firstPath = paths[0];
const ext = extname(firstPath);
const outPath = getOutPath(customOutDir, firstPath, `merged${ext}`);
return mergeFiles({ paths, outPath, allStreams });
}
export async function autoMergeSegments({ customOutDir, sourceFile, segmentPaths }) {
const ext = extname(sourceFile);
const outPath = getOutPath(customOutDir, sourceFile, `cut-merged-${new Date().getTime()}${ext}`);

@ -34,7 +34,7 @@ export async function showMergeDialog(paths, onMergeClick) {
});
if (!dismiss) {
onMergeClick({ paths: outPaths, allStreams });
await onMergeClick({ paths: outPaths, allStreams });
}
}

Loading…
Cancel
Save