merge transferTimestamps and transferTimestampsWithOffset

pull/699/head
Mikael Finstad 5 years ago
parent 8e2c22086e
commit 62f99a5e7e
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -1,6 +1,6 @@
import strongDataUri from 'strong-data-uri';
import { formatDuration, getOutPath, transferTimestampsWithOffset } from './util';
import { formatDuration, getOutPath, transferTimestamps } from './util';
import { captureFrame as ffmpegCaptureFrame } from './ffmpeg';
@ -19,9 +19,9 @@ function getFrameFromVideo(video, format) {
return strongDataUri.decode(dataUri);
}
async function transferTimestamps({ duration, currentTime, fromPath, toPath }) {
async function transferTimestampsWithTime({ duration, currentTime, fromPath, toPath }) {
const offset = -duration + currentTime;
await transferTimestampsWithOffset(fromPath, toPath, offset);
await transferTimestamps(fromPath, toPath, offset);
}
export async function captureFrameFfmpeg({ customOutDir, filePath, currentTime, captureFormat, duration }) {
@ -29,7 +29,7 @@ export async function captureFrameFfmpeg({ customOutDir, filePath, currentTime,
const outPath = getOutPath(customOutDir, filePath, `${time}.${captureFormat}`);
await ffmpegCaptureFrame({ timestamp: currentTime, videoPath: filePath, outPath });
await transferTimestamps({ duration, currentTime, fromPath: filePath, toPath: outPath });
await transferTimestampsWithTime({ duration, currentTime, fromPath: filePath, toPath: outPath });
return outPath;
}
@ -42,6 +42,6 @@ export async function captureFrameFromTag({ customOutDir, filePath, currentTime,
const outPath = getOutPath(customOutDir, filePath, `${time}.${ext}`);
await fs.writeFile(outPath, buf);
await transferTimestamps({ duration, currentTime, fromPath: filePath, toPath: outPath });
await transferTimestampsWithTime({ duration, currentTime, fromPath: filePath, toPath: outPath });
return outPath;
}

@ -89,20 +89,10 @@ export async function dirExists(dirPath) {
return (await fs.exists(dirPath)) && (await fs.lstat(dirPath)).isDirectory();
}
export async function transferTimestamps(inPath, outPath) {
export async function transferTimestamps(inPath, outPath, offset = 0) {
try {
const stat = await fs.stat(inPath);
await fs.utimes(outPath, stat.atime.getTime() / 1000, stat.mtime.getTime() / 1000);
} catch (err) {
console.error('Failed to set output file modified time', err);
}
}
export async function transferTimestampsWithOffset(inPath, outPath, offset) {
try {
const stat = await fs.stat(inPath);
const time = (stat.mtime.getTime() / 1000) + offset;
await fs.utimes(outPath, time, time);
const { atime, mtime } = await fs.stat(inPath);
await fs.utimes(outPath, (atime.getTime() / 1000) + offset, (mtime.getTime() / 1000) + offset);
} catch (err) {
console.error('Failed to set output file modified time', err);
}

Loading…
Cancel
Save