Skip to content

The swiss army knife of lossless video/audio editing

allow create chapters when merge files too

Mikael Finstad19c002b64abd
diff --git a/src/App.jsx b/src/App.jsx
index fcd751a8..df0c1697 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -42,7 +42,7 @@ import {
getDefaultOutFormat, getFormatData, mergeFiles as ffmpegMergeFiles, renderThumbnails as ffmpegRenderThumbnails,
readFrames, renderWaveformPng, html5ifyDummy, cutMultiple, extractStreams, autoMergeSegments, getAllStreams,
findNearestKeyFrameTime, html5ify as ffmpegHtml5ify, isStreamThumbnail, isAudioSupported, isIphoneHevc, tryReadChaptersToEdl,
- fixInvalidDuration, getDuration, getTimecodeFromStreams,
+ fixInvalidDuration, getDuration, getTimecodeFromStreams, createChaptersFromSegments,
} from './ffmpeg';
import { saveCsv, loadCsv, loadXmeml, loadCue, loadPbf } from './edlStore';
import {
@@ -63,7 +63,7 @@ const isDev = window.require('electron-is-dev');
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 { extname, parse: parsePath } = window.require('path');
const { dialog, app } = electron.remote;
@@ -622,7 +622,7 @@ const App = memo(() => {
return { cancel: false, newCustomOutDir };
}, [customOutDir]);
- const mergeFiles = useCallback(async ({ paths, allStreams }) => {
+ const mergeFiles = useCallback(async ({ paths, allStreams, segmentsToChapters: segmentsToChapters2 }) => {
try {
setWorking(i18n.t('Merging'));
@@ -634,8 +634,14 @@ const App = memo(() => {
const outPath = getOutPath(newCustomOutDir, firstPath, `merged${ext}`);
const outDir = getOutDir(customOutDir, firstPath);
+ let chapters;
+ if (segmentsToChapters2) {
+ const chapterNames = paths.map((path) => parsePath(path).name);
+ chapters = await createChaptersFromSegments({ segmentPaths: paths, chapterNames });
+ }
+
// console.log('merge', paths);
- await ffmpegMergeFiles({ paths, outPath, allStreams, ffmpegExperimental, onProgress: setCutProgress, preserveMovData, preserveMetadataOnMerge });
+ await ffmpegMergeFiles({ paths, outPath, outDir, allStreams, ffmpegExperimental, onProgress: setCutProgress, preserveMovData, preserveMetadataOnMerge, chapters });
openDirToast({ icon: 'success', dirPath: outDir, text: i18n.t('Files merged!') });
} catch (err) {
errorToast(i18n.t('Failed to merge files. Make sure they are all of the exact same codecs'));
@@ -644,7 +650,7 @@ const App = memo(() => {
setWorking();
setCutProgress();
}
- }, [assureOutDirAccess, outputDir, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge]);
+ }, [assureOutDirAccess, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge, customOutDir]);
const toggleCaptureFormat = useCallback(() => setCaptureFormat(f => (f === 'png' ? 'jpeg' : 'png')), []);
diff --git a/src/ffmpeg.js b/src/ffmpeg.js
index 0df339d5..02c8d1f8 100644
--- a/src/ffmpeg.js
+++ b/src/ffmpeg.js
@@ -586,7 +586,7 @@ export async function mergeFiles({ paths, outDir, outPath, allStreams, outFormat
await transferTimestamps(paths[0], outPath);
}
-async function createChaptersFromSegments({ segmentPaths, chapterNames }) {
+export async function createChaptersFromSegments({ segmentPaths, chapterNames }) {
if (chapterNames) {
try {
const durations = await pMap(segmentPaths, (segmentPath) => getDuration(segmentPath), { concurrency: 3 });
diff --git a/src/merge/SortableFiles.jsx b/src/merge/SortableFiles.jsx
index 8e2e9bff..aff37362 100644
--- a/src/merge/SortableFiles.jsx
+++ b/src/merge/SortableFiles.jsx
@@ -29,12 +29,14 @@ const SortableContainer = sortableContainer(({ items }) => (
));
const SortableFiles = memo(({
- items: itemsProp, onChange, helperContainer, onAllStreamsChange,
+ items: itemsProp, onChange, helperContainer, onAllStreamsChange, onSegmentsToChaptersChange,
}) => {
const [items, setItems] = useState(itemsProp);
const [allStreams, setAllStreams] = useState(false);
+ const [segmentsToChapters, setSegmentsToChapters] = useState(false);
useEffect(() => onAllStreamsChange(allStreams), [allStreams, onAllStreamsChange]);
+ useEffect(() => onSegmentsToChaptersChange(segmentsToChapters), [segmentsToChapters, onSegmentsToChaptersChange]);
useEffect(() => onChange(items), [items, onChange]);
const onSortEnd = useCallback(({ oldIndex, newIndex }) => {
@@ -57,8 +59,14 @@ const SortableFiles = memo(({
/>
<div style={{ marginTop: 10 }}>
- <Checkbox checked={allStreams} onChange={e => setAllStreams(e.target.checked)} label={t('Include all tracks?')} />
- <div style={{ fontSize: 12, textAlign: 'left' }}>{t('If this is checked, all audio/video/subtitle/data tracks will be included. This may not always work for all file types. If not checked, only default streams will be included.')}</div>
+ <div>
+ <Checkbox checked={allStreams} onChange={e => setAllStreams(e.target.checked)} label={t('Include all tracks?')} />
+ <div style={{ fontSize: 12, textAlign: 'left' }}>{t('If this is checked, all audio/video/subtitle/data tracks will be included. This may not always work for all file types. If not checked, only default streams will be included.')}</div>
+ </div>
+
+ <div>
+ <Checkbox checked={segmentsToChapters} onChange={e => setSegmentsToChapters(e.target.checked)} label={t('Create chapters from merged segments? (slow)')} />
+ </div>
</div>
</div>
);
diff --git a/src/merge/merge.jsx b/src/merge/merge.jsx
index ae7ee691..6cb047c6 100644
--- a/src/merge/merge.jsx
+++ b/src/merge/merge.jsx
@@ -20,6 +20,7 @@ export async function showMergeDialog(paths, onMergeClick) {
let swalElem;
let outPaths = paths;
let allStreams = false;
+ let segmentsToChapters = false;
const { dismiss } = await MySwal.fire({
width: '90%',
showCancelButton: true,
@@ -29,12 +30,13 @@ export async function showMergeDialog(paths, onMergeClick) {
items={outPaths}
onChange={(val) => { outPaths = val; }}
onAllStreamsChange={(val) => { allStreams = val; }}
+ onSegmentsToChaptersChange={(val) => { segmentsToChapters = val; }}
helperContainer={() => swalElem}
/>),
});
if (!dismiss) {
- await onMergeClick({ paths: outPaths, allStreams });
+ await onMergeClick({ paths: outPaths, allStreams, segmentsToChapters });
}
}