-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
53 lines (47 loc) · 1.12 KB
/
run.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
// Let's try this shit in Node
// ffmpeg -re -i org/video_1.mp4 -an -f matroska - | mplayer -
const { spawn } = require("child_process");
const { readdirSync } = require("fs");
const { extname, join } = require("path");
const { Transform } = require("stream");
const middleMan = new Transform({
transform(chunk, encoding, callback) {
this.push(chunk);
callback();
}
});
// List videos in folder
const folder = join(".", "org");
const files = readdirSync(folder).filter(f => extname(f) === ".mp4");
let curFile = 0;
// Start mplayer
const mplayer = spawn("mplayer", ["-"]);
middleMan.pipe(mplayer.stdin);
// Play a single video
const playNext = () => {
console.log("playing", files[curFile]);
const ffmpeg = spawn("ffmpeg", [
"-re",
"-i",
join(folder, files[curFile]),
"-an",
"-filter_complex",
"scale=480:-1,crop=480:160:0:0",
"-f",
"matroska",
"-"
]);
ffmpeg.stdout.pipe(
middleMan,
{ end: false }
);
ffmpeg.on("close", () => {
playNext();
});
ffmpeg.on("error", e => console.log(e));
curFile++;
if (curFile >= files.length) {
curFile = 0;
}
};
playNext();