|
|
|
|
@ -2,6 +2,8 @@ import strongDataUri from 'strong-data-uri';
|
|
|
|
|
|
|
|
|
|
import { formatDuration, getOutPath, transferTimestampsWithOffset } from './util';
|
|
|
|
|
|
|
|
|
|
import { captureFrame as ffmpegCaptureFrame } from './ffmpeg';
|
|
|
|
|
|
|
|
|
|
const fs = window.require('fs-extra');
|
|
|
|
|
const mime = window.require('mime-types');
|
|
|
|
|
|
|
|
|
|
@ -17,7 +19,21 @@ function getFrameFromVideo(video, format) {
|
|
|
|
|
return strongDataUri.decode(dataUri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function captureFrame(customOutDir, filePath, video, currentTime, captureFormat) {
|
|
|
|
|
async function transferTimestamps({ duration, currentTime, fromPath, toPath }) {
|
|
|
|
|
const offset = -duration + currentTime;
|
|
|
|
|
await transferTimestampsWithOffset(fromPath, toPath, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function captureFrameFfmpeg({ customOutDir, videoPath, currentTime, captureFormat, duration }) {
|
|
|
|
|
const time = formatDuration({ seconds: currentTime, fileNameFriendly: true });
|
|
|
|
|
|
|
|
|
|
const outPath = getOutPath(customOutDir, videoPath, `${time}.${captureFormat}`);
|
|
|
|
|
await ffmpegCaptureFrame({ timestamp: currentTime, videoPath, outPath });
|
|
|
|
|
await transferTimestamps({ duration, currentTime, fromPath: videoPath, toPath: outPath });
|
|
|
|
|
return outPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function captureFrameFromTag({ customOutDir, filePath, video, currentTime, captureFormat }) {
|
|
|
|
|
const buf = getFrameFromVideo(video, captureFormat);
|
|
|
|
|
|
|
|
|
|
const ext = mime.extension(buf.mimetype);
|
|
|
|
|
@ -25,7 +41,7 @@ export default async function captureFrame(customOutDir, filePath, video, curren
|
|
|
|
|
|
|
|
|
|
const outPath = getOutPath(customOutDir, filePath, `${time}.${ext}`);
|
|
|
|
|
await fs.writeFile(outPath, buf);
|
|
|
|
|
const offset = -video.duration + currentTime;
|
|
|
|
|
await transferTimestampsWithOffset(filePath, outPath, offset);
|
|
|
|
|
|
|
|
|
|
await transferTimestamps({ duration: video.duration, currentTime, fromPath: filePath, toPath: outPath });
|
|
|
|
|
return outPath;
|
|
|
|
|
}
|
|
|
|
|
|