mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-22 10:22:31 +01:00
improve black detect
allow black detect to work on start/end times of selected segment closes #1226
This commit is contained in:
parent
280068a08f
commit
0803858575
@ -1757,9 +1757,9 @@ const App = memo(() => {
|
||||
setWorking(i18n.t('Detecting black scenes'));
|
||||
setCutProgress(0);
|
||||
|
||||
const blackSegments = await blackDetect({ filePath, duration, onProgress: setCutProgress });
|
||||
const blackSegments = await blackDetect({ filePath, duration, onProgress: setCutProgress, from: currentApparentCutSeg.start, to: currentApparentCutSeg.end });
|
||||
console.log('blackSegments', blackSegments);
|
||||
loadCutSegments(blackSegments.map(({ blackStart, blackEnd }) => ({ start: blackStart, end: blackEnd })));
|
||||
loadCutSegments(blackSegments.map(({ blackStart, blackEnd }) => ({ start: blackStart, end: blackEnd })), true);
|
||||
} catch (err) {
|
||||
errorToast(i18n.t('Failed to detect black scenes'));
|
||||
console.error('Failed to detect black scenes', err);
|
||||
@ -1767,7 +1767,7 @@ const App = memo(() => {
|
||||
setWorking();
|
||||
setCutProgress();
|
||||
}
|
||||
}, [duration, filePath, setWorking, loadCutSegments]);
|
||||
}, [filePath, setWorking, duration, currentApparentCutSeg, loadCutSegments]);
|
||||
|
||||
const userHtml5ifyCurrentFile = useCallback(async () => {
|
||||
if (!filePath) return;
|
||||
|
@ -532,8 +532,14 @@ export async function renderWaveformPng({ filePath, aroundTime, window, color })
|
||||
}
|
||||
}
|
||||
|
||||
export async function blackDetect({ filePath, duration, minInterval = 0.05, onProgress }) {
|
||||
const args = ['-hide_banner', '-i', filePath, '-vf', `blackdetect=d=${minInterval}`, '-an', '-f', 'null', '-'];
|
||||
export async function blackDetect({ filePath, duration, minInterval = 0.05, onProgress, from, to }) {
|
||||
const args = [
|
||||
'-hide_banner',
|
||||
...(from != null ? ['-ss', from.toFixed(5)] : []),
|
||||
'-i', filePath,
|
||||
...(to != null ? ['-t', (to - from).toFixed(5)] : []),
|
||||
'-vf', `blackdetect=d=${minInterval}`, '-an', '-f', 'null', '-',
|
||||
];
|
||||
const process = execa(getFfmpegPath(), args, { encoding: null, buffer: false });
|
||||
|
||||
const blackSegments = [];
|
||||
@ -549,7 +555,8 @@ export async function blackDetect({ filePath, duration, minInterval = 0.05, onPr
|
||||
handleProgress(process, duration, onProgress, customMatcher);
|
||||
|
||||
await process;
|
||||
return blackSegments;
|
||||
const offset = from != null ? from : 0;
|
||||
return blackSegments.map(({ blackStart, blackEnd }) => ({ blackStart: blackStart + offset, blackEnd: blackEnd + offset }));
|
||||
}
|
||||
|
||||
export async function extractWaveform({ filePath, outPath }) {
|
||||
|
Loading…
Reference in New Issue
Block a user