From 8b54a7cc2d8c9927e042706ab845e0d86ca8270b Mon Sep 17 00:00:00 2001 From: Erik Fonselius Date: Sun, 11 Feb 2018 14:09:01 +0100 Subject: [PATCH] Offset modified date to respect the frame offset (#55) --- src/capture-frame.js | 3 ++- src/util.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/capture-frame.js b/src/capture-frame.js index b6f4dd25..69bd8c62 100644 --- a/src/capture-frame.js +++ b/src/capture-frame.js @@ -27,7 +27,8 @@ async function captureFrame(customOutDir, filePath, video, currentTime, captureF const outPath = util.getOutPath(customOutDir, filePath, `${time}.${ext}`); await fs.writeFileAsync(outPath, buf); - return util.transferTimestamps(filePath, outPath); + const offset = -video.duration + currentTime; + return util.transferTimestampsWithOffset(filePath, outPath, offset); } module.exports = captureFrame; diff --git a/src/util.js b/src/util.js index 800accf4..86d191e3 100644 --- a/src/util.js +++ b/src/util.js @@ -33,8 +33,19 @@ async function transferTimestamps(inPath, outPath) { } } +async function transferTimestampsWithOffset(inPath, outPath, offset) { + try { + const stat = await fs.statAsync(inPath); + const time = (stat.mtime.getTime() / 1000) + offset; + await fs.utimesAsync(outPath, time, time); + } catch (err) { + console.error('Failed to set output file modified time', err); + } +} + module.exports = { formatDuration, getOutPath, transferTimestamps, + transferTimestampsWithOffset, };