Skip to content

The swiss army knife of lossless video/audio editing

fix cover art regression

Mikael Finstad26052961e03b
diff --git a/src/renderer/src/StreamsSelector.tsx b/src/renderer/src/StreamsSelector.tsx
index 8e20446f..fcd7c242 100644
--- a/src/renderer/src/StreamsSelector.tsx
+++ b/src/renderer/src/StreamsSelector.tsx
@@ -13,11 +13,10 @@ import AutoExportToggler from './components/AutoExportToggler';
import Select from './components/Select';
import type { FileStream } from './ffmpeg';
import { getStreamFps } from './ffmpeg';
-import { deleteDispositionValue } from './util';
import { getActiveDisposition, attachedPicDisposition, isGpsStream } from './util/streams';
import TagEditor from './components/TagEditor';
import type { FFprobeChapter, FFprobeFormat, FFprobeStream } from '../../common/ffprobe';
-import type { CustomTagsByFile, FilesMeta, FormatTimecode, ParamsByStreamId, StreamParams } from './types';
+import { contentDispositionOptionsSchema, deleteDispositionValue, dispositionOptions, type ContentDispositionOptions, type CustomTagsByFile, type FilesMeta, type FormatTimecode, type ParamsByStreamId, type StreamParams } from './types';
import Button, { DialogButton } from './components/Button';
import styles from './StreamsSelector.module.css';
import Json5Dialog from './components/Json5Dialog';
@@ -26,9 +25,6 @@ import TextInput from './components/TextInput';
import Switch from './components/Switch';
-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';
-
type UpdateStreamParams = (fileId: string, streamId: number, setter: (a: StreamParams) => void) => void;
interface EditingStream {
@@ -223,6 +219,8 @@ const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, pat
);
});
+const unchangedDispositionValue = 'llc_disposition_unchanged';
+
// eslint-disable-next-line react/display-name
const Stream = memo(({ filePath, stream, onToggle, toggleCopyStreamIds, copyStream, fileDuration, setEditingStream, onExtractStreamPress, paramsByStreamId, updateStreamParams, formatTimecode, loadSubtitleTrackToSegments }: {
filePath: string,
@@ -277,9 +275,10 @@ const Stream = memo(({ filePath, stream, onToggle, toggleCopyStreamIds, copyStre
const onClick = () => onToggle && onToggle(stream.index);
const onDispositionChange = useCallback<ChangeEventHandler<HTMLSelectElement>>((e) => {
- let newDisposition: string;
- if (dispositionOptions.includes(e.target.value)) {
- newDisposition = e.target.value;
+ let newDisposition: ContentDispositionOptions | 'llc_disposition_remove' | undefined;
+ const dispositionParsed = contentDispositionOptionsSchema.safeParse(e.target.value);
+ if (dispositionParsed.success) {
+ newDisposition = dispositionParsed.data;
} else if (e.target.value === deleteDispositionValue) {
newDisposition = deleteDispositionValue; // needs a separate value (not a real disposition)
} // else unchanged (undefined)
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.ts
index fa1b1fa9..8a054a7e 100644
--- a/src/renderer/src/hooks/useFfmpegOperations.ts
+++ b/src/renderer/src/hooks/useFfmpegOperations.ts
@@ -5,14 +5,14 @@ import pMap from 'p-map';
import invariant from 'tiny-invariant';
import i18n from 'i18next';
-import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, deleteDispositionValue, getHtml5ifiedPath, unlinkWithRetry, getFrameDuration, isMac, html5ifiedPrefix, html5dummySuffix, assertFileExists } from '../util';
+import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, getHtml5ifiedPath, unlinkWithRetry, getFrameDuration, isMac, html5ifiedPrefix, html5dummySuffix, assertFileExists } from '../util';
import { isCuttingStart, isCuttingEnd, runFfmpegWithProgress, getFfCommandLine, getDuration, createChaptersFromSegments, readFileFfprobeMeta, getExperimentalArgs, getVideoTimescaleArgs, logStdoutStderr, runFfmpegConcat, RefuseOverwriteError, runFfmpeg } from '../ffmpeg';
import { getMapStreamsArgs, getStreamIdsToCopy } from '../util/streams';
import { needsSmartCut, getCodecParams } from '../smartcut';
import { getGuaranteedSegments, isDurationValid } from '../segments';
import type { FFprobeStream } from '../../../common/ffprobe';
import type { AvoidNegativeTs, FfmpegHwAccel, Html5ifyMode, PreserveMetadata } from '../../../common/types';
-import type { AllFilesMeta, Chapter, CopyfileStreams, CustomTagsByFile, LiteFFprobeStream, ParamsByStreamId, SegmentToExport } from '../types';
+import { deleteDispositionValue, type AllFilesMeta, type Chapter, type CopyfileStreams, type CustomTagsByFile, type LiteFFprobeStream, type ParamsByStreamId, type SegmentToExport } from '../types';
import type { LossyMode } from '../../../main';
import { UserFacingError } from '../../errors';
import mainApi from '../mainApi';
@@ -289,7 +289,15 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// If cutting multiple files, `-ss` must be before `-i`, regardless of `ssBeforeInput` choice
// and it seems that `-t` must be after `-i` #896
const inputFilesArgs = copyFileStreamsFiltered.length > 1
- ? flatMap(copyFileStreamsFiltered, ({ path }) => [...cutFromArgs, '-i', path, ...cutToArgs])
+ ? flatMap(copyFileStreamsFiltered, ({ streamIds, path }) => {
+ // don't "cut"/seek cover art or images attached by users, see https://github.com/mifi/lossless-cut/issues/2884
+ const streamParams = streamIds.map((streamId) => paramsByStreamId.get(path)?.get(streamId));
+ if (streamIds.length === 1 && streamParams[0]?.disposition === 'attached_pic') {
+ return ['-i', path];
+ }
+
+ return [...cutFromArgs, '-i', path, ...cutToArgs];
+ })
: [
...(ssBeforeInput ? cutFromArgs : []),
'-i', copyFileStreamsFiltered[0]!.path,
diff --git a/src/renderer/src/types.ts b/src/renderer/src/types.ts
index c0199e9e..0787dce4 100644
--- a/src/renderer/src/types.ts
+++ b/src/renderer/src/types.ts
@@ -163,9 +163,14 @@ export type AllFilesMeta = Record<string, {
export type CustomTagsByFile = Record<string, Record<string, string>>;
+export const dispositionOptions = ['default', 'dub', 'original', 'comment', 'lyrics', 'karaoke', 'forced', 'hearing_impaired', 'visual_impaired', 'clean_effects', 'attached_pic', 'captions', 'descriptions', 'dependent', 'metadata'] as const;
+export const contentDispositionOptionsSchema = z.enum(dispositionOptions);
+export type ContentDispositionOptions = z.infer<typeof contentDispositionOptionsSchema>;
+export const deleteDispositionValue = 'llc_disposition_remove' as const;
+
export interface StreamParams {
customTags?: Record<string, string>,
- disposition?: string,
+ disposition?: ContentDispositionOptions | 'llc_disposition_remove' | undefined,
bsfH264Mp4toannexb?: boolean,
bsfHevcMp4toannexb?: boolean,
bsfHevcAudInsert?: boolean,
diff --git a/src/renderer/src/util.ts b/src/renderer/src/util.ts
index 017896bf..6799528d 100644
--- a/src/renderer/src/util.ts
+++ b/src/renderer/src/util.ts
@@ -273,9 +273,6 @@ export function getHtml5ifiedPath(cod: string | undefined, fp: string, type: Exc
return getSuffixedOutPath({ customOutDir: cod, filePath: fp, nameSuffix: `${html5ifiedPrefix}${type}.${ext}` });
}
-
-export const deleteDispositionValue = 'llc_disposition_remove';
-
export const mirrorTransform = 'matrix(-1, 0, 0, 1, 0, 0)';
// todo this is not a correct assumption
diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts
index 6ed4d19c..8bdfae30 100644
--- a/src/renderer/src/util/streams.ts
+++ b/src/renderer/src/util/streams.ts
@@ -197,10 +197,18 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi
return args;
}
+export type AllFilesStreamMeta = Record<string, Pick<AllFilesMeta[string], 'streams'>>;
+
+export const getStreamById = ({ allFilesMeta, streamId, path }: {
+ allFilesMeta: AllFilesStreamMeta,
+ streamId: number,
+ path: string,
+}) => allFilesMeta?.[path]?.streams.find((s) => s.index === streamId);
+
export function getMapStreamsArgs({ startIndex = 0, outFormat, allFilesMeta, copyFileStreams, manuallyCopyDisposition, getVideoArgs, needFlac }: {
startIndex?: number,
outFormat: string | undefined,
- allFilesMeta: Record<string, Pick<AllFilesMeta[string], 'streams'>>,
+ allFilesMeta: AllFilesStreamMeta,
copyFileStreams: CopyfileStreams,
manuallyCopyDisposition?: boolean,
getVideoArgs?: GetVideoArgsFn,
@@ -211,9 +219,9 @@ export function getMapStreamsArgs({ startIndex = 0, outFormat, allFilesMeta, cop
copyFileStreams.forEach(({ streamIds, path }, fileIndex) => {
streamIds.forEach((streamId) => {
- const { streams } = allFilesMeta[path]!;
- const stream = streams.find((s) => s.index === streamId);
+ const stream = getStreamById({ allFilesMeta, streamId, path });
invariant(stream != null);
+
args = [
...args,
'-map', `${fileIndex}:${streamId}`,