mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-22 10:22:31 +01:00
parent
1e003537ed
commit
f375e8ee74
@ -284,18 +284,29 @@ function getFffmpegJpegQuality(quality) {
|
|||||||
return Math.min(Math.max(qMin, quality, Math.round((1 - quality) * (qMax - qMin) + qMin)), qMax);
|
return Math.min(Math.max(qMin, quality, Math.round((1 - quality) * (qMax - qMin) + qMin)), qMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function captureFrames({ from, to, videoPath, outPathTemplate, quality, filter, framePts, onProgress }) {
|
function getQualityOpts({ captureFormat, quality }) {
|
||||||
const ffmpegQuality = getFffmpegJpegQuality(quality);
|
if (captureFormat === 'jpeg') return ['-q:v', getFffmpegJpegQuality(quality)];
|
||||||
|
if (captureFormat === 'webp') return ['-q:v', Math.max(0, Math.min(100, Math.round(quality * 100)))];
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCodecOpts(captureFormat) {
|
||||||
|
if (captureFormat === 'webp') return ['-c:v', 'libwebp']; // else we get only a single file for webp https://github.com/mifi/lossless-cut/issues/1693
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function captureFrames({ from, to, videoPath, outPathTemplate, quality, filter, framePts, onProgress, captureFormat }) {
|
||||||
const args = [
|
const args = [
|
||||||
'-ss', from,
|
'-ss', from,
|
||||||
'-i', videoPath,
|
'-i', videoPath,
|
||||||
'-t', Math.max(0, to - from),
|
'-t', Math.max(0, to - from),
|
||||||
'-q:v', ffmpegQuality,
|
...getQualityOpts({ captureFormat, quality }),
|
||||||
...(filter != null ? ['-vf', filter] : []),
|
...(filter != null ? ['-vf', filter] : []),
|
||||||
// https://superuser.com/questions/1336285/use-ffmpeg-for-thumbnail-selections
|
// https://superuser.com/questions/1336285/use-ffmpeg-for-thumbnail-selections
|
||||||
...(framePts ? ['-frame_pts', '1'] : []),
|
...(framePts ? ['-frame_pts', '1'] : []),
|
||||||
'-vsync', '0', // else we get a ton of duplicates (thumbnail filter)
|
'-vsync', '0', // else we get a ton of duplicates (thumbnail filter)
|
||||||
|
...getCodecOpts(captureFormat),
|
||||||
|
'-f', 'image2',
|
||||||
'-y', outPathTemplate,
|
'-y', outPathTemplate,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export default ({ formatTimecode, treatOutputFileModifiedTimeAsStart }) => {
|
|||||||
const outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: nameTemplateSuffix });
|
const outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: nameTemplateSuffix });
|
||||||
const firstFileOutPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix });
|
const firstFileOutPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix });
|
||||||
|
|
||||||
await ffmpegCaptureFrames({ from: fromTime, to: toTime, videoPath: filePath, outPathTemplate, quality, filter, onProgress });
|
await ffmpegCaptureFrames({ from: fromTime, to: toTime, videoPath: filePath, outPathTemplate, captureFormat, quality, filter, onProgress });
|
||||||
|
|
||||||
return firstFileOutPath;
|
return firstFileOutPath;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ export default ({ formatTimecode, treatOutputFileModifiedTimeAsStart }) => {
|
|||||||
// see https://github.com/mifi/lossless-cut/issues/1139
|
// see https://github.com/mifi/lossless-cut/issues/1139
|
||||||
const tmpSuffix = 'llc-tmp-frame-capture-';
|
const tmpSuffix = 'llc-tmp-frame-capture-';
|
||||||
const outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: getSuffix(`${tmpSuffix}%d`) });
|
const outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: getSuffix(`${tmpSuffix}%d`) });
|
||||||
await ffmpegCaptureFrames({ from: fromTime, to: toTime, videoPath: filePath, outPathTemplate, quality, filter, framePts: true, onProgress });
|
await ffmpegCaptureFrames({ from: fromTime, to: toTime, videoPath: filePath, outPathTemplate, captureFormat, quality, filter, framePts: true, onProgress });
|
||||||
|
|
||||||
const outDir = getOutDir(customOutDir, filePath);
|
const outDir = getOutDir(customOutDir, filePath);
|
||||||
const files = await readdir(outDir);
|
const files = await readdir(outDir);
|
||||||
|
Loading…
Reference in New Issue
Block a user