diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-07 13:14:16 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-07 13:14:16 +0100 |
commit | 6f9278fe81c55978feca8e073618898f4433a98c (patch) | |
tree | 0dcad01f6885ba387bcfa596d85ba47001e64e94 /init.js | |
download | badapple-6f9278fe81c55978feca8e073618898f4433a98c.tar.xz |
Diffstat (limited to 'init.js')
-rw-r--r-- | init.js | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +const fs = require("fs").promises +const seurat = require("seurat") +const ffmpegExtractFrames = require("ffmpeg-extract-frames") +const imageSize = require("image-size") + +const fps = 1.0 +const limit = 2000 +const url = "https://www.youtube.com/watch?v=9lNZ_Rnr7Jc" + +fs.rm("frames", {recursive: true, force: true}) + .then(_ => fs.mkdir("frames")) + .then(_ => ffmpegExtractFrames({ + input: "bad_apple.mkv", + output: "frames/%5d.png", + fps + })) + .then(_ => fs.readdir("frames")) + .then(files => { + const dimensions = imageSize("frames/00001.png") + const ratio = dimensions.width / dimensions.height + const size = Math.sqrt(limit) + + return Promise.all(files.map(file => + seurat.convert("frames/" + file, { + width: Math.floor(size * ratio), + height: Math.floor(size / ratio), + threshold: 25, + }))) + }) + .then(frames => fs.writeFile("badapple.json", JSON.stringify({fps, frames}))) +/**/ |