From ea222ad12a4f9aff0a1d8482568afaee8bb0da4d Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 20 Feb 2020 14:20:05 +0800 Subject: [PATCH] show ffmpeg command log --- src/HelpSheet.jsx | 11 ++++++++++- src/ffmpeg.js | 10 ++++++++-- src/renderer.jsx | 8 ++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/HelpSheet.jsx b/src/HelpSheet.jsx index 1d487853..5b3a2596 100644 --- a/src/HelpSheet.jsx +++ b/src/HelpSheet.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { IoIosCloseCircleOutline } from 'react-icons/io'; import { motion, AnimatePresence } from 'framer-motion'; -const HelpSheet = ({ visible, onTogglePress, renderSettings }) => ( +const HelpSheet = ({ visible, onTogglePress, renderSettings, ffmpegCommandLog }) => ( {visible && ( ( {renderSettings()} + +

Last ffmpeg commands

+
+ {ffmpegCommandLog.reverse().map((log) => ( +
+ {log} +
+ ))} +
)}
diff --git a/src/ffmpeg.js b/src/ffmpeg.js index de853251..f91f2fc8 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -82,7 +82,7 @@ function getExtensionForFormat(format) { async function cut({ filePath, outFormat, cutFrom, cutTo, videoDuration, rotation, - onProgress, copyStreamIds, keyframeCut, outPath, + onProgress, copyStreamIds, keyframeCut, outPath, appendFfmpegCommandLog, }) { console.log('Cutting from', cutFrom, 'to', cutTo); @@ -126,7 +126,11 @@ async function cut({ '-f', outFormat, '-y', outPath, ]; - console.log('ffmpeg', ffmpegArgs.join(' ')); + const mapArg = arg => (/[^0-9a-zA-Z-_]/.test(arg) ? `'${arg}'` : arg); + const ffmpegCommand = `ffmpeg ${ffmpegArgs.map(mapArg).join(' ')}`; + + console.log(ffmpegCommand); + appendFfmpegCommandLog(ffmpegCommand); onProgress(0); @@ -142,6 +146,7 @@ async function cut({ async function cutMultiple({ customOutDir, filePath, segments: segmentsUnsorted, videoDuration, rotation, onProgress, keyframeCut, copyStreamIds, outFormat, isOutFormatUserSelected, + appendFfmpegCommandLog, }) { const segments = sortBy(segmentsUnsorted, 'cutFrom'); const singleProgresses = {}; @@ -174,6 +179,7 @@ async function cutMultiple({ cutTo, // eslint-disable-next-line no-loop-func onProgress: progress => onSingleProgress(i, progress), + appendFfmpegCommandLog, }); outFiles.push(outPath); diff --git a/src/renderer.jsx b/src/renderer.jsx index bc4e9a9d..f9e4f346 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -107,6 +107,7 @@ const App = memo(() => { const [streamsSelectorShown, setStreamsSelectorShown] = useState(false); const [zoom, setZoom] = useState(1); const [commandedTime, setCommandedTime] = useState(0); + const [ffmpegCommandLog, setFfmpegCommandLog] = useState([]); // Preferences const [captureFormat, setCaptureFormat] = useState(configStore.get('captureFormat')); @@ -137,6 +138,11 @@ const App = memo(() => { const timelineScrollerRef = useRef(); const timelineScrollerSkipEventRef = useRef(); + + function appendFfmpegCommandLog(command) { + setFfmpegCommandLog(old => [...old, command]); + } + function setCopyStreamIdsForPath(path, cb) { setCopyStreamIdsByFile((old) => { const oldIds = old[path] || {}; @@ -641,6 +647,7 @@ const App = memo(() => { keyframeCut, segments: ffmpegSegments, onProgress: setCutProgress, + appendFfmpegCommandLog, }); if (outFiles.length > 1 && autoMerge) { @@ -1631,6 +1638,7 @@ const App = memo(() => { visible={!!helpVisible} onTogglePress={toggleHelp} renderSettings={renderSettings} + ffmpegCommandLog={ffmpegCommandLog} /> );