Created
February 2, 2020 04:15
-
-
Save N0NamedGuy/576174f4c75e0a0f2833dd5a4dc62bab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { spawnSync } = require("child_process"); | |
| const fs = require("fs"); | |
| // TODO: split automatically | |
| // ffprobe -f lavfi -i "movie=./video-in.mkv,blackdetect[out0]" -show_entries tags=lavfi.black_start,lavfi.black_end -of default=nw=1 -v quiet | |
| function processBlacksFile(err, contents) { | |
| const durations = contents.split('\n') | |
| .map((line) => { | |
| const time = parseFloat(line.split('=')[1]); | |
| return { | |
| isStart: line.startsWith('TAG:lavfi.black_end='), | |
| time | |
| } | |
| }) | |
| .filter((line) => line.time) | |
| .reduce((acc, cur, i, arr) => { | |
| if (i % 2 !== 0) { | |
| acc.push({ | |
| start: arr[i - 1].time, | |
| end: cur.time | |
| }) | |
| } | |
| return acc; | |
| }, []); | |
| console.log(durations); | |
| durations.forEach((duration, i) => { | |
| spawnSync('ffmpeg', [ | |
| '-i', 'video-in.mkv', | |
| '-ss', duration.start, | |
| '-to', duration.end, | |
| '-c', 'copy', `part${i}.mkv` | |
| ]) | |
| }); | |
| } | |
| fs.readFile('blacks.txt', 'utf8', processBlacksFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment