Skip to content

The swiss army knife of lossless video/audio editing

Offset modified date to respect the frame offset (#55)

Erik Fonselius8b54a7cc2d8c
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,
};