Skip to content

Instantly share code, notes, and snippets.

@fabriziogiordano
Created April 18, 2018 12:18
Show Gist options
  • Save fabriziogiordano/37b4d75b95de63f9723806d394cc0b84 to your computer and use it in GitHub Desktop.
Save fabriziogiordano/37b4d75b95de63f9723806d394cc0b84 to your computer and use it in GitHub Desktop.
Extract frames from Video
const imgDiff = require('ffmpeg-image-diff');
const testFolder = './tests/';
const fs = require('fs');
const files = [];
const index_exclude = [];
(async () => {
fs.readdirSync(testFolder).forEach(file => {
files.push(file);
});
for (let i = 0; i < files.length; i++) {
if (index_exclude.includes(i)) {
continue;
}
for (let j = i + 1; j < i + 5; j++) {
const source = testFolder + files[i];
const compare = testFolder + files[j];
if (!fs.existsSync(compare)) {
continue;
}
const diff = await imgDiff(source, compare);
if (diff.All > 0.98) {
console.log('Equal');
fs.unlinkSync(compare);
index_exclude.push(j);
}
}
}
})();
const readFile = (referenceImage, comparisonImage) =>
new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment