-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (51 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const { fetchFile } = FFmpegUtil;
const { FFmpeg } = FFmpegWASM;
let ffmpeg = null
let zip = null
const dir_name = "frames";
function getElementByIdOrDie(id) {
const el = document.getElementById(id);
if (el === null)
throw new Error("Could not find element " + id);
return el;
}
const split = async ({target: {files}}) => {
console.log("Running Split!");
await ffmpeg.load({
coreURL: "../../../core/dist/umd/ffmpeg-core.js",
wasmURL: "../../../core/dist/umd/ffmpeg-core.wasm",
});
const {name} = files[0];
await ffmpeg.writeFile(name, await fetchFile(files[0]));
await ffmpeg.createDir(dir_name);
await ffmpeg.exec([
'-i', name,
'-vf', 'fps=8',
dir_name + '/frame-%03d.png',
]);
const frames = await ffmpeg.listDir(dir_name);
for (let i = 0; i < frames.length; i++) {
if (frames[i].isDir == true)
continue;
const file_path = dir_name + "/" + frames[i].name;
const file = await ffmpeg.readFile(file_path);
zip.file(file_path, new Blob([file.buffer], {type: "image/png"}));
}
zip.generateAsync({type: "blob"}).then((blob) => {
saveAs(blob, dir_name + ".zip");
})
}
window.onload = () => {
console.log("Hello World!")
ffmpeg = new FFmpeg();
ffmpeg.on("log", ({message}) => {
console.log(message);
})
ffmpeg.on("progress", ({progress}) => {
const prog = getElementByIdOrDie("prog");
prog.value = progress;
})
zip = new JSZip();
const el = getElementByIdOrDie("para");
el.addEventListener("change", split)
}