Skip to content

The swiss army knife of lossless video/audio editing

allow per-stream bitstream filters

Mikael Finstadc88e63c5ef24
diff --git a/package.json b/package.json
index 5a1e77f4..ee9963d7 100644
--- a/package.json
+++ b/package.json
@@ -66,6 +66,7 @@
"framer-motion": "^9.0.3",
"i18next-parser": "^7.6.0",
"icon-gen": "^3.0.0",
+ "immer": "^10.0.2",
"ky": "^0.33.1",
"luxon": "^3.3.0",
"mkdirp": "^1.0.3",
diff --git a/src/App.jsx b/src/App.jsx
index 1d4ba538..35776d54 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -7,6 +7,7 @@ import useDebounceOld from 'react-use/lib/useDebounce'; // Want to phase out thi
import { useDebounce } from 'use-debounce';
import i18n from 'i18next';
import { useTranslation } from 'react-i18next';
+import { produce } from 'immer';
import fromPairs from 'lodash/fromPairs';
import sortBy from 'lodash/sortBy';
@@ -130,8 +131,7 @@ const App = memo(() => {
const [filePath, setFilePath] = useState('');
const [externalFilesMeta, setExternalFilesMeta] = useState({});
const [customTagsByFile, setCustomTagsByFile] = useState({});
- const [customTagsByStreamId, setCustomTagsByStreamId] = useState({});
- const [dispositionByStreamId, setDispositionByStreamId] = useState({});
+ const [paramsByStreamId, setParamsByStreamId] = useState(new Map());
const [detectedFps, setDetectedFps] = useState();
const [mainFileMeta, setMainFileMeta] = useState({ streams: [], formatData: {} });
const [mainVideoStream, setMainVideoStream] = useState();
@@ -698,8 +698,7 @@ const App = memo(() => {
setFilePath(''); // Setting video src="" prevents memory leak in chromium
setExternalFilesMeta({});
setCustomTagsByFile({});
- setCustomTagsByStreamId({});
- setDispositionByStreamId({});
+ setParamsByStreamId(new Map());
setDetectedFps();
setMainFileMeta({ streams: [], formatData: [] });
setMainVideoStream();
@@ -1146,8 +1145,7 @@ const App = memo(() => {
movFastStart,
avoidNegativeTs,
customTagsByFile,
- customTagsByStreamId,
- dispositionByStreamId,
+ paramsByStreamId,
chapters: chaptersToAdd,
detectedFps,
});
@@ -1229,7 +1227,7 @@ const App = memo(() => {
setWorking();
setCutProgress();
}
- }, [numStreamsToCopy, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, segmentsToExport, getOutSegError, cutMultiple, outputDir, customOutDir, fileFormat, duration, isRotationSet, effectiveRotation, copyFileStreams, allFilesMeta, keyframeCut, shortestFlag, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge, movFastStart, avoidNegativeTs, customTagsByFile, customTagsByStreamId, dispositionByStreamId, detectedFps, enableOverwriteOutput, willMerge, exportConfirmEnabled, mainFileFormatData, mainStreams, exportExtraStreams, areWeCutting, hideAllNotifications, cleanupChoices, cleanupFiles, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, isCustomFormatSelected, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]);
+ }, [numStreamsToCopy, setWorking, segmentsToChaptersOnly, outSegTemplateOrDefault, generateOutSegFileNames, segmentsToExport, getOutSegError, cutMultiple, outputDir, customOutDir, fileFormat, duration, isRotationSet, effectiveRotation, copyFileStreams, allFilesMeta, keyframeCut, shortestFlag, ffmpegExperimental, preserveMovData, preserveMetadataOnMerge, movFastStart, avoidNegativeTs, customTagsByFile, paramsByStreamId, detectedFps, willMerge, enableOverwriteOutput, exportConfirmEnabled, mainFileFormatData, mainStreams, exportExtraStreams, areWeCutting, hideAllNotifications, cleanupChoices, cleanupFiles, selectedSegmentsOrInverse, segmentsToChapters, invertCutSegments, autoConcatCutSegments, isCustomFormatSelected, autoDeleteMergedSegments, nonCopiedExtraStreams, filePath, handleExportFailed]);
const onExportPress = useCallback(async () => {
if (!filePath || workingRef.current || segmentsToExport.length < 1) return;
@@ -1675,13 +1673,21 @@ const App = memo(() => {
return fileMeta;
}, [allFilesMeta, setCopyStreamIdsForPath]);
+ const updateStreamParams = useCallback((fileId, streamId, setter) => setParamsByStreamId(produce((draft) => {
+ if (!draft.has(fileId)) draft.set(fileId, new Map());
+ const fileMap = draft.get(fileId);
+ if (!fileMap.has(streamId)) fileMap.set(streamId, new Map());
+
+ setter(fileMap.get(streamId));
+ })), [setParamsByStreamId]);
+
const addFileAsCoverArt = useCallback(async (path) => {
const fileMeta = await addStreamSourceFile(path);
if (!fileMeta) return false;
const firstIndex = fileMeta.streams[0].index;
- setDispositionByStreamId((old) => ({ ...old, [path]: { [firstIndex]: 'attached_pic' } }));
+ updateStreamParams(path, firstIndex, (params) => params.set('disposition', 'attached_pic'));
return true;
- }, [addStreamSourceFile]);
+ }, [addStreamSourceFile, updateStreamParams]);
const captureSnapshotAsCoverArt = useCallback(async () => {
if (!filePath) return;
@@ -2436,10 +2442,8 @@ const App = memo(() => {
nonCopiedExtraStreams={nonCopiedExtraStreams}
customTagsByFile={customTagsByFile}
setCustomTagsByFile={setCustomTagsByFile}
- customTagsByStreamId={customTagsByStreamId}
- setCustomTagsByStreamId={setCustomTagsByStreamId}
- dispositionByStreamId={dispositionByStreamId}
- setDispositionByStreamId={setDispositionByStreamId}
+ paramsByStreamId={paramsByStreamId}
+ updateStreamParams={updateStreamParams}
/>
)}
</Sheet>
diff --git a/src/StreamsSelector.jsx b/src/StreamsSelector.jsx
index d4796f5b..4b05babc 100644
--- a/src/StreamsSelector.jsx
+++ b/src/StreamsSelector.jsx
@@ -1,10 +1,10 @@
-import React, { memo, useState, useMemo, useCallback } from 'react';
+import React, { memo, useState, useMemo, useCallback, useRef, useEffect } from 'react';
import { FaImage, FaCheckCircle, FaPaperclip, FaVideo, FaVideoSlash, FaFileImport, FaVolumeUp, FaVolumeMute, FaBan, FaFileExport } from 'react-icons/fa';
import { GoFileBinary } from 'react-icons/go';
import { FiEdit, FiCheck, FiTrash } from 'react-icons/fi';
import { MdSubtitles } from 'react-icons/md';
-import { BookIcon, TextInput, MoreIcon, Position, Popover, Menu, TrashIcon, EditIcon, InfoSignIcon, IconButton, Heading, SortAscIcon, SortDescIcon, Dialog, Button, PlusIcon, ForkIcon, WarningSignIcon } from 'evergreen-ui';
+import { Checkbox, BookIcon, TextInput, MoreIcon, Position, Popover, Menu, TrashIcon, EditIcon, InfoSignIcon, IconButton, Heading, SortAscIcon, SortDescIcon, Dialog, Button, PlusIcon, ForkIcon, WarningSignIcon } from 'evergreen-ui';
import { useTranslation } from 'react-i18next';
import prettyBytes from 'pretty-bytes';
@@ -22,10 +22,10 @@ const activeColor = '#429777';
const dispositionOptions = ['default', 'dub', 'original', 'comment', 'lyrics', 'karaoke', 'forced', 'hearing_impaired', 'visual_impaired', 'clean_effects', 'attached_pic', 'captions', 'descriptions', 'dependent', 'metadata'];
const unchangedDispositionValue = 'llc_disposition_unchanged';
-const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) => {
+const TagEditor = memo(({ existingTags, customTags, editingTag, setEditingTag, onTagChange, onTagReset }) => {
const { t } = useTranslation();
+ const ref = useRef();
- const [editingTag, setEditingTag] = useState();
const [editingTagVal, setEditingTagVal] = useState();
const [newTag, setNewTag] = useState();
@@ -35,7 +35,7 @@ const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) =
onTagReset(editingTag);
setEditingTag();
setNewTag();
- }, [editingTag, onTagReset]);
+ }, [editingTag, onTagReset, setEditingTag]);
function onEditClick(tag) {
if (newTag) {
@@ -60,13 +60,19 @@ const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) =
onEditClick();
}
- const onAddPress = useCallback(async () => {
+ const onAddPress = useCallback(async (e) => {
+ e.preventDefault();
+ e.target.blur();
const tag = await askForMetadataKey();
if (!tag || Object.keys(mergedTags).includes(tag)) return;
setEditingTag(tag);
setEditingTagVal('');
setNewTag(tag);
- }, [mergedTags]);
+ }, [mergedTags, setEditingTag]);
+
+ useEffect(() => {
+ ref.current?.focus();
+ }, [editingTag]);
return (
<>
@@ -85,7 +91,7 @@ const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) =
<td style={{ paddingTop: 5, paddingBottom: 5 }}>
{editingThis ? (
<form style={{ display: 'inline' }} onSubmit={onSubmit}>
- <TextInput placeholder={t('Enter value')} value={editingTagVal || ''} onChange={(e) => setEditingTagVal(e.target.value)} />
+ <TextInput ref={ref} placeholder={t('Enter value')} value={editingTagVal || ''} onChange={(e) => setEditingTagVal(e.target.value)} />
</form>
) : (
<span style={{ color: thisTagCustom ? activeColor : undefined, fontWeight: thisTagCustom ? 'bold' : undefined }}>{mergedTags[tag]}</span>
@@ -105,6 +111,8 @@ const TagEditor = memo(({ existingTags, customTags, onTagChange, onTagReset }) =
});
const EditFileDialog = memo(({ editingFile, allFilesMeta, customTagsByFile, setCustomTagsByFile }) => {
+ const [editingTag, setEditingTag] = useState();
+
const { formatData } = allFilesMeta[editingFile];
const existingTags = formatData.tags || {};
const customTags = customTagsByFile[editingFile] || {};
@@ -120,14 +128,13 @@ const EditFileDialog = memo(({ editingFile, allFilesMeta, customTagsByFile, setC
});
}, [editingFile, setCustomTagsByFile]);
- return <TagEditor existingTags={existingTags} customTags={customTags} onTagChange={onTagChange} onTagReset={onTagReset} />;
+ return <TagEditor existingTags={existingTags} customTags={customTags} editingTag={editingTag} setEditingTag={setEditingTag} onTagChange={onTagChange} onTagReset={onTagReset} />;
});
const getStreamDispositionsObj = (stream) => ((stream && stream.disposition) || {});
-const getStreamCustomDisposition = (dispositionByStreamId, file, streamId) => (dispositionByStreamId[file] || {})[streamId];
-function getStreamEffectiveDisposition(dispositionByStreamId, file, stream) {
- const customDisposition = getStreamCustomDisposition(dispositionByStreamId, file, stream.index);
+function getStreamEffectiveDisposition(paramsByStreamId, fileId, stream) {
+ const customDisposition = paramsByStreamId.get(fileId)?.get(stream.index)?.get('disposition');
const existingDispositionsObj = getStreamDispositionsObj(stream);
if (customDisposition) return customDisposition;
@@ -135,47 +142,75 @@ function getStreamEffectiveDisposition(dispositionByStreamId, file, stream) {
}
-const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, path: editingFile }, allFilesMeta, customTagsByStreamId, setCustomTagsByStreamId }) => {
+const StreamParametersEditor = ({ stream, streamParams, updateStreamParams }) => {
+ const { t } = useTranslation();
+
+ const ui = [];
+ // https://github.com/mifi/lossless-cut/issues/1680#issuecomment-1682915193
+ if (stream.codec_name === 'h264') {
+ ui.push(
+ <Checkbox key="bsfH264Mp4toannexb" checked={!!streamParams.get('bsfH264Mp4toannexb')} label={t('Enable "{{filterName}}" bitstream filter.', { filterName: 'h264_mp4toannexb' })} onChange={(e) => updateStreamParams((params) => params.set('bsfH264Mp4toannexb', e.target.checked))} />,
+ );
+ }
+ if (stream.codec_name === 'hevc') {
+ ui.push(
+ <Checkbox key="bsfHevcMp4toannexb" checked={!!streamParams.get('bsfHevcMp4toannexb')} label={t('Enable "{{filterName}}" bitstream filter.', { filterName: 'hevc_mp4toannexb' })} onChange={(e) => updateStreamParams((params) => params.set('bsfHevcMp4toannexb', e.target.checked))} />,
+ );
+ }
+
+ return (
+ <div style={{ marginBottom: '1em' }}>
+ {ui.length > 0
+ ? ui
+ : t('No editable parameters for this stream.')}
+ </div>
+ );
+};
+
+const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, path: editingFile }, setEditingStream, allFilesMeta, paramsByStreamId, updateStreamParams }) => {
+ const { t } = useTranslation();
+ const [editingTag, setEditingTag] = useState();
+
const { streams } = allFilesMeta[editingFile];
const editingStream = useMemo(() => streams.find((s) => s.index === editingStreamId), [streams, editingStreamId]);
const existingTags = useMemo(() => (editingStream && editingStream.tags) || {}, [editingStream]);
- const customTags = useMemo(() => (customTagsByStreamId[editingFile] || {})[editingStreamId] || {}, [customTagsByStreamId, editingFile, editingStreamId]);
+
+ const streamParams = useMemo(() => paramsByStreamId.get(editingFile)?.get(editingStreamId) ?? new Map(), [editingFile, editingStreamId, paramsByStreamId]);
+ const customTags = useMemo(() => streamParams.get('customTags') ?? {}, [streamParams]);
const onTagChange = useCallback((tag, value) => {
- setCustomTagsByStreamId((old) => ({
- ...old,
- [editingFile]: {
- ...old[editingFile],
- [editingStreamId]: {
- ...(old[editingFile] || {})[editingStreamId],
- [tag]: value,
- },
- },
- }));
- }, [editingFile, editingStreamId, setCustomTagsByStreamId]);
+ updateStreamParams(editingFile, editingStreamId, (params) => {
+ if (!params.has('customTags')) params.set('customTags', {});
+ const tags = params.get('customTags');
+ tags[tag] = value;
+ });
+ }, [editingFile, editingStreamId, updateStreamParams]);
const onTagReset = useCallback((tag) => {
- setCustomTagsByStreamId((old) => {
- const { [tag]: deleted, ...rest } = (old[editingFile] || {})[editingStreamId] || {};
-
- return {
- ...old,
- [editingFile]: {
- ...old[editingFile],
- [editingStreamId]: rest,
- },
- };
+ updateStreamParams(editingFile, editingStreamId, (params) => {
+ if (!params.has('customTags')) return;
+ // eslint-disable-next-line no-param-reassign
+ delete params.get('customTags')[tag];
});
- }, [editingFile, editingStreamId, setCustomTagsByStreamId]);
-
- if (!editingStream) return null;
+ }, [editingFile, editingStreamId, updateStreamParams]);
return (
- <>
- <Heading>Tags</Heading>
- <TagEditor existingTags={existingTags} customTags={customTags} onTagChange={onTagChange} onTagReset={onTagReset} />
- </>
+ <Dialog
+ title={t('Edit track {{trackNum}} metadata', { trackNum: editingStream && (editingStream.index + 1) })}
+ isShown={!!editingStream}
+ hasCancel={false}
+ isConfirmDisabled={editingTag != null}
+ confirmLabel={t('Done')}
+ onCloseComplete={() => setEditingStream()}
+ >
+ <div style={{ color: 'black' }}>
+ <Heading>Parameters</Heading>
+ <StreamParametersEditor stream={editingStream} streamParams={streamParams} updateStreamParams={(setter) => updateStreamParams(editingFile, editingStreamId, setter)} />
+ <Heading>Tags</Heading>
+ <TagEditor existingTags={existingTags} customTags={customTags} editingTag={editingTag} setEditingTag={setEditingTag} onTagChange={onTagChange} onTagReset={onTagReset} />
+ </div>
+ </Dialog>
);
});
@@ -183,10 +218,10 @@ function onInfoClick(json, title) {
showJson5Dialog({ title, json });
}
-const Stream = memo(({ dispositionByStreamId, setDispositionByStreamId, filePath, stream, onToggle, batchSetCopyStreamIds, copyStream, fileDuration, setEditingStream, onExtractStreamPress }) => {
+const Stream = memo(({ filePath, stream, onToggle, batchSetCopyStreamIds, copyStream, fileDuration, setEditingStream, onExtractStreamPress, paramsByStreamId, updateStreamParams }) => {
const { t } = useTranslation();
- const effectiveDisposition = useMemo(() => getStreamEffectiveDisposition(dispositionByStreamId, filePath, stream), [dispositionByStreamId, filePath, stream]);
+ const effectiveDisposition = useMemo(() => getStreamEffectiveDisposition(paramsByStreamId, filePath, stream), [filePath, paramsByStreamId, stream]);
const bitrate = parseInt(stream.bit_rate, 10);
const streamDuration = parseInt(stream.duration, 10);
@@ -230,14 +265,8 @@ const Stream = memo(({ dispositionByStreamId, setDispositionByStreamId, filePath
newDisposition = deleteDispositionValue; // needs a separate value (not a real disposition)
} // else unchanged (undefined)
- setDispositionByStreamId((old) => ({
- ...old,
- [filePath]: {
- ...old[filePath],
- [stream.index]: newDisposition,
- },
- }));
- }, [filePath, setDispositionByStreamId, stream.index]);
+ updateStreamParams(filePath, stream.index, (params) => params.set('disposition', newDisposition));
+ }, [filePath, updateStreamParams, stream.index]);
const codecTag = stream.codec_tag !== '0x0000' && stream.codec_tag_string;
@@ -353,8 +382,7 @@ const StreamsSelector = memo(({
mainFilePath, mainFileFormatData, mainFileStreams, mainFileChapters, isCopyingStreamId, toggleCopyStreamId,
setCopyStreamIdsForPath, onExtractStreamPress, onExtractAllStreamsPress, allFilesMeta, externalFilesMeta, setExternalFilesMeta,
showAddStreamSourceDialog, shortestFlag, setShortestFlag, nonCopiedExtraStreams,
- customTagsByFile, setCustomTagsByFile, customTagsByStreamId, setCustomTagsByStreamId,
- dispositionByStreamId, setDispositionByStreamId,
+ customTagsByFile, setCustomTagsByFile, paramsByStreamId, updateStreamParams,
}) => {
const [editingFile, setEditingFile] = useState();
const [editingStream, setEditingStream] = useState();
@@ -404,8 +432,6 @@ const StreamsSelector = memo(({
<tbody>
{mainFileStreams.map((stream) => (
<Stream
- dispositionByStreamId={dispositionByStreamId}
- setDispositionByStreamId={setDispositionByStreamId}
key={stream.index}
filePath={mainFilePath}
stream={stream}
@@ -415,6 +441,8 @@ const StreamsSelector = memo(({
setEditingStream={setEditingStream}
fileDuration={getFormatDuration(mainFileFormatData)}
onExtractStreamPress={() => onExtractStreamPress(stream.index)}
+ paramsByStreamId={paramsByStreamId}
+ updateStreamParams={updateStreamParams}
/>
))}
</tbody>
@@ -430,8 +458,6 @@ const StreamsSelector = memo(({
<tbody>
{streams.map((stream) => (
<Stream
- dispositionByStreamId={dispositionByStreamId}
- setDispositionByStreamId={setDispositionByStreamId}
key={stream.index}
filePath={path}
stream={stream}
@@ -440,6 +466,8 @@ const StreamsSelector = memo(({
batchSetCopyStreamIds={(filter, enabled) => batchSetCopyStreamIdsForPath(path, streams, filter, enabled)}
setEditingStream={setEditingStream}
fileDuration={getFormatDuration(formatData)}
+ paramsByStreamId={paramsByStreamId}
+ updateStreamParams={updateStreamParams}
/>
))}
</tbody>
@@ -483,15 +511,15 @@ const StreamsSelector = memo(({
<EditFileDialog editingFile={editingFile} allFilesMeta={allFilesMeta} customTagsByFile={customTagsByFile} setCustomTagsByFile={setCustomTagsByFile} />
</Dialog>
- <Dialog
- title={t('Edit track {{trackNum}} metadata', { trackNum: editingStream && (editingStream.streamId + 1) })}
- isShown={!!editingStream}
- hasCancel={false}
- confirmLabel={t('Done')}
- onCloseComplete={() => setEditingStream()}
- >
- <EditStreamDialog editingStream={editingStream} allFilesMeta={allFilesMeta} customTagsByStreamId={customTagsByStreamId} setCustomTagsByStreamId={setCustomTagsByStreamId} />
- </Dialog>
+ {editingStream != null && (
+ <EditStreamDialog
+ editingStream={editingStream}
+ setEditingStream={setEditingStream}
+ allFilesMeta={allFilesMeta}
+ paramsByStreamId={paramsByStreamId}
+ updateStreamParams={updateStreamParams}
+ />
+ )}
</>
);
});
diff --git a/src/hooks/useFfmpegOperations.js b/src/hooks/useFfmpegOperations.js
index fad1e374..66e07d6f 100644
--- a/src/hooks/useFfmpegOperations.js
+++ b/src/hooks/useFfmpegOperations.js
@@ -172,7 +172,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
const cutSingle = useCallback(async ({
keyframeCut: ssBeforeInput, avoidNegativeTs, copyFileStreams, cutFrom, cutTo, chaptersPath, onProgress, outPath,
- videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, customTagsByStreamId, dispositionByStreamId, videoTimebase,
+ videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, paramsByStreamId, videoTimebase,
}) => {
if (await shouldSkipExistingFile(outPath)) return;
@@ -231,48 +231,48 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
return streamCount + copiedStreamIndex;
}
- function lessDeepMap(root, fn) {
- let ret = [];
- Object.entries(root).forEach(([path, streamsMap]) => (
- Object.entries(streamsMap || {}).forEach(([streamId, value]) => {
- ret = [...ret, ...fn(path, streamId, value)];
- })));
-
- return ret;
- }
-
- // The structure is deep! file -> stream -> key -> value Example: { 'file.mp4': { 0: { key: 'value' } } }
- const deepMap = (root, fn) => lessDeepMap(root, (path, streamId, tagsMap) => {
- let ret = [];
- Object.entries(tagsMap || {}).forEach(([key, value]) => {
- ret = [...ret, ...fn(path, streamId, key, value)];
- });
- return ret;
- });
-
const customTagsArgs = [
// Main file metadata:
...flatMap(Object.entries(customTagsByFile[filePath] || []), ([key, value]) => ['-metadata', `${key}=${value}`]),
-
- // Example: { 'file.mp4': { 0: { tag_name: 'Tag Value' } } }
- ...deepMap(customTagsByStreamId, (path, streamId, tag, value) => {
- const outputIndex = mapInputStreamIndexToOutputIndex(path, parseInt(streamId, 10));
- if (outputIndex == null) return [];
- return [`-metadata:s:${outputIndex}`, `${tag}=${value}`];
- }),
];
const mapStreamsArgs = getMapStreamsArgs({ copyFileStreams: copyFileStreamsFiltered, allFilesMeta, outFormat });
- // Example: { 'file.mp4': { 0: { attached_pic: 1 } } }
- const customDispositionArgs = lessDeepMap(dispositionByStreamId, (path, streamId, disposition) => {
- if (disposition == null) return [];
- const outputIndex = mapInputStreamIndexToOutputIndex(path, parseInt(streamId, 10));
- if (outputIndex == null) return [];
- // 0 means delete the disposition for this stream
- const dispositionArg = disposition === deleteDispositionValue ? '0' : disposition;
- return [`-disposition:${outputIndex}`, String(dispositionArg)];
- });
+ const customParamsArgs = (() => {
+ const ret = [];
+ // eslint-disable-next-line no-restricted-syntax
+ for (const [fileId, fileParams] of paramsByStreamId.entries()) {
+ // eslint-disable-next-line no-restricted-syntax
+ for (const [streamId, streamParams] of fileParams.entries()) {
+ const outputIndex = mapInputStreamIndexToOutputIndex(fileId, parseInt(streamId, 10));
+ if (outputIndex != null) {
+ const disposition = streamParams.get('disposition');
+ if (disposition != null) {
+ // "0" means delete the disposition for this stream
+ const dispositionArg = disposition === deleteDispositionValue ? '0' : disposition;
+ ret.push(`-disposition:${outputIndex}`, String(dispositionArg));
+ }
+
+ if (streamParams.get('bsfH264Mp4toannexb')) {
+ ret.push(`-bsf:${outputIndex}`, String('h264_mp4toannexb'));
+ }
+ if (streamParams.get('bsfHevcMp4toannexb')) {
+ ret.push(`-bsf:${outputIndex}`, String('hevc_mp4toannexb'));
+ }
+
+ // custom stream metadata tags
+ const customTags = streamParams.get('customTags');
+ if (customTags != null) {
+ // eslint-disable-next-line no-restricted-syntax
+ for (const [tag, value] of Object.entries(customTags)) {
+ ret.push(`-metadata:s:${outputIndex}`, `${tag}=${value}`);
+ }
+ }
+ }
+ }
+ }
+ return ret;
+ })();
const ffmpegArgs = [
'-hide_banner',
@@ -294,7 +294,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
...customTagsArgs,
- ...customDispositionArgs,
+ ...customParamsArgs,
// See https://github.com/mifi/lossless-cut/issues/170
'-ignore_unknown',
@@ -323,10 +323,10 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
outputDir, customOutDir, segments, outSegFileNames, videoDuration, rotation, detectedFps,
onProgress: onTotalProgress, keyframeCut, copyFileStreams, allFilesMeta, outFormat,
appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, avoidNegativeTs,
- customTagsByFile, customTagsByStreamId, dispositionByStreamId, chapters, preserveMetadataOnMerge,
+ customTagsByFile, paramsByStreamId, chapters, preserveMetadataOnMerge,
}) => {
console.log('customTagsByFile', customTagsByFile);
- console.log('customTagsByStreamId', customTagsByStreamId);
+ console.log('paramsByStreamId', paramsByStreamId);
const singleProgresses = {};
function onSingleProgress(id, singleProgress) {
@@ -353,7 +353,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// old fashioned way
const outPath = await makeSegmentOutPath();
await cutSingle({
- cutFrom: desiredCutFrom, cutTo, chaptersPath, outPath, copyFileStreams, keyframeCut, avoidNegativeTs, videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, customTagsByStreamId, dispositionByStreamId, onProgress: (progress) => onSingleProgress(i, progress),
+ cutFrom: desiredCutFrom, cutTo, chaptersPath, outPath, copyFileStreams, keyframeCut, avoidNegativeTs, videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, paramsByStreamId, onProgress: (progress) => onSingleProgress(i, progress),
});
return outPath;
}
@@ -404,7 +404,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// for smart cut we need to use keyframe cut here, and no avoid_negative_ts
await cutSingle({
- cutFrom: encodeCutTo, cutTo, chaptersPath, outPath: smartCutMainPartOutPath, copyFileStreams: copyFileStreamsFiltered, keyframeCut: true, avoidNegativeTs: false, videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, customTagsByStreamId, dispositionByStreamId, videoTimebase, onProgress: onCutProgress,
+ cutFrom: encodeCutTo, cutTo, chaptersPath, outPath: smartCutMainPartOutPath, copyFileStreams: copyFileStreamsFiltered, keyframeCut: true, avoidNegativeTs: false, videoDuration, rotation, allFilesMeta, outFormat, appendFfmpegCommandLog, shortestFlag, ffmpegExperimental, preserveMovData, movFastStart, customTagsByFile, paramsByStreamId, videoTimebase, onProgress: onCutProgress,
});
// OK, just return the single cut file (we may need smart cut in other segments though)
diff --git a/src/index.jsx b/src/index.jsx
index b1aab474..d8e24cab 100644
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -1,6 +1,7 @@
import React, { Suspense } from 'react';
import { createRoot } from 'react-dom/client';
import { MotionConfig } from 'framer-motion';
+import { enableMapSet } from 'immer';
import 'sweetalert2/dist/sweetalert2.css';
@@ -24,6 +25,8 @@ import './i18n';
import './main.css';
+enableMapSet();
+
const { app } = window.require('@electron/remote');
console.log('Version', app.getVersion());
diff --git a/yarn.lock b/yarn.lock
index 3efa03b2..44e61bbe 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5454,6 +5454,13 @@ __metadata:
languageName: node
linkType: hard
+"immer@npm:^10.0.2":
+ version: 10.0.2
+ resolution: "immer@npm:10.0.2"
+ checksum: 525a3b14210d02ae420c3b9f6ca14f7e9bcf625611d1356e773e7739f14c7c8de50dac442e6c7de3a6e24a782f7b792b6b8666bc0b3f00269d21a95f8f68ca84
+ languageName: node
+ linkType: hard
+
"import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1":
version: 3.3.0
resolution: "import-fresh@npm:3.3.0"
@@ -6452,6 +6459,7 @@ __metadata:
i18next-fs-backend: ^2.1.1
i18next-parser: ^7.6.0
icon-gen: ^3.0.0
+ immer: ^10.0.2
json5: ^2.2.2
ky: ^0.33.1
lodash: ^4.17.19