The swiss army knife of lossless video/audio editing
log ffmpeg stderr
Mikael Finstad5bb67f8078f6
diff --git a/src/App.jsx b/src/App.jsxindex 14f9a72a..67b8cdff 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -1585,7 +1585,8 @@ const App = memo(() => {if (!checkFileOpened() || workingRef.current) return;try {setWorking(i18n.t('Fixing file duration'));- const path = await fixInvalidDuration({ fileFormat, customOutDir });+ setCutProgress(0);+ const path = await fixInvalidDuration({ fileFormat, customOutDir, duration, onProgress: setCutProgress });toast.fire({ icon: 'info', text: i18n.t('Duration has been fixed') });await loadMedia({ filePath: path, customOutDir });} catch (err) {@@ -1593,8 +1594,9 @@ const App = memo(() => {console.error('Failed to fix file duration', err);} finally {setWorking();+ setCutProgress();}- }, [checkFileOpened, customOutDir, fileFormat, fixInvalidDuration, loadMedia, setWorking]);+ }, [checkFileOpened, customOutDir, duration, fileFormat, fixInvalidDuration, loadMedia, setWorking]);const addStreamSourceFile = useCallback(async (path) => {if (allFilesMeta[path]) return undefined; // Already added?diff --git a/src/ffmpeg.js b/src/ffmpeg.jsindex 1b3b1b00..617c4d9d 100644--- a/src/ffmpeg.js+++ b/src/ffmpeg.js@@ -61,6 +61,7 @@ export async function runFfprobe(args, { timeout = isDev ? 10000 : 30000 } = {})}}+// todo collect warnings from ffmpeg output and show them after export? example: https://github.com/mifi/lossless-cut/issues/1469export function runFfmpeg(args, execaOptions, { logCli = true } = {}) {const ffmpegPath = getFfmpegPath();if (logCli) console.log(getFfCommandLine('ffmpeg', args));@@ -79,6 +80,17 @@ export function runFfmpeg(args, execaOptions, { logCli = true } = {}) {return process;}+export function logStdoutStderr({ stdout, stderr }) {+ if (stdout.length > 0) {+ console.log('%cSTDOUT:', 'color: green; font-weight: bold');+ console.log(stdout);+ }+ if (stderr.length > 0) {+ console.log('%cSTDERR:', 'color: blue; font-weight: bold');+ console.log(stderr);+ }+}+export function abortFfmpegs() {runningFfmpegs.forEach((process) => {process.kill('SIGTERM', { forceKillAfterTimeout: 10000 });diff --git a/src/hooks/useFfmpegOperations.js b/src/hooks/useFfmpegOperations.jsindex 142c2579..a90cd6fd 100644--- a/src/hooks/useFfmpegOperations.js+++ b/src/hooks/useFfmpegOperations.js@@ -4,7 +4,7 @@ import sum from 'lodash/sum';import pMap from 'p-map';import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, deleteDispositionValue, getHtml5ifiedPath } from '../util';-import { isCuttingStart, isCuttingEnd, handleProgress, getFfCommandLine, getDuration, runFfmpeg, createChaptersFromSegments, readFileMeta, cutEncodeSmartPart, getExperimentalArgs, html5ify as ffmpegHtml5ify, getVideoTimescaleArgs, RefuseOverwriteError } from '../ffmpeg';+import { isCuttingStart, isCuttingEnd, handleProgress, getFfCommandLine, getDuration, runFfmpeg, createChaptersFromSegments, readFileMeta, cutEncodeSmartPart, getExperimentalArgs, html5ify as ffmpegHtml5ify, getVideoTimescaleArgs, RefuseOverwriteError, logStdoutStderr } from '../ffmpeg';import { getMapStreamsArgs, getStreamIdsToCopy } from '../util/streams';import { getSmartCutParams } from '../smartcut';@@ -160,8 +160,8 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {stringToStream(concatTxt).pipe(process.stdin);- const { stdout } = await process;- console.log(stdout);+ const result = await process;+ logStdoutStderr(result);await optionalTransferTimestamps(metadataFromPath, outPath);@@ -315,7 +315,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {const process = runFfmpeg(ffmpegArgs);handleProgress(process, cutDuration, onProgress);const result = await process;- console.log(result.stdout);+ logStdoutStderr(result);await optionalTransferTimestamps(filePath, outPath, cutFrom);}, [filePath, optionalTransferTimestamps]);@@ -483,14 +483,14 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {const process = runFfmpeg(ffmpegArgs);handleProgress(process, duration, onProgress);- const { stdout } = await process;- console.log(stdout);+ const result = await process;+ logStdoutStderr(result);await optionalTransferTimestamps(filePathArg, outPath);}, [optionalTransferTimestamps]);// https://stackoverflow.com/questions/34118013/how-to-determine-webm-duration-using-ffprobe- const fixInvalidDuration = useCallback(async ({ fileFormat, customOutDir }) => {+ const fixInvalidDuration = useCallback(async ({ fileFormat, customOutDir, duration, onProgress }) => {const ext = getOutFileExtension({ outFormat: fileFormat, filePath });const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `reformatted${ext}` });@@ -508,9 +508,11 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {'-y', outPath,];- // TODO progress- const { stdout } = await runFfmpeg(ffmpegArgs);- console.log(stdout);+ const process = runFfmpeg(ffmpegArgs);+ handleProgress(process, duration, onProgress);++ const result = await process;+ logStdoutStderr(result);await optionalTransferTimestamps(filePath, outPath);