1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 18:32:34 +01:00

always save llc inside source directory

also refactor getOutPath
closes #905
This commit is contained in:
Mikael Finstad 2022-01-14 18:03:42 +07:00
parent d09f03306a
commit 5534574df7
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
6 changed files with 16 additions and 17 deletions

View File

@ -523,9 +523,10 @@ const App = memo(() => {
const projectSuffix = 'proj.llc';
const oldProjectSuffix = 'llc-edl.csv';
const getEdlFilePath = useCallback((fp) => getOutPath(customOutDir, fp, projectSuffix), [customOutDir]);
// Old versions of LosslessCut used CSV files:
const getEdlFilePathOld = useCallback((fp) => getOutPath(customOutDir, fp, oldProjectSuffix), [customOutDir]);
// New LLC format is stored along with input file https://github.com/mifi/lossless-cut/issues/905
const getEdlFilePath = useCallback((fp) => getOutPath({ filePath: fp, nameSuffix: projectSuffix }), []);
// Old versions of LosslessCut used CSV files and stored them in customOutDir:
const getEdlFilePathOld = useCallback((fp) => getOutPath({ customOutDir, filePath: fp, nameSuffix: oldProjectSuffix }), [customOutDir]);
const edlFilePath = useMemo(() => getEdlFilePath(filePath), [getEdlFilePath, filePath]);
const currentSaveOperation = useMemo(() => {
@ -632,7 +633,7 @@ const App = memo(() => {
if (cancel) return;
const ext = extname(firstPath);
const outPath = getOutPath(newCustomOutDir, firstPath, `merged${ext}`);
const outPath = getOutPath({ customOutDir: newCustomOutDir, filePath: firstPath, nameSuffix: `merged${ext}` });
const outDir = getOutDir(customOutDir, firstPath);
let chapters;
@ -896,7 +897,7 @@ const App = memo(() => {
async function doHtml5ify() {
if (speed === 'fastest') {
const path = getOutPath(cod, fp, `${html5ifiedPrefix}${html5dummySuffix}.mkv`);
const path = getOutPath({ customOutDir: cod, filePath: fp, nameSuffix: `${html5ifiedPrefix}${html5dummySuffix}.mkv` });
try {
setCutProgress(0);
await html5ifyDummy({ filePath: fp, outPath: path, onProgress: setCutProgress });

View File

@ -82,7 +82,7 @@ const Settings = memo(({
<Row>
<KeyCell>
{t('Working directory')}<br />
{t('This is where working files, exported files, project files (LLC) are stored.')}
{t('This is where working files and exported files are stored.')}
</KeyCell>
<Table.TextCell>
<Button iconBefore={customOutDir ? FolderCloseIcon : DocumentIcon} onClick={changeOutDir}>
@ -151,7 +151,7 @@ const Settings = memo(({
<Row>
<KeyCell>
{t('Auto save project file?')}<br />
{t('The project will be stored alongside the output files as a project LLC file')}
{t('The project will be stored alongside the input file as a project LLC file')}
</KeyCell>
<Table.TextCell>
<Checkbox

View File

@ -23,7 +23,7 @@ function getFrameFromVideo(video, format) {
export async function captureFrameFfmpeg({ customOutDir, filePath, currentTime, captureFormat, enableTransferTimestamps }) {
const time = formatDuration({ seconds: currentTime, fileNameFriendly: true });
const outPath = getOutPath(customOutDir, filePath, `${time}.${captureFormat}`);
const outPath = getOutPath({ customOutDir, filePath, nameSuffix: `${time}.${captureFormat}` });
await ffmpegCaptureFrame({ timestamp: currentTime, videoPath: filePath, outPath });
if (enableTransferTimestamps) await transferTimestamps(filePath, outPath, currentTime);
@ -36,7 +36,7 @@ export async function captureFrameFromTag({ customOutDir, filePath, currentTime,
const ext = mime.extension(buf.mimetype);
const time = formatDuration({ seconds: currentTime, fileNameFriendly: true });
const outPath = getOutPath(customOutDir, filePath, `${time}.${ext}`);
const outPath = getOutPath({ customOutDir, filePath, nameSuffix: `${time}.${ext}` });
await fs.writeFile(outPath, buf);
if (enableTransferTimestamps) await transferTimestamps(filePath, outPath, currentTime);

View File

@ -314,7 +314,7 @@ async function extractNonAttachmentStreams({ customOutDir, filePath, streams })
console.log('Extracting', streams.length, 'normal streams');
const streamArgs = flatMap(streams, ({ index, codec, type, format: { format, ext } }) => [
'-map', `0:${index}`, '-c', 'copy', '-f', format, '-y', getOutPath(customOutDir, filePath, `stream-${index}-${type}-${codec}.${ext}`),
'-map', `0:${index}`, '-c', 'copy', '-f', format, '-y', getOutPath({ customOutDir, filePath, nameSuffix: `stream-${index}-${type}-${codec}.${ext}` }),
]);
const ffmpegArgs = [
@ -336,7 +336,7 @@ async function extractAttachmentStreams({ customOutDir, filePath, streams }) {
const streamArgs = flatMap(streams, ({ index, codec_name: codec, codec_type: type }) => {
const ext = codec || 'bin';
return [
`-dump_attachment:${index}`, getOutPath(customOutDir, filePath, `stream-${index}-${type}-${codec}.${ext}`),
`-dump_attachment:${index}`, getOutPath({ customOutDir, filePath, nameSuffix: `stream-${index}-${type}-${codec}.${ext}` }),
];
});

View File

@ -274,8 +274,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
const autoMergeSegments = useCallback(async ({ customOutDir, isCustomFormatSelected, outFormat, segmentPaths, ffmpegExperimental, onProgress, preserveMovData, movFastStart, autoDeleteMergedSegments, chapterNames, preserveMetadataOnMerge }) => {
const ext = getOutFileExtension({ isCustomFormatSelected, outFormat, filePath });
const fileName = `cut-merged-${new Date().getTime()}${ext}`;
const outPath = getOutPath(customOutDir, filePath, fileName);
const outPath = getOutPath({ customOutDir, filePath, nameSuffix: `cut-merged-${new Date().getTime()}${ext}` });
const outDir = getOutDir(customOutDir, filePath);
const chapters = await createChaptersFromSegments({ segmentPaths, chapterNames });
@ -404,8 +403,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
// https://stackoverflow.com/questions/34118013/how-to-determine-webm-duration-using-ffprobe
const fixInvalidDuration = useCallback(async ({ fileFormat, customOutDir }) => {
const ext = getOutFileExtension({ outFormat: fileFormat, filePath });
const fileName = `reformatted${ext}`;
const outPath = getOutPath(customOutDir, filePath, fileName);
const outPath = getOutPath({ customOutDir, filePath, nameSuffix: `reformatted${ext}` });
const ffmpegArgs = [
'-hide_banner',

View File

@ -23,7 +23,7 @@ export function getFileBaseName(filePath) {
return parsed.name;
}
export function getOutPath(customOutDir, filePath, nameSuffix) {
export function getOutPath({ customOutDir, filePath, nameSuffix }) {
if (!filePath) return undefined;
return join(getOutDir(customOutDir, filePath), `${getFileBaseName(filePath)}-${nameSuffix}`);
}
@ -238,7 +238,7 @@ export async function findExistingHtml5FriendlyFile(fp, cod) {
export function getHtml5ifiedPath(cod, fp, type) {
// See also inside ffmpegHtml5ify
const ext = (isMac && ['slowest', 'slow', 'slow-audio'].includes(type)) ? 'mp4' : 'mkv';
return getOutPath(cod, fp, `${html5ifiedPrefix}${type}.${ext}`);
return getOutPath({ customOutDir: cod, filePath: fp, nameSuffix: `${html5ifiedPrefix}${type}.${ext}` });
}
export async function deleteFiles({ toDelete, paths: { previewFilePath, filePath, edlFilePath } }) {