The swiss army knife of lossless video/audio editing
move timecode out of timeline #2592 #2691 #2800 #483
Mikael Finstad2605292763ee
diff --git a/src/main/configStore.ts b/src/main/configStore.tsindex c9f7e6a2..58a495de 100644--- a/src/main/configStore.ts+++ b/src/main/configStore.ts@@ -26,8 +26,8 @@ const defaultKeyBindings: KeyBinding[] = [{ keys: 'Comma', action: 'seekPreviousFrame' },{ keys: 'Period', action: 'seekNextFrame' },{ keys: 'KeyC', action: 'captureSnapshot' },- { keys: 'ControlLeft+KeyC', action: 'copySegmentsToClipboard' },- { keys: 'MetaLeft+KeyC', action: 'copySegmentsToClipboard' },+ { keys: 'ControlLeft+AltLeft+KeyC', action: 'copySegmentsToClipboard' },+ { keys: 'MetaLeft+AltLeft+KeyC', action: 'copySegmentsToClipboard' },{ keys: 'ShiftLeft+KeyC', action: 'captureSnapshotToClipboard' },{ keys: 'KeyI', action: 'setCutStart' },diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsxindex cf738ea5..240b680c 100644--- a/src/renderer/src/App.tsx+++ b/src/renderer/src/App.tsx@@ -202,7 +202,7 @@ function App() {const { working, setWorking, workingRef, abortWorking } = useLoading();const { videoRef, videoContainerRef, playbackRate, setPlaybackRate, outputPlaybackRate, setOutputPlaybackRate, commandedTime, seekAbs, playingRef, getRelevantTime, setPlaying, onSeeked, relevantTime, onStartPlaying, setCommandedTime, setOutputPlaybackRateState, commandedTimeRef, onStopPlaying, onVideoAbort, playerTime, setPlayerTime, playbackMode, setPlaybackMode, playbackModeRef, playing, play, pause, seekRel } = useVideo({ filePath });- const { timecodePlaceholder, formatTimecode, formatTimeAndFrames, parseTimecode, getFrameCount, promptTimecode } = useTimecode({ detectedFps, timecodeFormat, showGenericDialog });+ const { timecodePlaceholder, formatTimecode, parseTimecode, getFrameCount, promptTimecode } = useTimecode({ detectedFps, timecodeFormat, showGenericDialog });const { loadSubtitle, subtitlesByStreamId, setSubtitlesByStreamId } = useSubtitles();const fileDurationNonZero = isDurationValid(fileDuration) ? fileDuration : 1;@@ -231,6 +231,10 @@ function App() {const isFileOpened = !!filePath;+ const [hoveringTime, setHoveringTime] = useState<number>();++ const displayTime = (hoveringTime != null && isFileOpened && !playing ? hoveringTime : relevantTime) + startTimeOffset;+const onOutputFormatUserChange = useCallback((newFormat: string) => {setFileFormat(newFormat);if (outFormatLocked) {@@ -2605,7 +2609,7 @@ function App() {</AnimatePresence></div>- <div className="no-user-select" style={bottomStyle}>+ <div style={bottomStyle}><TimelineshouldShowKeyframes={shouldShowKeyframes}waveforms={waveforms}@@ -2630,7 +2634,6 @@ function App() {currentCutSeg={currentCutSeg}inverseCutSegments={inverseCutSegments}formatTimecode={formatTimecode}- formatTimeAndFrames={formatTimeAndFrames}zoomWindowStartTime={zoomWindowStartTime}zoomWindowEndTime={zoomWindowEndTime}onZoomWindowStartTimeChange={setZoomWindowStartTime}@@ -2641,6 +2644,7 @@ function App() {goToTimecode={goToTimecode}darkMode={darkMode}setCutTime={setCutTime}+ setHoveringTime={setHoveringTime}/><BottomBar@@ -2692,6 +2696,9 @@ function App() {playbackRate={playbackRate}currentFrame={currentFrame}playbackMode={playbackMode}+ displayTime={displayTime}+ fileDurationNonZero={fileDurationNonZero}+ getFrameCount={getFrameCount}/></div>diff --git a/src/renderer/src/BottomBar.tsx b/src/renderer/src/BottomBar.tsxindex 127544ec..f6132404 100644--- a/src/renderer/src/BottomBar.tsx+++ b/src/renderer/src/BottomBar.tsx@@ -25,7 +25,7 @@ import { useSegColors } from './contexts';import { isExactDurationMatch } from './util/duration';import useUserSettings from './hooks/useUserSettings';import { askForPlaybackRate, checkAppPath } from './dialogs';-import type { FormatTimecode, ParseTimecode, PlaybackMode, SegmentColorIndex, SegmentToExport, StateSegment } from './types';+import type { FormatTimecode, GetFrameCount, ParseTimecode, PlaybackMode, SegmentColorIndex, SegmentToExport, StateSegment } from './types';import type { WaveformMode } from '../../common/types';import type { Frame } from './ffmpeg';@@ -36,6 +36,15 @@ const zoomOptions = Array.from({ length: 13 }).fill(undefined).map((_unused, z)const leftRightWidth = 100;+const timeWrapperStyle: CSSProperties = {+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+ position: 'absolute',+ inset: 0,+ marginLeft: '1em',+};+// eslint-disable-next-line react/display-nameconst InvertCutModeButton = memo(({ invertCutSegments, setInvertCutSegments }: { invertCutSegments: boolean, setInvertCutSegments: Dispatch<SetStateAction<boolean>> }) => {const { t } = useTranslation();@@ -218,8 +227,9 @@ const CutTimeInput = memo(({ disabled, darkMode, cutTime, setCutTime, startTimeOmarginLeft: isStart ? 0 : 5,marginRight: isStart ? 5 : 0,boxSizing: 'border-box',- fontFamily: 'inherit',- width: 90,+ fontFamily: 'monospace',+ letterSpacing: '-.05em',+ width: 94,outline: 'none',color: error ? dangerColor : (isCutTimeManualSet() ? 'var(--gray-12)' : 'var(--gray-11)'),}), [border, error, isCutTimeManualSet, isStart]);@@ -260,7 +270,7 @@ function BottomBar({toggleShowThumbnails, toggleWaveformMode, waveformMode, showThumbnails,outputPlaybackRate, setOutputPlaybackRate,formatTimecode, parseTimecode, playbackRate,- currentFrame, playbackMode,+ currentFrame, playbackMode, displayTime, fileDurationNonZero, getFrameCount,}: {zoom: number,setZoom: (fn: (z: number) => number) => void,@@ -310,10 +320,15 @@ function BottomBar({playbackRate: number,currentFrame: Frame | undefined,playbackMode: PlaybackMode | undefined,+ displayTime: number,+ fileDurationNonZero: number,+ getFrameCount: GetFrameCount,}) {const { t } = useTranslation();const { getSegColor } = useSegColors();+ const isZoomed = zoom > 1;+const playStyle = useMemo<CSSProperties>(() => ({paddingLeft: playing ? 0 : '.1em',color: 'white',@@ -404,9 +419,13 @@ function BottomBar({const currentCutSegOrDefault = useMemo(() => currentCutSeg ?? { segColorIndex: 0 }, [currentCutSeg]);+ const displayTimePercent = useMemo(() => `${Math.round((displayTime / fileDurationNonZero) * 100)}%`, [displayTime, fileDurationNonZero]);++ const displayTimeFrameCount = useMemo(() => getFrameCount(displayTime), [displayTime, getFrameCount]);+return (<>- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', opacity: isFileOpened ? 1 : 0.5 }}>+ <div className="no-user-select" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', opacity: isFileOpened ? 1 : 0.5 }}><div style={{ display: 'flex', alignItems: 'center', flexBasis: leftRightWidth }}>{!simpleMode && (<>@@ -530,10 +549,7 @@ function BottomBar({<div style={{ flexBasis: leftRightWidth }} /></div>- <div- className="no-user-select"- style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '.1em .3em', gap: '.5em', height: '2em' }}- >+ <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '.1em .3em', gap: '.5em', height: '2em' }}><InvertCutModeButton invertCutSegments={invertCutSegments} setInvertCutSegments={setInvertCutSegments} /><div style={{ display: 'flex', alignItems: 'center' }}>@@ -557,7 +573,7 @@ function BottomBar({<div ref={playbackRateRef} title={t('Playback rate')} style={{ color: 'var(--gray-11)', fontSize: '.7em' }}>{playbackRate.toFixed(1)}</div>- <div>+ <div style={{ whiteSpace: 'nowrap' }}><IoMdSpeedometer title={t('Change FPS')} style={{ fontSize: '1.3em', verticalAlign: 'middle' }} role="button" onClick={handleChangePlaybackRateClick} />{detectedFps != null && (@@ -568,7 +584,7 @@ function BottomBar({)}{isFileOpened && !simpleMode && hasVideo && (- <div onClick={increaseRotation} role="button">+ <div onClick={increaseRotation} role="button" style={{ whiteSpace: 'nowrap' }}><MdRotate90DegreesCcwstyle={{ fontSize: '1.3em', verticalAlign: 'middle', color: isRotationSet ? primaryTextColor : undefined }}title={`${t('Set output rotation. Current: ')} ${isRotationSet ? rotationStr : t('Don\'t modify')}`}@@ -579,6 +595,14 @@ function BottomBar({<div style={{ flexGrow: 1 }} />+ <div style={timeWrapperStyle}>+ <div style={{ fontFamily: 'monospace', letterSpacing: '-0.08em' }}>+ {formatTimecode({ seconds: displayTime })}+ <span style={{ display: 'inline-block', minWidth: '3em', marginLeft: '.5em' }}><span style={{ opacity: 0.5, userSelect: 'none' }}>f</span>{displayTimeFrameCount ?? 0}</span>+ {isZoomed && ` ${displayTimePercent}`}+ </div>+ </div>+{!simpleMode && isFileOpened && (<FaTrashAlttitle={t('Close file and clean up')}@@ -589,7 +613,7 @@ function BottomBar({)}{hasVideo && (- <div>+ <div style={{ whiteSpace: 'nowrap' }}><IoIosCamerarole="button"style={{ fontSize: '1.9em', verticalAlign: 'middle' }}diff --git a/src/renderer/src/Timeline.module.css b/src/renderer/src/Timeline.module.cssindex 1774509f..f0a2b22b 100644--- a/src/renderer/src/Timeline.module.css+++ b/src/renderer/src/Timeline.module.css@@ -1,21 +1,3 @@-.time-wrapper {- position: absolute;- left: 0;- right: 0;- bottom: 0;- display: flex;- align-items: center;- justify-content: center;- pointer-events: none;-}-.time {- background: rgba(0,0,0,0.4);- border-radius: 3px;- padding: 2px 4px;- color: rgba(255, 255, 255, 0.8);- transition: opacity 0.2s;-}-@keyframes background-animation {0% {background-position: 0% 50%}100% {background-position: 100% 50%}diff --git a/src/renderer/src/Timeline.tsx b/src/renderer/src/Timeline.tsxindex 6f77b1e7..e4e2a8da 100644--- a/src/renderer/src/Timeline.tsx+++ b/src/renderer/src/Timeline.tsx@@ -1,5 +1,5 @@import type { MutableRefObject, CSSProperties, WheelEventHandler, MouseEventHandler } from 'react';-import { memo, useRef, useMemo, useCallback, useEffect, useState } from 'react';+import { memo, useRef, useMemo, useCallback, useEffect } from 'react';import { motion, useMotionValue, useSpring } from 'motion/react';import debounce from 'lodash/debounce';import { useTranslation } from 'react-i18next';@@ -84,11 +84,8 @@ const CommandedTime = memo(({ commandedTimePercent }: { commandedTimePercent: stconst timelineHeight = 36;-const timeWrapperStyle: CSSProperties = { height: timelineHeight };-function Timeline({fileDurationNonZero,- startTimeOffset,playerTime,commandedTime,relevantTime,@@ -101,7 +98,6 @@ function Timeline({currentCutSeg,inverseCutSegments,formatTimecode,- formatTimeAndFrames,waveforms,overviewWaveform,shouldShowWaveform,@@ -114,13 +110,12 @@ function Timeline({waveformEnabled,waveformHeight,showThumbnails,- playing,- isFileOpened,onWheel,commandedTimeRef,goToTimecode,darkMode,setCutTime,+ setHoveringTime,} : {fileDurationNonZero: number,startTimeOffset: number,@@ -136,7 +131,6 @@ function Timeline({currentCutSeg: StateSegment | undefined,inverseCutSegments: InverseCutSegment[],formatTimecode: FormatTimecode,- formatTimeAndFrames: (a: number) => string,waveforms: WaveformSlice[],overviewWaveform: OverviewWaveform | undefined,shouldShowWaveform: boolean,@@ -155,7 +149,8 @@ function Timeline({commandedTimeRef: MutableRefObject<number>,goToTimecode: () => void,darkMode: boolean,- setCutTime: UseSegments['setCutTime'];+ setCutTime: UseSegments['setCutTime'],+ setHoveringTime: (time: number | undefined) => void,}) {const { t } = useTranslation();@@ -166,11 +161,6 @@ function Timeline({const timelineScrollerSkipEventDebounce = useRef<() => void>();const timelineWrapperRef = useRef<HTMLDivElement>(null);- const [hoveringTime, setHoveringTime] = useState<number>();-- const displayTime = (hoveringTime != null && isFileOpened && !playing ? hoveringTime : relevantTime) + startTimeOffset;- const displayTimePercent = useMemo(() => `${Math.round((displayTime / fileDurationNonZero) * 100)}%`, [displayTime, fileDurationNonZero]);-const isZoomed = zoom > 1;const keyFramesInZoomWindow = useMemo(() => (zoomWindowEndTime == null ? [] : neighbouringKeyFrames.filter((f) => f.time >= zoomWindowStartTime && f.time <= zoomWindowEndTime)), [neighbouringKeyFrames, zoomWindowEndTime, zoomWindowStartTime]);@@ -292,7 +282,7 @@ function Timeline({useEffect(() => {setHoveringTime(undefined);- }, [relevantTime]);+ }, [relevantTime, setHoveringTime]);// for performanceconst currentCutSegRef = useRef<StateSegment | undefined>(currentCutSeg);@@ -358,29 +348,7 @@ function Timeline({window.addEventListener('mousemove', onMouseMove);}, [fileDurationNonZero, getMouseTimelinePos, seekAbs, segmentMouseModifierKey, setCutTime, zoom]);- const timeRef = useRef<HTMLDivElement>(null);- const timeFadeTimeoutRef = useRef<NodeJS.Timeout>();-- const onMouseMove = useCallback<MouseEventHandler<HTMLDivElement>>((e) => {- // need to manually check, because we cannot use css :hover when pointer-events: none- // and we need pointer-events: none on time because we want to be able to click through it to segments behind (and they are not parent)- const rect = timeRef.current?.getBoundingClientRect();- const isInBounds = rect && e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom;- const showHide = (show: boolean) => timeRef.current?.style.setProperty('opacity', show ? '0.2' : '1');- if (isInBounds != null) showHide(isInBounds);- // console.log('isInBounds', isInBounds);-- // https://github.com/mifi/lossless-cut/issues/2592#issuecomment-3476211496- if (timeFadeTimeoutRef.current) clearTimeout(timeFadeTimeoutRef.current);- timeFadeTimeoutRef.current = setTimeout(() => showHide(false), 1000);-- if (!mouseDownRef.current) { // no button pressed- setHoveringTime(getMouseTimelinePos(e.nativeEvent));- }- e.preventDefault();- }, [getMouseTimelinePos]);-- const onMouseOut = useCallback(() => setHoveringTime(undefined), []);+ const onMouseOut = useCallback(() => setHoveringTime(undefined), [setHoveringTime]);const contextMenuTemplate = useMemo(() => [{ label: t('Seek to timecode'), click: goToTimecode },@@ -396,9 +364,9 @@ function Timeline({return (// eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/mouse-events-have-key-events<div+ className="no-user-select"style={{ position: 'relative', borderTop: '1px solid var(--gray-7)', borderBottom: '1px solid var(--gray-7)' }}onMouseDown={onMouseDown}- onMouseMove={onMouseMove}// eslint-disable-next-line jsx-a11y/mouse-events-have-key-eventsonMouseOut={onMouseOut}>@@ -486,12 +454,6 @@ function Timeline({)}</div></div>-- <div style={timeWrapperStyle} className={styles['time-wrapper']}>- <div className={styles['time']} ref={timeRef}>- {formatTimeAndFrames(displayTime)}{isZoomed ? ` ${displayTimePercent}` : ''}- </div>- </div></div>);}diff --git a/src/renderer/src/hooks/useTimecode.tsx b/src/renderer/src/hooks/useTimecode.tsxindex 5ae69ef9..c078d89a 100644--- a/src/renderer/src/hooks/useTimecode.tsx+++ b/src/renderer/src/hooks/useTimecode.tsx@@ -54,16 +54,6 @@ export default ({ detectedFps, timecodeFormat, showGenericDialog }: {return parseDuration(val);}, [detectedFps, frameCountToDuration, timecodeFormat]);- const formatTimeAndFrames = useCallback((seconds: number) => {- const frameCount = getFrameCount(seconds);-- const timeStr = timecodeFormat === 'timecodeWithFramesFraction'- ? formatDuration({ seconds, fps: detectedFps })- : formatDuration({ seconds });-- return `${timeStr} (${frameCount ?? '0'})`;- }, [detectedFps, timecodeFormat, getFrameCount]);-const promptTimecode = useCallback(async ({ initialValue, title, description, inputPlaceholder, allowRelative = false }: {initialValue?: string | undefined,title: string,@@ -141,7 +131,6 @@ export default ({ detectedFps, timecodeFormat, showGenericDialog }: {return {parseTimecode,formatTimecode,- formatTimeAndFrames,timecodePlaceholder,getFrameCount,promptTimecode,