Skip to content

The swiss army knife of lossless video/audio editing

Address review findings in metadata editor suggestions

Claude4abe77a2c4b2
diff --git a/locales/en/translation.json b/locales/en/translation.json
index e91a5ac7..d89f0dee 100644
--- a/locales/en/translation.json
+++ b/locales/en/translation.json
@@ -767,6 +767,7 @@
"Subtitle": "Subtitle",
"Subtitles (SRT)": "Subtitles (SRT)",
"Success!": "Success!",
+ "Suggestions": "Suggestions",
"System default": "System default",
"System language": "System language",
"Template error: {{error}}": "Template error: {{error}}",
diff --git a/src/renderer/src/StreamsSelector.tsx b/src/renderer/src/StreamsSelector.tsx
index 241ca93f..67fef389 100644
--- a/src/renderer/src/StreamsSelector.tsx
+++ b/src/renderer/src/StreamsSelector.tsx
@@ -294,10 +294,9 @@ const EditStreamDialog = memo(({ editingStream: { streamId: editingStreamId, pat
},
}), [i18n.language, t]);
- const codecTagSuggestions = useMemo(() => getCodecTagSuggestions(editingStream?.codec_name).map((value) => ({ value })), [editingStream?.codec_name]);
- const effectiveCodecTag = streamParams?.tag ?? editingStream?.codec_tag_string;
+ const codecTagSuggestions = useMemo(() => (isMov(outFormat) ? getCodecTagSuggestions(editingStream?.codec_name).map((value) => ({ value })) : []), [editingStream?.codec_name, outFormat]);
// https://developer.apple.com/documentation/http-live-streaming/hls-authoring-specification-for-apple-devices
- const suggestHvc1 = editingStream?.codec_name === 'hevc' && isMov(outFormat) && effectiveCodecTag !== 'hvc1';
+ const suggestHvc1 = editingStream?.codec_name === 'hevc' && isMov(outFormat) && streamParams?.tag == null && editingStream.codec_tag_string !== 'hvc1';
const updateCurrentStreamParams = (setter: (a: StreamParams) => void) => updateStreamParams(editingFile, editingStreamId, setter);
diff --git a/src/renderer/src/components/SuggestionTextField.tsx b/src/renderer/src/components/SuggestionTextField.tsx
index 0a65e172..6c0607ba 100644
--- a/src/renderer/src/components/SuggestionTextField.tsx
+++ b/src/renderer/src/components/SuggestionTextField.tsx
@@ -2,6 +2,7 @@ import type { ComponentProps } from 'react';
import { useImperativeHandle, useRef } from 'react';
import { DropdownMenu, IconButton, TextField } from '@radix-ui/themes';
import { FaChevronDown } from 'react-icons/fa';
+import { useTranslation } from 'react-i18next';
export interface Suggestion {
@@ -14,8 +15,9 @@ export default function SuggestionTextField({ ref, suggestions, onValueChange, d
suggestions: Suggestion[],
onValueChange: (value: string) => void,
}) {
+ const { t } = useTranslation();
const inputRef = useRef<HTMLInputElement>(null);
- useImperativeHandle(ref, () => inputRef.current!);
+ useImperativeHandle(ref, () => inputRef.current!, []);
return (
// eslint-disable-next-line react/jsx-props-no-spreading
@@ -24,7 +26,7 @@ export default function SuggestionTextField({ ref, suggestions, onValueChange, d
<TextField.Slot side="right">
<DropdownMenu.Root>
<DropdownMenu.Trigger disabled={disabled}>
- <IconButton type="button" size="1" variant="ghost" color="gray"><FaChevronDown /></IconButton>
+ <IconButton type="button" size="1" variant="ghost" color="gray" aria-label={t('Suggestions')} title={t('Suggestions')}><FaChevronDown /></IconButton>
</DropdownMenu.Trigger>
{/* Focus the input (not the trigger) after selecting, so that Enter submits */}
<DropdownMenu.Content size="1" style={{ maxHeight: '20em' }} onCloseAutoFocus={(e) => { e.preventDefault(); inputRef.current?.focus(); }}>
diff --git a/src/renderer/src/components/TagEditor.tsx b/src/renderer/src/components/TagEditor.tsx
index 45361d86..0b4ce7de 100644
--- a/src/renderer/src/components/TagEditor.tsx
+++ b/src/renderer/src/components/TagEditor.tsx
@@ -41,7 +41,8 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi
canDeleteExisting?: boolean,
}) {
const { t } = useTranslation();
- const ref = useRef<HTMLInputElement>(null);
+ const editRef = useRef<HTMLInputElement>(null);
+ const addRef = useRef<HTMLInputElement>(null);
const [editingTagVal, setEditingTagVal] = useState<string>();
const [newTagKey, setNewTagKey] = useState<string>();
@@ -126,7 +127,7 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi
}, [add]);
useEffect(() => {
- ref.current?.focus();
+ (editingTag != null ? editRef : addRef).current?.focus();
}, [editingTag]);
const editingTagError = editingTag != null && editingTagVal ? tagInfo?.[editingTag]?.validate?.(editingTagVal) : undefined;
@@ -176,7 +177,7 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi
<td style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: '.5em' }}>
{editingThis ? (
<form style={{ marginRight: '.5em', display: 'inline' }} onSubmit={onSubmit}>
- <SuggestionTextField ref={ref} placeholder={t('Enter value')} value={editingTagVal ?? ''} onValueChange={setEditingTagVal} suggestions={tagInfo?.[tag]?.suggestions ?? []} />
+ <SuggestionTextField ref={editRef} placeholder={t('Enter value')} value={editingTagVal ?? ''} onValueChange={setEditingTagVal} suggestions={tagInfo?.[tag]?.suggestions ?? []} />
</form>
) : (
renderValue({ isDeletedExisting, value, thisTagCustom })
@@ -211,7 +212,7 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi
{editingTagError && <Warning style={{ marginBottom: '1em' }}>{editingTagError}</Warning>}
<form onSubmit={onAddSubmit} style={{ opacity: canAdd ? undefined : 0.5, marginBottom: '1em', display: 'flex', alignItems: 'center' }}>
- <SuggestionTextField ref={ref} disabled={!canAdd} value={newTagKeyInput} onValueChange={setNewTagKeyInput} suggestions={availableKeySuggestions} placeholder={addTagTitle} style={{ marginRight: '1em' }} />
+ <SuggestionTextField ref={addRef} disabled={!canAdd} value={newTagKeyInput} onValueChange={setNewTagKeyInput} suggestions={availableKeySuggestions} placeholder={addTagTitle} style={{ marginRight: '1em' }} />
<IconButton size="2" type="submit" disabled={!canAdd} title={addTagTitle} onClick={add}><FaPlus /></IconButton>
</form>
diff --git a/src/renderer/src/util/streams.test.ts b/src/renderer/src/util/streams.test.ts
index 9d9c5bca..dd2c073b 100644
--- a/src/renderer/src/util/streams.test.ts
+++ b/src/renderer/src/util/streams.test.ts
@@ -1,6 +1,6 @@
import { test, expect } from 'vitest';
-import { getEffectiveAvoidNegativeTs, getKeyframeCutSeekCompensation, getMapStreamsArgs, getStreamIdsToCopy, isCopyingOnlyAudioStreams } from './streams';
+import { getEffectiveAvoidNegativeTs, getKeyframeCutSeekCompensation, getMapStreamsArgs, getStreamIdsToCopy, isCopyingOnlyAudioStreams, isValidCodecTag } from './streams';
import type { FFprobeStreamDisposition } from '../../../common/ffprobe';
import type { LiteFFprobeStream } from '../types';
@@ -232,3 +232,10 @@ test('getKeyframeCutSeekCompensation', () => {
// not cutting start
expect(getKeyframeCutSeekCompensation({ formatName: 'matroska,webm', streams: bFrames, cutFrom: 0 })).toBe(0);
});
+
+test('isValidCodecTag', () => {
+ expect(isValidCodecTag('hvc1')).toBe(true);
+ expect(isValidCodecTag('0x31637668')).toBe(true);
+ expect(isValidCodecTag('hvc1 ')).toBe(false);
+ expect(isValidCodecTag('hvc')).toBe(false);
+});
diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts
index ae9be678..b618ae86 100644
--- a/src/renderer/src/util/streams.ts
+++ b/src/renderer/src/util/streams.ts
@@ -105,13 +105,13 @@ export const isMov = (format: string | undefined) => format != null && ['ismv',
export const isMatroska = (format: string | undefined) => format != null && ['matroska', 'webm'].includes(format);
-// Common codec tags (FourCC) for use with `-tag`. Mostly relevant for MP4/MOV output
+// Common codec tags (FourCC) for use with `-tag` when outputting MP4/MOV
const codecTagsByCodec: Record<string, string[]> = {
- hevc: ['hvc1', 'hev1', 'dvh1', 'dvhe'],
+ hevc: ['hvc1', 'hev1'],
h264: ['avc1', 'avc3'],
av1: ['av01'],
vp9: ['vp09'],
- mpeg4: ['mp4v', 'XVID', 'DIVX'],
+ mpeg4: ['mp4v'],
aac: ['mp4a'],
ac3: ['ac-3'],
eac3: ['ec-3'],
@@ -121,7 +121,8 @@ const codecTagsByCodec: Record<string, string[]> = {
export const getCodecTagSuggestions = (codecName: string | undefined) => (codecName != null && codecTagsByCodec[codecName]) || [];
-export const isValidCodecTag = (tag: string) => tag.length === 4;
+// ffmpeg accepts a FourCC or a numeric tag like 0x31637668
+export const isValidCodecTag = (tag: string) => tag.length === 4 || /^0x[\da-f]+$/i.test(tag);
type GetVideoArgsFn = (a: { streamIndex: number, outputIndex: number }) => string[] | undefined;