The swiss army knife of lossless video/audio editing
use correct stream index if more than one
Mikael Finstad826cb5743c82
diff --git a/src/App.jsx b/src/App.jsxindex 862dd13f..c27d0e38 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -820,7 +820,7 @@ const App = memo(() => {useEffect(() => () => waveform && URL.revokeObjectURL(waveform.url), [waveform]);function showUnsupportedFileMessage() {- toast.fire({ timer: 10000, icon: 'info', title: i18n.t('File not natively supported'), text: i18n.t('There will be no audio and a low quality preview. The final export will however be lossless and contains audio. You may convert it from the menu for a better preview') });+ toast.fire({ timer: 10000, icon: 'info', title: i18n.t('File not natively supported'), text: i18n.t('Preview will have no audio and low quality. The final export will however be lossless with audio. You may convert it from the menu for a better preview.') });}const createDummyVideo = useCallback(async (cod, fp) => {@@ -1797,7 +1797,7 @@ const App = memo(() => {onError={onVideoError}/>- {canvasPlayerEnabled && <Canvas rotate={effectiveRotation} filePath={filePath} width={mainVideoStream.width} height={mainVideoStream.height} playerTime={playerTime} commandedTime={commandedTime} playing={playing} />}+ {canvasPlayerEnabled && <Canvas rotate={effectiveRotation} filePath={filePath} width={mainVideoStream.width} height={mainVideoStream.height} streamIndex={mainVideoStream.index} playerTime={playerTime} commandedTime={commandedTime} playing={playing} />}</div>{isRotationSet && (diff --git a/src/CanvasPlayer.js b/src/CanvasPlayer.jsindex 96f5b3d7..470ba574 100644--- a/src/CanvasPlayer.js+++ b/src/CanvasPlayer.js@@ -3,7 +3,7 @@ import { encodeLiveRawStream, getOneRawFrame } from './ffmpeg';// TODO keep everything in electron land?const strtok3 = window.require('strtok3');-export default ({ path, width: inWidth, height: inHeight }) => {+export default ({ path, width: inWidth, height: inHeight, streamIndex }) => {let canvas;let terminated;@@ -35,7 +35,7 @@ export default ({ path, width: inWidth, height: inHeight }) => {if (playing) {try {- const { process: processIn, channels, width, height } = encodeLiveRawStream({ path, inWidth, inHeight, seekTo: commandedTime });+ const { process: processIn, channels, width, height } = encodeLiveRawStream({ path, inWidth, inHeight, streamIndex, seekTo: commandedTime });process = processIn;// process.stderr.on('data', data => console.log(data.toString('utf-8')));@@ -55,7 +55,7 @@ export default ({ path, width: inWidth, height: inHeight }) => {}} else {try {- const { process: processIn, width, height } = getOneRawFrame({ path, inWidth, inHeight, seekTo: commandedTime });+ const { process: processIn, width, height } = getOneRawFrame({ path, inWidth, inHeight, streamIndex, seekTo: commandedTime });process = processIn;const { stdout: rgbaImage } = await process;diff --git a/src/ffmpeg.js b/src/ffmpeg.jsindex 937819c2..4b182bec 100644--- a/src/ffmpeg.js+++ b/src/ffmpeg.js@@ -712,7 +712,7 @@ export function getStreamFps(stream) {return undefined;}-function createRawFfmpeg({ fps = 25, path, inWidth, inHeight, seekTo, oneFrameOnly, execaOpts }) {+function createRawFfmpeg({ fps = 25, path, inWidth, inHeight, seekTo, oneFrameOnly, execaOpts, streamIndex }) {// const fps = 25; // TODOconst aspectRatio = inWidth / inHeight;@@ -739,7 +739,7 @@ function createRawFfmpeg({ fps = 25, path, inWidth, inHeight, seekTo, oneFrameOn'-i', path,'-vf', `fps=${fps},scale=${newWidth}:${newHeight}:flags=lanczos`,- '-map', 'v:0',+ '-map', `0:${streamIndex}`,'-vcodec', 'rawvideo','-pix_fmt', 'rgba',@@ -759,13 +759,13 @@ function createRawFfmpeg({ fps = 25, path, inWidth, inHeight, seekTo, oneFrameOn};}-export function getOneRawFrame({ path, inWidth, inHeight, seekTo }) {- const { process, width, height, channels } = createRawFfmpeg({ path, inWidth, inHeight, seekTo, oneFrameOnly: true, execaOpts: { encoding: null } });+export function getOneRawFrame({ path, inWidth, inHeight, seekTo, streamIndex }) {+ const { process, width, height, channels } = createRawFfmpeg({ path, inWidth, inHeight, seekTo, streamIndex, oneFrameOnly: true, execaOpts: { encoding: null } });return { process, width, height, channels };}-export function encodeLiveRawStream({ path, inWidth, inHeight, seekTo }) {- const { process, width, height, channels } = createRawFfmpeg({ path, inWidth, inHeight, seekTo, execaOpts: { encoding: null, buffer: false } });+export function encodeLiveRawStream({ path, inWidth, inHeight, seekTo, streamIndex }) {+ const { process, width, height, channels } = createRawFfmpeg({ path, inWidth, inHeight, seekTo, streamIndex, execaOpts: { encoding: null, buffer: false } });return {process,