Skip to content

The swiss army knife of lossless video/audio editing

Keep dispositions when resetting track changes

Claudeed88d7ddf0fc
diff --git a/src/renderer/src/StreamsSelector.tsx b/src/renderer/src/StreamsSelector.tsx
index 0c09c8b7..39f65be1 100644
--- a/src/renderer/src/StreamsSelector.tsx
+++ b/src/renderer/src/StreamsSelector.tsx
@@ -38,6 +38,20 @@ function EditButton({ title, onClick, highlighted }: { title: string, onClick: (
return <Button title={title} onClick={onClick}><FaEdit style={{ verticalAlign: 'middle', color: highlighted ? 'var(--accent-11)' : undefined }} /></Button>;
}
+// Without streamId: resets the file's own params (not its tracks). Keeps disposition (see hasStreamEdits)
+function resetParamsDraft(fileParams: FileParams, streamId?: number) {
+ if (streamId == null) {
+ // eslint-disable-next-line no-param-reassign
+ fileParams.metadata = {};
+ // eslint-disable-next-line no-param-reassign
+ delete fileParams.offset;
+ return;
+ }
+ const disposition = fileParams.paramsByStream.get(streamId)?.disposition;
+ if (disposition != null) fileParams.paramsByStream.set(streamId, { metadata: {}, disposition });
+ else fileParams.paramsByStream.delete(streamId);
+}
+
type UpdateStreamParams = (fileId: string, streamId: number, setter: (a: StreamParams) => void) => void;
interface EditingStream {
@@ -461,7 +475,7 @@ const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, pat
</Tabs.Root>
<Dialog.ButtonRow>
- <ResetButton disabled={!hasStreamEdits(streamParams)} onClick={() => resetParams(editingFile, editingStreamId)} />
+ <ResetButton disabled={editingKey != null || !hasStreamEdits(streamParams)} onClick={() => resetParams(editingFile, editingStreamId)} />
<Dialog.Close asChild>
<DialogButton disabled={editingKey != null} primary>{t('Done')}</DialogButton>
</Dialog.Close>
@@ -773,22 +787,21 @@ function StreamsSelector({
const externalFilesEntries = Object.entries(externalFilesMeta);
- // without streamId: resets the file's own params (not its tracks)
const resetParams = useCallback<ResetParams>((path, streamId) => setParamsByFile(produce((draft) => {
const fileParams = draft.get(path);
- if (fileParams == null) return;
- if (streamId != null) {
- fileParams.paramsByStream.delete(streamId);
- } else {
- fileParams.metadata = {};
- delete fileParams.offset;
- }
+ if (fileParams != null) resetParamsDraft(fileParams, streamId);
})), [setParamsByFile]);
- const haveEdits = [...paramsByFile.values()].some((fileParams) => hasFileEdits(fileParams) || [...fileParams.paramsByStream.values()].some((streamParams) => hasStreamEdits(streamParams)));
+ const haveEdits = useMemo(() => [...paramsByFile.values()].some((fileParams) => hasFileEdits(fileParams) || [...fileParams.paramsByStream.values()].some((streamParams) => hasStreamEdits(streamParams))), [paramsByFile]);
const onResetAllClick = useCallback(async () => {
- if (await confirmDialog({ description: t('Reset all changes to files and tracks?') })) setParamsByFile(new Map());
+ if (!(await confirmDialog({ description: t('Reset all changes to files and tracks?') }))) return;
+ setParamsByFile(produce((draft) => {
+ for (const fileParams of draft.values()) {
+ resetParamsDraft(fileParams);
+ for (const streamId of fileParams.paramsByStream.keys()) resetParamsDraft(fileParams, streamId);
+ }
+ }));
}, [confirmDialog, setParamsByFile, t]);
return (
@@ -886,7 +899,7 @@ function StreamsSelector({
<EditFileDialog editingFile={editingFile} editingKey={editingKey} setEditingKey={setEditingKey} allFilesMeta={allFilesMeta} paramsByFile={paramsByFile} setParamsByFile={setParamsByFile} enableMetadata={editingFile === mainFilePath} outFormat={outFormat} />
<Dialog.ButtonRow>
- <ResetButton disabled={!hasFileEdits(paramsByFile.get(editingFile))} onClick={() => resetParams(editingFile)} />
+ <ResetButton disabled={editingKey != null || !hasFileEdits(paramsByFile.get(editingFile))} onClick={() => resetParams(editingFile)} />
<Dialog.Close asChild>
<DialogButton primary disabled={editingKey != null}>{t('Done')}</DialogButton>
</Dialog.Close>
diff --git a/src/renderer/src/util/streams.test.ts b/src/renderer/src/util/streams.test.ts
index 19fc1603..24151eb3 100644
--- a/src/renderer/src/util/streams.test.ts
+++ b/src/renderer/src/util/streams.test.ts
@@ -240,6 +240,7 @@ test('hasStreamEdits', () => {
expect(hasStreamEdits({ metadata: { language: 'eng' } })).toBe(true);
expect(hasStreamEdits({ metadata: { title: '' } })).toBe(true); // empty means delete
expect(hasStreamEdits({ metadata: {}, tag: 'hvc1' })).toBe(true);
+ expect(hasStreamEdits({ metadata: {}, disposition: 'attached_pic' })).toBe(false);
expect(hasStreamEdits({ metadata: {}, crop: { left: 2, right: 0, top: 0, bottom: 0 } })).toBe(true);
});
diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts
index 4a59f6f6..825e4eeb 100644
--- a/src/renderer/src/util/streams.ts
+++ b/src/renderer/src/util/streams.ts
@@ -110,9 +110,9 @@ export const isCropActive = (crop: BsfCropParams | undefined): crop is BsfCropPa
export const isAspectRatioActive = (aspectRatio: BsfAspectRatioParams | undefined): aspectRatio is BsfAspectRatioParams => aspectRatio != null && aspectRatio.num > 0 && aspectRatio.den > 0;
// whether the user has made any changes that affect the export (params can linger after being undone, e.g. a switch turned off)
+// Disposition doesn't count: it's shown and changed in the track row, and is also set automatically (e.g. for captured cover art)
export const hasStreamEdits = (params: StreamParams | undefined) => params != null && (
Object.keys(params.metadata).length > 0
- || params.disposition != null
|| !!params.bsfH264Mp4toannexb || !!params.bsfHevcMp4toannexb || !!params.bsfHevcAudInsert
|| params.tag != null
|| isCropActive(params.crop)