log ffmpeg stderr

also add progress to fix invalid duration
pull/1452/head
Mikael Finstad 4 years ago
parent e82f83ccbd
commit 5bb67f8078
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -1585,7 +1585,8 @@ const App = memo(() => {
if (!checkFileOpened() || workingRef.current) return; if (!checkFileOpened() || workingRef.current) return;
try { try {
setWorking(i18n.t('Fixing file duration')); 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') }); toast.fire({ icon: 'info', text: i18n.t('Duration has been fixed') });
await loadMedia({ filePath: path, customOutDir }); await loadMedia({ filePath: path, customOutDir });
} catch (err) { } catch (err) {
@ -1593,8 +1594,9 @@ const App = memo(() => {
console.error('Failed to fix file duration', err); console.error('Failed to fix file duration', err);
} finally { } finally {
setWorking(); setWorking();
setCutProgress();
} }
}, [checkFileOpened, customOutDir, fileFormat, fixInvalidDuration, loadMedia, setWorking]); }, [checkFileOpened, customOutDir, duration, fileFormat, fixInvalidDuration, loadMedia, setWorking]);
const addStreamSourceFile = useCallback(async (path) => { const addStreamSourceFile = useCallback(async (path) => {
if (allFilesMeta[path]) return undefined; // Already added? if (allFilesMeta[path]) return undefined; // Already added?

@ -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/1469
export function runFfmpeg(args, execaOptions, { logCli = true } = {}) { export function runFfmpeg(args, execaOptions, { logCli = true } = {}) {
const ffmpegPath = getFfmpegPath(); const ffmpegPath = getFfmpegPath();
if (logCli) console.log(getFfCommandLine('ffmpeg', args)); if (logCli) console.log(getFfCommandLine('ffmpeg', args));
@ -79,6 +80,17 @@ export function runFfmpeg(args, execaOptions, { logCli = true } = {}) {
return process; 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() { export function abortFfmpegs() {
runningFfmpegs.forEach((process) => { runningFfmpegs.forEach((process) => {
process.kill('SIGTERM', { forceKillAfterTimeout: 10000 }); process.kill('SIGTERM', { forceKillAfterTimeout: 10000 });

@ -4,7 +4,7 @@ import sum from 'lodash/sum';
import pMap from 'p-map'; import pMap from 'p-map';
import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, deleteDispositionValue, getHtml5ifiedPath } from '../util'; 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 { getMapStreamsArgs, getStreamIdsToCopy } from '../util/streams';
import { getSmartCutParams } from '../smartcut'; import { getSmartCutParams } from '../smartcut';
@ -160,8 +160,8 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
stringToStream(concatTxt).pipe(process.stdin); stringToStream(concatTxt).pipe(process.stdin);
const { stdout } = await process; const result = await process;
console.log(stdout); logStdoutStderr(result);
await optionalTransferTimestamps(metadataFromPath, outPath); await optionalTransferTimestamps(metadataFromPath, outPath);
@ -315,7 +315,7 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
const process = runFfmpeg(ffmpegArgs); const process = runFfmpeg(ffmpegArgs);
handleProgress(process, cutDuration, onProgress); handleProgress(process, cutDuration, onProgress);
const result = await process; const result = await process;
console.log(result.stdout); logStdoutStderr(result);
await optionalTransferTimestamps(filePath, outPath, cutFrom); await optionalTransferTimestamps(filePath, outPath, cutFrom);
}, [filePath, optionalTransferTimestamps]); }, [filePath, optionalTransferTimestamps]);
@ -483,14 +483,14 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
const process = runFfmpeg(ffmpegArgs); const process = runFfmpeg(ffmpegArgs);
handleProgress(process, duration, onProgress); handleProgress(process, duration, onProgress);
const { stdout } = await process; const result = await process;
console.log(stdout); logStdoutStderr(result);
await optionalTransferTimestamps(filePathArg, outPath); await optionalTransferTimestamps(filePathArg, outPath);
}, [optionalTransferTimestamps]); }, [optionalTransferTimestamps]);
// https://stackoverflow.com/questions/34118013/how-to-determine-webm-duration-using-ffprobe // 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 ext = getOutFileExtension({ outFormat: fileFormat, filePath });
const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `reformatted${ext}` }); const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `reformatted${ext}` });
@ -508,9 +508,11 @@ function useFfmpegOperations({ filePath, enableTransferTimestamps }) {
'-y', outPath, '-y', outPath,
]; ];
// TODO progress const process = runFfmpeg(ffmpegArgs);
const { stdout } = await runFfmpeg(ffmpegArgs); handleProgress(process, duration, onProgress);
console.log(stdout);
const result = await process;
logStdoutStderr(result);
await optionalTransferTimestamps(filePath, outPath); await optionalTransferTimestamps(filePath, outPath);

Loading…
Cancel
Save