Skip to content

The swiss army knife of lossless video/audio editing

play multiple audio tracks simultaneously #256 #936

Mikael Finstadf7dd568d4380
diff --git a/README.md b/README.md
index 4f0cfa46..bb02b08a 100644
--- a/README.md
+++ b/README.md
@@ -37,11 +37,13 @@ The main feature is lossless trimming and cutting of video and audio files, whic
- Losslessly cut out parts of video/audio (for cutting away commercials etc.)
- Losslessly rearrange the order of video/audio segments
- Lossless merge/concatenation of arbitrary files (with identical codecs parameters, e.g. from the same camera)
-- Lossless stream editing
+- Lossless multi track/stream editing
- Combine arbitrary tracks from multiple files (ex. add music or subtitle track to a video file)
- Remove unneeded tracks
- Replace or re-encode only some tracks
- Extract all tracks from a file (extract video, audio, subtitle, attachments and other tracks from one file into separate files)
+- View technical data about all tracks. Edit file metadata, per-track metadata and per-track disposition
+- Select video/audio tracks for playback. Playback multiple audio tracks simultaneously.
- Fast multi-file workflow (note: no mass/batch export yet)
- Keyboard shortcut workflow
- Losslessly remux video/audio into a different container (file) format
@@ -51,9 +53,7 @@ The main feature is lossless trimming and cutting of video and audio files, whic
- Optionally include original timestamps in image file names
- Manual input of cutpoint times
- Apply a per-file timecode offset (and auto load timecode from file)
-- Edit file metadata, per-track metadata and per-track disposition
- Change rotation/orientation metadata in videos
-- View technical data about all tracks
- Timeline zoom and frame/keyframe jumping for cutting around keyframes
- Video thumbnails and audio waveform
- Saves per project cut segments to project file
diff --git a/src/main/compatPlayer.ts b/src/main/compatPlayer.ts
index 16a3490e..baafb70f 100644
--- a/src/main/compatPlayer.ts
+++ b/src/main/compatPlayer.ts
@@ -5,16 +5,21 @@ import logger from './logger.js';
import { createMediaSourceProcess, readOneJpegFrame as readOneJpegFrameRaw } from './ffmpeg.js';
-export function createMediaSourceStream({ path, videoStreamIndex, audioStreamIndex, seekTo, size, fps }: {
- path: string, videoStreamIndex?: number | undefined, audioStreamIndex?: number | undefined, seekTo: number, size?: number | undefined, fps?: number | undefined,
+export function createMediaSourceStream({ path, videoStreamIndex, audioStreamIndexes, seekTo, size, fps }: {
+ path: string,
+ videoStreamIndex?: number | undefined,
+ audioStreamIndexes: number[],
+ seekTo: number,
+ size?: number | undefined,
+ fps?: number | undefined,
}) {
const abortController = new AbortController();
- logger.info('Starting preview process', { videoStreamIndex, audioStreamIndex, seekTo });
- const process = createMediaSourceProcess({ path, videoStreamIndex, audioStreamIndex, seekTo, size, fps });
+ logger.info('Starting preview process', { videoStreamIndex, audioStreamIndexes, seekTo });
+ const process = createMediaSourceProcess({ path, videoStreamIndex, audioStreamIndexes, seekTo, size, fps });
// eslint-disable-next-line unicorn/prefer-add-event-listener
abortController.signal.onabort = () => {
- logger.info('Aborting preview process', { videoStreamIndex, audioStreamIndex, seekTo });
+ logger.info('Aborting preview process', { videoStreamIndex, audioStreamIndexes, seekTo });
process.kill('SIGKILL');
};
diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.ts
index 18919fba..aed4a9b5 100644
--- a/src/main/ffmpeg.ts
+++ b/src/main/ffmpeg.ts
@@ -547,17 +547,42 @@ export function readOneJpegFrame({ path, seekTo, videoStreamIndex }: { path: str
const enableLog = false;
const encode = true;
-export function createMediaSourceProcess({ path, videoStreamIndex, audioStreamIndex, seekTo, size, fps }: {
- path: string, videoStreamIndex?: number | undefined, audioStreamIndex?: number | undefined, seekTo: number, size?: number | undefined, fps?: number | undefined,
+export function createMediaSourceProcess({ path, videoStreamIndex, audioStreamIndexes, seekTo, size, fps }: {
+ path: string,
+ videoStreamIndex?: number | undefined,
+ audioStreamIndexes: number[],
+ seekTo: number,
+ size?: number | undefined,
+ fps?: number | undefined,
}) {
- function getVideoFilters() {
- if (videoStreamIndex == null) return [];
-
- const filters: string[] = [];
- if (fps != null) filters.push(`fps=${fps}`);
- if (size != null) filters.push(`scale=${size}:${size}:flags=lanczos:force_original_aspect_ratio=decrease`);
- if (filters.length === 0) return [];
- return ['-vf', filters.join(',')];
+ function getFilters() {
+ const graph: string[] = [];
+
+ if (videoStreamIndex != null) {
+ const videoFilters: string[] = [];
+ if (fps != null) videoFilters.push(`fps=${fps}`);
+ // todo
+ // [libx264 @ 0x13bf07a40] height not divisible by 2 (800x333)
+ // [vost#0:0/libx264 @ 0x13bf07770] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
+ if (size != null) videoFilters.push(`scale=${size}:${size}:flags=lanczos:force_original_aspect_ratio=decrease`);
+ const videoFiltersStr = videoFilters.length > 0 ? videoFilters.join(',') : 'null';
+ graph.push(`[0:${videoStreamIndex}]${videoFiltersStr}[video]`);
+ }
+
+ if (audioStreamIndexes.length > 0) {
+ const indexesStr = audioStreamIndexes.map((i) => `[0:${i}]`).join('');
+ let audioFiltersStr;
+ if (audioStreamIndexes.length > 1) {
+ const weightsStr = audioStreamIndexes.map(() => '1').join(' ');
+ audioFiltersStr = `amix=inputs=${audioStreamIndexes.length}:duration=longest:weights=${weightsStr}:normalize=0:dropout_transition=2`;
+ } else {
+ audioFiltersStr = 'anull';
+ }
+ graph.push(`${indexesStr}${audioFiltersStr}[audio]`);
+ }
+
+ if (graph.length === 0) return [];
+ return ['-filter_complex', graph.join(';')];
}
// https://stackoverflow.com/questions/16658873/how-to-minimize-the-delay-in-a-live-streaming-with-ffmpeg
@@ -580,21 +605,19 @@ export function createMediaSourceProcess({ path, videoStreamIndex, audioStreamIn
'-i', path,
- ...(videoStreamIndex != null ? ['-map', `0:${videoStreamIndex}`] : ['-vn']),
-
- ...(audioStreamIndex != null ? ['-map', `0:${audioStreamIndex}`] : ['-an']),
-
...(encode ? [
- ...(videoStreamIndex != null ? [
- ...getVideoFilters(),
+ ...getFilters(),
+ ...(videoStreamIndex != null ? [
+ '-map', '[video]',
'-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-preset', 'ultrafast', '-tune', 'zerolatency', '-crf', '10',
'-g', '1', // reduces latency and buffering
- ] : []),
+ ] : ['-vn']),
- ...(audioStreamIndex != null ? [
+ ...(audioStreamIndexes.length > 0 ? [
+ '-map', '[audio]',
'-ac', '2', '-c:a', 'aac', '-b:a', '128k',
- ] : []),
+ ] : ['-an']),
// May alternatively use webm/vp8 https://stackoverflow.com/questions/24152810/encoding-ffmpeg-to-mpeg-dash-or-webm-with-keyframe-clusters-for-mediasource
] : [
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 6f8606db..32164fff 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -138,7 +138,7 @@ function App() {
const [shortestFlag, setShortestFlag] = useState(false);
const [zoomWindowStartTime, setZoomWindowStartTime] = useState(0);
const [activeVideoStreamIndex, setActiveVideoStreamIndex] = useState<number>();
- const [activeAudioStreamIndex, setActiveAudioStreamIndex] = useState<number>();
+ const [activeAudioStreamIndexes, setActiveAudioStreamIndexes] = useState<Set<number>>(new Set());
const [activeSubtitleStreamIndex, setActiveSubtitleStreamIndex] = useState<number>();
const [hideMediaSourcePlayer, setHideMediaSourcePlayer] = useState(false);
const [exportConfirmVisible, setExportConfirmVisible] = useState(false);
@@ -292,9 +292,14 @@ function App() {
const mainVideoStream = useMemo(() => videoStreams[0], [videoStreams]);
const mainAudioStream = useMemo(() => audioStreams[0], [audioStreams]);
- const activeVideoStream = useMemo(() => (activeVideoStreamIndex != null ? videoStreams.find((stream) => stream.index === activeVideoStreamIndex) : undefined) ?? mainVideoStream, [activeVideoStreamIndex, mainVideoStream, videoStreams]);
- const activeAudioStream = useMemo(() => (activeAudioStreamIndex != null ? audioStreams.find((stream) => stream.index === activeAudioStreamIndex) : undefined) ?? mainAudioStream, [activeAudioStreamIndex, audioStreams, mainAudioStream]);
const activeSubtitle = useMemo(() => (activeSubtitleStreamIndex != null ? subtitlesByStreamId[activeSubtitleStreamIndex] : undefined), [activeSubtitleStreamIndex, subtitlesByStreamId]);
+ const activeVideoStream = useMemo(() => (activeVideoStreamIndex != null ? videoStreams.find((stream) => stream.index === activeVideoStreamIndex) : undefined) ?? mainVideoStream, [activeVideoStreamIndex, mainVideoStream, videoStreams]);
+ const activeAudioStreams = useMemo(() => {
+ let ret: FFprobeStream[] = [];
+ if (activeAudioStreamIndexes.size > 0) ret = audioStreams.filter((stream) => activeAudioStreamIndexes.has(stream.index));
+ if (ret.length === 0 && mainAudioStream != null) ret = [mainAudioStream];
+ return ret;
+ }, [activeAudioStreamIndexes, audioStreams, mainAudioStream]);
// 360 means we don't modify rotation gtrgt
const isRotationSet = rotation !== 360;
@@ -302,13 +307,23 @@ function App() {
const zoomAbs = useCallback((fn: (v: number) => number) => setZoom((z) => Math.min(Math.max(fn(z), 1), zoomMax)), []);
const zoomRel = useCallback((rel: number) => zoomAbs((z) => z + (rel * (1 + (z / 10)))), [zoomAbs]);
- const compatPlayerRequired = usingDummyVideo;
- const compatPlayerWanted = (
- isRotationSet
- // if user selected a custom video/audio stream, use compat player if the html5 player does not have any track index corresponding to the selected stream indexes
- || ((activeVideoStreamIndex != null || activeAudioStreamIndex != null) && videoRef.current != null && !canHtml5PlayerPlayStreams(videoRef.current, activeVideoStreamIndex, activeAudioStreamIndex))
- ) && !hideMediaSourcePlayer;
- const compatPlayerEnabled = (compatPlayerRequired || compatPlayerWanted) && (activeVideoStream != null || activeAudioStream != null);
+ const compatPlayerRequired = (
+ // when using html5ified dummy video, we *have* to use canvas player
+ usingDummyVideo
+ // or if user selected an explicit video or audio stream, and the html5 player does not have any track index corresponding to the selected stream index
+ || (
+ (activeVideoStreamIndex != null || activeAudioStreamIndexes.size === 1)
+ && videoRef.current != null
+ && !canHtml5PlayerPlayStreams(videoRef.current, activeVideoStreamIndex, [...activeAudioStreamIndexes][0])
+ )
+ // or if selected multiple audio streams (html5 video element doesn't support that)
+ || activeAudioStreamIndexes.size > 1
+ );
+ // if user selected a rotation, but they might want to turn off the rotation preview
+ // but allow the user to disable
+ const compatPlayerWanted = isRotationSet && !hideMediaSourcePlayer;
+
+ const compatPlayerEnabled = (compatPlayerRequired || compatPlayerWanted) && (activeVideoStream != null || activeAudioStreams.length > 0);
const shouldShowPlaybackStreamSelector = videoStreams.length > 0 || audioStreams.length > 0 || (subtitleStreams.length > 0 && !compatPlayerEnabled);
@@ -530,11 +545,12 @@ function App() {
enableVideoTrack(videoRef.current, videoStreamIndex);
setActiveVideoStreamIndex(videoStreamIndex);
}, [videoRef]);
- const onActiveAudioStreamChange = useCallback((audioStreamIndex?: number) => {
+
+ const onActiveAudioStreamsChange = useCallback((audioStreamIndexes: Set<number>) => {
invariant(videoRef.current);
setHideMediaSourcePlayer(false);
- enableAudioTrack(videoRef.current, audioStreamIndex);
- setActiveAudioStreamIndex(audioStreamIndex);
+ enableAudioTrack(videoRef.current, [...audioStreamIndexes][0]);
+ setActiveAudioStreamIndexes(audioStreamIndexes);
}, [videoRef]);
const allFilesMeta = useMemo(() => ({
@@ -545,7 +561,7 @@ function App() {
// total number of streams for ALL files
const numStreamsTotal = Object.values(allFilesMeta).flatMap(({ streams }) => streams).length;
- const hasAudio = !!activeAudioStream;
+ const hasAudio = activeAudioStreams.length > 0;
const hasVideo = !!activeVideoStream;
const waveformEnabled = hasAudio && waveformMode != null;
@@ -555,7 +571,7 @@ function App() {
const { thumbnailsSorted, setThumbnails } = useThumbnails({ filePath, zoomedDuration, zoomWindowStartTime, showThumbnails });
const { neighbouringKeyFrames, findNearestKeyFrameTime } = useKeyframes({ keyframesEnabled, filePath, commandedTime, videoStream: activeVideoStream, detectedFps, ffmpegExtractWindow });
- const { waveforms, overviewWaveform, renderOverviewWaveform } = useWaveform({ filePath, relevantTime, waveformEnabled, audioStream: activeAudioStream, ffmpegExtractWindow, fileDuration });
+ const { waveforms, overviewWaveform, renderOverviewWaveform } = useWaveform({ filePath, relevantTime, waveformEnabled, audioStream: activeAudioStreams[0], ffmpegExtractWindow, fileDuration });
const onGenerateOverviewWaveformClick = useCallback(async () => {
if (working) return;
@@ -605,7 +621,7 @@ function App() {
setZoomWindowStartTime(0);
setDeselectedSegmentIds({});
setSubtitlesByStreamId({});
- setActiveAudioStreamIndex(undefined);
+ setActiveAudioStreamIndexes(new Set());
setActiveVideoStreamIndex(undefined);
setActiveSubtitleStreamIndex(undefined);
setHideMediaSourcePlayer(false);
@@ -2488,7 +2504,7 @@ function App() {
{renderSubtitles()}
</video>
- {filePath != null && compatPlayerEnabled && <MediaSourcePlayer rotate={effectiveRotation} filePath={filePath} videoStream={activeVideoStream} audioStream={activeAudioStream} playerTime={playerTime ?? 0} commandedTime={commandedTime} playing={playing} eventId={compatPlayerEventId} masterVideoRef={videoRef} mediaSourceQuality={mediaSourceQuality} playbackVolume={playbackVolume} />}
+ {filePath != null && compatPlayerEnabled && <MediaSourcePlayer rotate={effectiveRotation} filePath={filePath} videoStream={activeVideoStream} audioStreams={activeAudioStreams} playerTime={playerTime ?? 0} commandedTime={commandedTime} playing={playing} eventId={compatPlayerEventId} masterVideoRef={videoRef} mediaSourceQuality={mediaSourceQuality} playbackVolume={playbackVolume} />}
</div>
{bigWaveformEnabled && <BigWaveform waveforms={waveforms} relevantTime={relevantTime} playing={playing} fileDurationNonZero={fileDurationNonZero} zoom={zoomUnrounded} seekRel={seekRel} darkMode={darkMode} />}
@@ -2513,11 +2529,11 @@ function App() {
)}
{isFileOpened && (
- <div className="no-user-select" style={{ position: 'absolute', right: 0, bottom: 0, marginBottom: 10, display: 'flex', alignItems: 'center' }}>
+ <div className="no-user-select" style={{ position: 'absolute', right: 0, bottom: 0, marginBottom: 10, display: 'flex', alignItems: 'flex-end' }}>
<VolumeControl playbackVolume={playbackVolume} setPlaybackVolume={setPlaybackVolume} onToggleMutedClick={toggleMuted} />
{shouldShowPlaybackStreamSelector && (
- <PlaybackStreamSelector subtitleStreams={subtitleStreams} videoStreams={videoStreams} audioStreams={audioStreams} activeSubtitleStreamIndex={activeSubtitleStreamIndex} activeVideoStreamIndex={activeVideoStreamIndex} activeAudioStreamIndex={activeAudioStreamIndex} onActiveSubtitleChange={onActiveSubtitleChange} onActiveVideoStreamChange={onActiveVideoStreamChange} onActiveAudioStreamChange={onActiveAudioStreamChange} />
+ <PlaybackStreamSelector subtitleStreams={subtitleStreams} videoStreams={videoStreams} audioStreams={audioStreams} activeSubtitleStreamIndex={activeSubtitleStreamIndex} activeVideoStreamIndex={activeVideoStreamIndex} activeAudioStreamIndexes={activeAudioStreamIndexes} onActiveSubtitleChange={onActiveSubtitleChange} onActiveVideoStreamChange={onActiveVideoStreamChange} onActiveAudioStreamsChange={onActiveAudioStreamsChange} />
)}
{!showRightBar && (
diff --git a/src/renderer/src/MediaSourcePlayer.tsx b/src/renderer/src/MediaSourcePlayer.tsx
index 2262168f..b5538224 100644
--- a/src/renderer/src/MediaSourcePlayer.tsx
+++ b/src/renderer/src/MediaSourcePlayer.tsx
@@ -9,11 +9,11 @@ import { FFprobeStream } from '../../../ffprobe';
const { compatPlayer: { createMediaSourceStream, readOneJpegFrame } } = window.require('@electron/remote').require('./index.js');
-async function startPlayback({ path, video, videoStreamIndex, audioStreamIndex, seekTo, signal, playSafe, onCanPlay, getTargetTime, size, fps }: {
+async function startPlayback({ path, video, videoStreamIndex, audioStreamIndexes, seekTo, signal, playSafe, onCanPlay, getTargetTime, size, fps }: {
path: string,
video: ChromiumHTMLVideoElement,
videoStreamIndex?: number | undefined,
- audioStreamIndex?: number | undefined,
+ audioStreamIndexes: number[],
seekTo: number,
signal: AbortSignal,
playSafe: () => void,
@@ -61,7 +61,7 @@ async function startPlayback({ path, video, videoStreamIndex, audioStreamIndex,
const codecs: string[] = [];
if (videoStreamIndex != null) codecs.push('avc1.42C01F');
- if (audioStreamIndex != null) codecs.push('mp4a.40.2');
+ if (audioStreamIndexes.length > 0) codecs.push('mp4a.40.2');
const codecTag = codecs.join(', ');
const mimeCodec = `video/mp4; codecs="${codecTag}"`;
@@ -183,7 +183,7 @@ async function startPlayback({ path, video, videoStreamIndex, audioStreamIndex,
processChunk();
});
- stream = createMediaSourceStream({ path, videoStreamIndex, audioStreamIndex, seekTo, size, fps });
+ stream = createMediaSourceStream({ path, videoStreamIndex, audioStreamIndexes, seekTo, size, fps });
interval = setInterval(() => {
if (mediaSource.readyState !== 'open') {
@@ -257,8 +257,18 @@ async function createPauseImage({ path, seekTo, videoStreamIndex, canvas, signal
drawJpegFrame(canvas, jpegImage);
}
-function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStream, commandedTime, playing, eventId, masterVideoRef, mediaSourceQuality, playbackVolume }: {
- rotate: number | undefined, filePath: string, playerTime: number, videoStream: FFprobeStream | undefined, audioStream: FFprobeStream | undefined, commandedTime: number, playing: boolean, eventId: number, masterVideoRef: RefObject<HTMLVideoElement>, mediaSourceQuality: number, playbackVolume: number,
+function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStreams, commandedTime, playing, eventId, masterVideoRef, mediaSourceQuality, playbackVolume }: {
+ rotate: number | undefined,
+ filePath: string,
+ playerTime: number,
+ videoStream: FFprobeStream | undefined,
+ audioStreams: FFprobeStream[],
+ commandedTime: number,
+ playing: boolean,
+ eventId: number,
+ masterVideoRef: RefObject<HTMLVideoElement>,
+ mediaSourceQuality: number,
+ playbackVolume: number,
}) {
const videoRef = useRef<HTMLVideoElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
@@ -273,6 +283,8 @@ function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStr
: { startTime: playerTime, playing, eventId }
), [commandedTime, eventId, playerTime, playing]);
+ const audioStreamIndexes = useMemo(() => audioStreams.map((s) => s.index), [audioStreams]);
+
const [debouncedState] = useDebounce(state, 300, {
equalityFn: (a, b) => a.startTime === b.startTime && a.playing === b.playing && a.eventId === b.eventId,
leading: true,
@@ -328,7 +340,7 @@ function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStr
if (mediaSourceQuality === 0) fps = 30;
else if (mediaSourceQuality === 1) fps = 15;
- await startPlayback({ path: filePath, video, videoStreamIndex: videoStream?.index, audioStreamIndex: audioStream?.index, seekTo: debouncedState.startTime, signal: abortController.signal, playSafe, onCanPlay, getTargetTime, size, fps });
+ await startPlayback({ path: filePath, video, videoStreamIndex: videoStream?.index, audioStreamIndexes, seekTo: debouncedState.startTime, signal: abortController.signal, playSafe, onCanPlay, getTargetTime, size, fps });
} else { // paused
if (videoStream != null) {
await createPauseImage({ path: filePath, seekTo: debouncedState.startTime, videoStreamIndex: videoStream.index, canvas: canvasRef.current, signal: abortController.signal });
@@ -342,7 +354,7 @@ function MediaSourcePlayer({ rotate, filePath, playerTime, videoStream, audioStr
return () => abortController.abort();
// Important that we also have eventId in the deps, so that we can restart the preview when the eventId changes
- }, [debouncedState.startTime, debouncedState.eventId, filePath, masterVideoRef, playSafe, debouncedState.playing, videoStream, mediaSourceQuality, audioStream?.index]);
+ }, [debouncedState.startTime, debouncedState.eventId, filePath, masterVideoRef, playSafe, debouncedState.playing, videoStream, mediaSourceQuality, audioStreamIndexes]);
useEffect(() => {
if (videoRef.current) videoRef.current.volume = playbackVolume;
diff --git a/src/renderer/src/components/PlaybackStreamSelector.module.css b/src/renderer/src/components/PlaybackStreamSelector.module.css
new file mode 100644
index 00000000..da650f7e
--- /dev/null
+++ b/src/renderer/src/components/PlaybackStreamSelector.module.css
@@ -0,0 +1,15 @@
+.wrapper {
+ display: flex;
+ margin: 0 .3em;
+ padding: .5em;
+ border-radius: .3em;
+ color: var(--gray12);
+ background: var(--whiteA8);
+ box-shadow: 0 0 .3em .3em var(--whiteA5);
+ backdrop-filter: blur(7px);
+}
+
+:global(.dark-theme) .wrapper {
+ background: var(--blackA8);
+ box-shadow: 0 0 .3em .3em var(--blackA5);
+}
diff --git a/src/renderer/src/components/PlaybackStreamSelector.tsx b/src/renderer/src/components/PlaybackStreamSelector.tsx
index 20c37711..0945ee62 100644
--- a/src/renderer/src/components/PlaybackStreamSelector.tsx
+++ b/src/renderer/src/components/PlaybackStreamSelector.tsx
@@ -1,30 +1,34 @@
import { memo, useState, useCallback, useRef, useEffect, ChangeEventHandler, ChangeEvent } from 'react';
import { MdSubtitles } from 'react-icons/md';
import { useTranslation } from 'react-i18next';
-import Select from './Select';
+import { motion } from 'framer-motion';
+import Select from './Select';
+import Switch from './Switch';
+import styles from './PlaybackStreamSelector.module.css';
import { FFprobeStream } from '../../../../ffprobe';
+
function PlaybackStreamSelector({
subtitleStreams,
videoStreams,
audioStreams,
activeSubtitleStreamIndex,
activeVideoStreamIndex,
- activeAudioStreamIndex,
+ activeAudioStreamIndexes,
onActiveSubtitleChange,
onActiveVideoStreamChange,
- onActiveAudioStreamChange,
+ onActiveAudioStreamsChange,
}: {
subtitleStreams: FFprobeStream[],
videoStreams: FFprobeStream[],
audioStreams: FFprobeStream[],
activeSubtitleStreamIndex?: number | undefined,
activeVideoStreamIndex?: number | undefined,
- activeAudioStreamIndex?: number | undefined,
+ activeAudioStreamIndexes: Set<number>,
onActiveSubtitleChange: (a?: number | undefined) => void,
onActiveVideoStreamChange: (a?: number | undefined) => void,
- onActiveAudioStreamChange: (a?: number | undefined) => void,
+ onActiveAudioStreamsChange: (a: Set<number>) => void,
}) {
const [controlVisible, setControlVisible] = useState(false);
const timeoutRef = useRef<number>();
@@ -33,7 +37,7 @@ function PlaybackStreamSelector({
const resetTimer = useCallback(() => {
clearTimeout(timeoutRef.current);
- timeoutRef.current = window.setTimeout(() => setControlVisible(false), 7000);
+ timeoutRef.current = window.setTimeout(() => setControlVisible(false), 10000);
}, []);
const onChange = useCallback((e: ChangeEvent<HTMLSelectElement>, fn: (a: number | undefined) => void) => {
@@ -45,7 +49,13 @@ function PlaybackStreamSelector({
const onActiveSubtitleChange2 = useCallback<ChangeEventHandler<HTMLSelectElement>>((e) => onChange(e, onActiveSubtitleChange), [onActiveSubtitleChange, onChange]);
const onActiveVideoStreamChange2 = useCallback<ChangeEventHandler<HTMLSelectElement>>((e) => onChange(e, onActiveVideoStreamChange), [onActiveVideoStreamChange, onChange]);
- const onActiveAudioStreamChange2 = useCallback<ChangeEventHandler<HTMLSelectElement>>((e) => onChange(e, onActiveAudioStreamChange), [onActiveAudioStreamChange, onChange]);
+ const handleActiveAudioStreamsChange = useCallback((index: number, checked: boolean) => {
+ resetTimer();
+ const newActiveAudioStreamIndexes = new Set(activeAudioStreamIndexes);
+ if (checked) newActiveAudioStreamIndexes.add(index);
+ else newActiveAudioStreamIndexes.delete(index);
+ onActiveAudioStreamsChange(newActiveAudioStreamIndexes);
+ }, [activeAudioStreamIndexes, onActiveAudioStreamsChange, resetTimer]);
const onIconClick = useCallback(() => {
resetTimer();
@@ -57,46 +67,61 @@ function PlaybackStreamSelector({
return (
<>
{controlVisible && (
- <>
+ <motion.div className={styles['wrapper']} initial={{ opacity: 0, transform: 'translateX(100%)' }} animate={{ opacity: 1, transform: 'translateX(0%)' }}>
{subtitleStreams.length > 0 && (
- <Select
- value={activeSubtitleStreamIndex ?? ''}
- onChange={onActiveSubtitleChange2}
- onMouseMove={resetTimer}
- >
- <option value="">{t('Subtitle')}</option>
- {subtitleStreams.map((stream, i) => (
- <option key={stream.index} value={stream.index}>#{i + 1} (id {stream.index}) {stream.tags?.language}</option>
- ))}
- </Select>
+ <div style={{ margin: '0 .5em' }}>
+ <div style={{ marginBottom: '.3em' }}>{t('Subtitle')}</div>
+
+ <Select
+ value={activeSubtitleStreamIndex ?? ''}
+ onChange={onActiveSubtitleChange2}
+ onMouseMove={resetTimer}
+ >
+ <option value="">{t('Default')}</option>
+ {subtitleStreams.map((stream, i) => (
+ <option key={stream.index} value={stream.index}>#{i + 1} (id {stream.index + 1}) {stream.tags?.language}</option>
+ ))}
+ </Select>
+ </div>
)}
{videoStreams.length > 0 && (
- <Select
- value={activeVideoStreamIndex ?? ''}
- onChange={onActiveVideoStreamChange2}
- onMouseMove={resetTimer}
- >
- <option value="">{t('Video track')}</option>
- {videoStreams.map((stream, i) => (
- <option key={stream.index} value={stream.index}>#{i + 1} (id {stream.index + 1}) {stream.codec_name}</option>
- ))}
- </Select>
+ <div style={{ margin: '0 .5em' }}>
+ <div style={{ marginBottom: '.3em' }}>{t('Video track')}</div>
+
+ <Select
+ value={activeVideoStreamIndex ?? ''}
+ onChange={onActiveVideoStreamChange2}
+ onMouseMove={resetTimer}
+ >
+ <option value="">{t('Default')}</option>
+ {videoStreams.map((stream, i) => (
+ <option key={stream.index} value={stream.index}>#{i + 1} (id {stream.index + 1}) {stream.codec_name}</option>
+ ))}
+ </Select>
+ </div>
)}
{audioStreams.length > 0 && (
- <Select
- value={activeAudioStreamIndex ?? ''}
- onChange={onActiveAudioStreamChange2}
- onMouseMove={resetTimer}
- >
- <option value="">{t('Audio track')}</option>
- {audioStreams.map((stream, i) => (
- <option key={stream.index} value={stream.index}>#{i + 1} (id {stream.index + 1}) {stream.codec_name} - {stream.tags?.language}</option>
+ <div style={{ margin: '0 .5em' }}>
+ <div style={{ marginBottom: '.3em' }}>{t('Audio track')}</div>
+
+ {audioStreams.map((audioStream, i) => (
+ <div key={audioStream.index}>
+ <Switch
+ style={{ verticalAlign: 'middle', marginRight: '.4em' }}
+ checked={activeAudioStreamIndexes.has(audioStream.index)}
+ onClick={(e) => e.currentTarget.blur()}
+ onCheckedChange={(checked) => handleActiveAudioStreamsChange(audioStream.index, checked)}
+ />
+ <span style={{ verticalAlign: 'middle', marginRight: '.1em' }}>
+ #{i + 1} <span style={{ opacity: 0.5 }}>(id {audioStream.index + 1}) {audioStream.codec_name} {audioStream.tags?.language}</span>
+ </span>
+ </div>
))}
- </Select>
+ </div>
)}
- </>
+ </motion.div>
)}
<MdSubtitles
diff --git a/src/renderer/src/components/VolumeControl.tsx b/src/renderer/src/components/VolumeControl.tsx
index ed673fec..bd2f8c09 100644
--- a/src/renderer/src/components/VolumeControl.tsx
+++ b/src/renderer/src/components/VolumeControl.tsx
@@ -42,6 +42,7 @@ function VolumeControl({ playbackVolume, setPlaybackVolume, onToggleMutedClick }
min={0}
max={100}
value={playbackVolume * 100}
+ style={{ height: 30 }}
onChange={onVolumeChange}
/>
)}
diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts
index cb57c5d2..4788e165 100644
--- a/src/renderer/src/util/streams.ts
+++ b/src/renderer/src/util/streams.ts
@@ -293,6 +293,7 @@ function resetAudioTrack(video: ChromiumHTMLVideoElement) {
// https://github.com/mifi/lossless-cut/issues/256
export function enableVideoTrack(video: ChromiumHTMLVideoElement, index: number | undefined) {
if (index == null) {
+ console.log('Resetting video track');
resetVideoTrack(video);
return;
}
@@ -305,6 +306,7 @@ export function enableVideoTrack(video: ChromiumHTMLVideoElement, index: number
export function enableAudioTrack(video: ChromiumHTMLVideoElement, index: number | undefined) {
if (index == null) {
+ console.log('Resetting audio track');
resetAudioTrack(video);
return;
}