Skip to content

The swiss army knife of lossless video/audio editing

Fix review findings on the lint TODO fixes

Claudea9b265ee0d15
diff --git a/docs/generated/types.md b/docs/generated/types.md
index 8c625cf4..d1e5f691 100644
--- a/docs/generated/types.md
+++ b/docs/generated/types.md
@@ -8,33 +8,19 @@
* All times are expressed in milliseconds since the POSIX Epoch.
*/
interface SourceFile {
- /**
- * The file's name without the file system path.
- */
+ /** The file's name without the file system path. */
name: string;
- /**
- * The full filesystem path of the file.
- */
+ /** The full filesystem path of the file. */
path: string;
- /**
- * File size in bytes.
- */
+ /** File size in bytes. */
size?: number | bigint | undefined;
- /**
- * The last time this file was accessed.
- */
+ /** The last time this file was accessed. */
atime?: number | undefined;
- /**
- * The last time this file was modified.
- */
+ /** The last time this file was modified. */
mtime?: number | undefined;
- /**
- * The last time the file status was changed.
- */
+ /** The last time the file status was changed. */
ctime?: number | undefined;
- /**
- * The creation time of this file.
- */
+ /** The creation time of this file. */
birthtime?: number | undefined;
}
```
@@ -75,29 +61,17 @@ interface FileNameTemplateContext {
* See https://losslesscut.app/docs/expressions
*/
interface Segment {
- /**
- * Index of the segment in the segment list, starting with 0
- */
+ /** Index of the segment in the segment list, starting with 0 */
index: number;
- /**
- * Name of the segment
- */
+ /** Name of the segment */
label: string;
- /**
- * Segment start time in seconds
- */
+ /** Segment start time in seconds */
start: number;
- /**
- * Segment end time in seconds, or undefined for markers
- */
+ /** Segment end time in seconds, or undefined for markers */
end?: number | undefined;
- /**
- * Duration in seconds (effectively `end` minus `start` or 0 for markers)
- */
+ /** Duration in seconds (effectively `end` minus `start` or 0 for markers) */
duration: number;
- /**
- * Tags associated with this segment
- */
+ /** Tags associated with this segment */
tags: Record<string, string>;
}
```
diff --git a/src/common/userTypes.ts b/src/common/userTypes.ts
index 55211356..39d937c2 100644
--- a/src/common/userTypes.ts
+++ b/src/common/userTypes.ts
@@ -1,3 +1,4 @@
+/* eslint-disable unicorn-js/single-line-block-comment-style, unicorn-js/no-asterisk-prefix-in-documentation-comments -- these doc comments are published as is in docs/generated/types.md */
// ⚠️ These types are a the contract with the user, through the documentation.
// ⚠️ JSDoc comments get converted to user documentation.
// ‼️ DO NOT change these types without considering the user impact!
@@ -5,44 +6,30 @@
// https://losslesscut.app/docs/file-name-template
/**
-Properties of a source file made available to the user in the export file name template.
-All times are expressed in milliseconds since the POSIX Epoch.
-*/
+ * Properties of a source file made available to the user in the export file name template.
+ * All times are expressed in milliseconds since the POSIX Epoch.
+ */
export interface SourceFile {
- /**
- The file's name without the file system path.
- */
+ /** The file's name without the file system path. */
name: string,
- /**
- The full filesystem path of the file.
- */
+ /** The full filesystem path of the file. */
path: string,
- /**
- File size in bytes.
- */
+ /** File size in bytes. */
size?: number | bigint | undefined, // File size in bytes
- /**
- The last time this file was accessed.
- */
+ /** The last time this file was accessed. */
atime?: number | undefined,
- /**
- The last time this file was modified.
- */
+ /** The last time this file was modified. */
mtime?: number | undefined,
- /**
- The last time the file status was changed.
- */
+ /** The last time the file status was changed. */
ctime?: number | undefined,
- /**
- The creation time of this file.
- */
+ /** The creation time of this file. */
birthtime?: number | undefined,
}
/**
-The global context made available to the user in the export file name template.
-See docs/file-name-template.md documentation for details.
-*/
+ * The global context made available to the user in the export file name template.
+ * See docs/file-name-template.md documentation for details.
+ */
export interface FileNameTemplateContext {
FILENAME: string;
FILES: SourceFile[];
@@ -65,31 +52,19 @@ export interface FileNameTemplateContext {
}
/**
-See https://losslesscut.app/docs/expressions
-*/
+ * See https://losslesscut.app/docs/expressions
+ */
export interface Segment {
- /**
- Index of the segment in the segment list, starting with 0
- */
+ /** Index of the segment in the segment list, starting with 0 */
index: number,
- /**
- Name of the segment
- */
+ /** Name of the segment */
label: string,
- /**
- Segment start time in seconds
- */
+ /** Segment start time in seconds */
start: number,
- /**
- Segment end time in seconds, or undefined for markers
- */
+ /** Segment end time in seconds, or undefined for markers */
end?: number | undefined,
- /**
- Duration in seconds (effectively `end` minus `start` or 0 for markers)
- */
+ /** Duration in seconds (effectively `end` minus `start` or 0 for markers) */
duration: number,
- /**
- Tags associated with this segment
- */
+ /** Tags associated with this segment */
tags: Record<string, string>,
}
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 5baf24ab..bc0fb410 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -1688,7 +1688,11 @@ function App() {
}, []);
const extractAllStreams = useCallback(async () => {
- if (!filePath || !(await confirmDialog({ focusConfirm: true, description: t('Please confirm that you want to extract all tracks as separate files'), confirmButtonText: t('Extract all tracks') })) || workingRef.current) return;
+ if (
+ !filePath
+ || !(await confirmDialog({ focusConfirm: true, description: t('Please confirm that you want to extract all tracks as separate files'), confirmButtonText: t('Extract all tracks') }))
+ || workingRef.current
+ ) return;
try {
setWorking({ text: i18n.t('Extracting all streams') });
setStreamsSelectorShown(false);
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.ts
index 337c40eb..bdab7321 100644
--- a/src/renderer/src/hooks/useFfmpegOperations.ts
+++ b/src/renderer/src/hooks/useFfmpegOperations.ts
@@ -378,67 +378,66 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
for (const [fileId, { paramsByStream }] of paramsByFile.entries()) {
for (const [streamId, streamParams] of paramsByStream.entries()) {
const outputIndex = mapInputStreamIndexToOutputIndex(fileId, streamId);
- // eslint-disable-next-line unicorn-js/prefer-continue -- dedenting this long block would make a large diff
- if (outputIndex != null) {
- const { disposition } = streamParams;
- if (disposition != null) {
- // "0" means delete the disposition for this stream
- const dispositionArg = disposition === deleteDispositionValue ? '0' : disposition;
- ret.push(`-disposition:${outputIndex}`, String(dispositionArg));
- }
+ if (outputIndex == null) continue;
- const bitstreamFilters: string[] = [];
- if (streamParams.bsfH264Mp4toannexb) bitstreamFilters.push('h264_mp4toannexb');
- if (streamParams.bsfHevcMp4toannexb) bitstreamFilters.push('hevc_mp4toannexb');
- if (streamParams.bsfHevcAudInsert) bitstreamFilters.push('hevc_metadata=aud=insert');
-
- const getFileStreams = () => allFilesMeta[fileId]?.streams;
- const getStream = () => getFileStreams()?.find((s) => s.index === streamId);
-
- // Lossless crop via codec bitstream metadata (#643)
- if (isCropActive(streamParams.crop)) {
- const { left, right, top, bottom } = streamParams.crop;
- // Look up codec_name from allFilesMeta to determine the correct bitstream filter
- const streamInfo = getStream();
- const codecName = streamInfo?.codec_name;
-
- const cropParams = `crop_left=${left}:crop_right=${right}:crop_top=${top}:crop_bottom=${bottom}`;
- if (codecName === 'h264') {
- bitstreamFilters.push(`h264_metadata=${cropParams}`);
- } else if (codecName === 'hevc') {
- bitstreamFilters.push(`hevc_metadata=${cropParams}`);
- }
- }
+ const { disposition } = streamParams;
+ if (disposition != null) {
+ // "0" means delete the disposition for this stream
+ const dispositionArg = disposition === deleteDispositionValue ? '0' : disposition;
+ ret.push(`-disposition:${outputIndex}`, String(dispositionArg));
+ }
- // Lossless aspect ratio (SAR) via codec bitstream metadata (#643)
- if (isAspectRatioActive(streamParams.aspectRatio)) {
- const { num, den } = streamParams.aspectRatio;
- const streamInfo = getStream();
- const codecName = streamInfo?.codec_name;
-
- if (codecName === 'h264') {
- bitstreamFilters.push(`h264_metadata=sample_aspect_ratio=${num}/${den}`);
- } else if (codecName === 'hevc') {
- bitstreamFilters.push(`hevc_metadata=sample_aspect_ratio=${num}/${den}`);
- } else {
- // For non-H264/HEVC codecs, use container-level -aspect flag
- ret.push('-aspect', `${num}:${den}`);
- }
+ const bitstreamFilters: string[] = [];
+ if (streamParams.bsfH264Mp4toannexb) bitstreamFilters.push('h264_mp4toannexb');
+ if (streamParams.bsfHevcMp4toannexb) bitstreamFilters.push('hevc_mp4toannexb');
+ if (streamParams.bsfHevcAudInsert) bitstreamFilters.push('hevc_metadata=aud=insert');
+
+ const getFileStreams = () => allFilesMeta[fileId]?.streams;
+ const getStream = () => getFileStreams()?.find((s) => s.index === streamId);
+
+ // Lossless crop via codec bitstream metadata (#643)
+ if (isCropActive(streamParams.crop)) {
+ const { left, right, top, bottom } = streamParams.crop;
+ // Look up codec_name from allFilesMeta to determine the correct bitstream filter
+ const streamInfo = getStream();
+ const codecName = streamInfo?.codec_name;
+
+ const cropParams = `crop_left=${left}:crop_right=${right}:crop_top=${top}:crop_bottom=${bottom}`;
+ if (codecName === 'h264') {
+ bitstreamFilters.push(`h264_metadata=${cropParams}`);
+ } else if (codecName === 'hevc') {
+ bitstreamFilters.push(`hevc_metadata=${cropParams}`);
}
+ }
- if (bitstreamFilters.length > 0) {
- ret.push(`-bsf:${outputIndex}`, bitstreamFilters.join(','));
+ // Lossless aspect ratio (SAR) via codec bitstream metadata (#643)
+ if (isAspectRatioActive(streamParams.aspectRatio)) {
+ const { num, den } = streamParams.aspectRatio;
+ const streamInfo = getStream();
+ const codecName = streamInfo?.codec_name;
+
+ if (codecName === 'h264') {
+ bitstreamFilters.push(`h264_metadata=sample_aspect_ratio=${num}/${den}`);
+ } else if (codecName === 'hevc') {
+ bitstreamFilters.push(`hevc_metadata=sample_aspect_ratio=${num}/${den}`);
+ } else {
+ // For non-H264/HEVC codecs, use container-level -aspect flag
+ ret.push('-aspect', `${num}:${den}`);
}
+ }
- if (streamParams.tag != null) {
- ret.push(`-tag:${outputIndex}`, streamParams.tag);
- }
+ if (bitstreamFilters.length > 0) {
+ ret.push(`-bsf:${outputIndex}`, bitstreamFilters.join(','));
+ }
+
+ if (streamParams.tag != null) {
+ ret.push(`-tag:${outputIndex}`, streamParams.tag);
+ }
- // custom stream metadata
- if (streamParams.metadata != null) {
- for (const [tag, value] of Object.entries(streamParams.metadata)) {
- ret.push(`-metadata:s:${outputIndex}`, `${tag}=${value}`);
- }
+ // custom stream metadata
+ if (streamParams.metadata != null) {
+ for (const [tag, value] of Object.entries(streamParams.metadata)) {
+ ret.push(`-metadata:s:${outputIndex}`, `${tag}=${value}`);
}
}
}
diff --git a/src/renderer/src/hooks/useKeyboard.ts b/src/renderer/src/hooks/useKeyboard.ts
index 1cfbc65b..b54b6627 100644
--- a/src/renderer/src/hooks/useKeyboard.ts
+++ b/src/renderer/src/hooks/useKeyboard.ts
@@ -22,6 +22,9 @@ See also https://github.com/mifi/lossless-cut/issues/2515
interface KeyEventParams { e: KeyboardEvent, action: KeyboardAction | undefined }
+// whether a key binding's modifiers (e.g. both ControlLeft and ControlRight) match whether that modifier is pressed
+const modifierMatches = (modifiers: Set<string>, bindingKeys: Set<string>, pressed: boolean) => modifiers.isDisjointFrom(bindingKeys) !== pressed;
+
export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfirm, exportConfirmOpen }: {
keyBindings: KeyBinding[],
keyUpActions: Record<string, () => void>,
@@ -148,11 +151,7 @@ export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfi
// only use first one, if multiple matches (shouldn't happen anyway)
const matchingKeyBinding = (keyBindingsByKeyCode[e.code] ?? []).find((kb) => {
const kbKeys = new Set(kb.keys.split('+'));
- const modifierMatches = (modifiers: Set<string>, pressed: boolean) => {
- const inBinding = !modifiers.isDisjointFrom(kbKeys);
- return inBinding === pressed;
- };
- return modifierMatches(controlModifiers, ctrl) && modifierMatches(shiftModifiers, shift) && modifierMatches(altModifiers, alt) && modifierMatches(metaModifiers, meta);
+ return modifierMatches(controlModifiers, kbKeys, ctrl) && modifierMatches(shiftModifiers, kbKeys, shift) && modifierMatches(altModifiers, kbKeys, alt) && modifierMatches(metaModifiers, kbKeys, meta);
});
if (ev === 'keyup') onKeyUp({ e, action: matchingKeyBinding?.action });
diff --git a/src/renderer/src/util/rate-calculator.test.ts b/src/renderer/src/util/rate-calculator.test.ts
index 90d3da15..005eec32 100644
--- a/src/renderer/src/util/rate-calculator.test.ts
+++ b/src/renderer/src/util/rate-calculator.test.ts
@@ -9,7 +9,7 @@ it('inverts for reverse direction', () => {
it('uses default rate', () => {
const r = adjustRate(1, 1);
- expect(r).toBe(Number(DEFAULT_PLAYBACK_RATE));
+ expect(r).toBe(DEFAULT_PLAYBACK_RATE);
});
it('allows multiplier override', () => {
diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts
index a466b25c..8ad16c3e 100644
--- a/src/renderer/src/util/streams.ts
+++ b/src/renderer/src/util/streams.ts
@@ -350,7 +350,9 @@ export function getKeyframeCutSeekCompensation({ formatName, streams, cutFrom }:
streams: Pick<FFprobeStream, 'has_b_frames'>[],
cutFrom: number,
}) {
- if (cutFrom <= 0 || (formatName ?? '').split(',').every((f) => !isMatroska(f)) || streams.every((stream) => !((stream.has_b_frames ?? 0) > 0))) return 0;
+ const isMatroskaFormat = (formatName ?? '').split(',').some((f) => isMatroska(f));
+ const hasBFrames = streams.some((stream) => (stream.has_b_frames ?? 0) > 0);
+ if (cutFrom <= 0 || !isMatroskaFormat || !hasBFrames) return 0;
return 3 / 23 + 0.001;
}