Last active
February 3, 2018 09:06
-
-
Save bentinata/ab36cc3abd821a87d49d4b1c06ab1b55 to your computer and use it in GitHub Desktop.
Code for https://youtu.be/4doWq-uSa60. Since this is using pipe, use it like `node . > out.mp4`.
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
'use strict'; | |
const { writeFileSync, unlinkSync } = require(`fs`); | |
const ffmpeg = require(`fluent-ffmpeg`); | |
const { stringify } = require(`subtitle`); | |
const syllable = require(`syllable`); | |
const words = ` | |
_l1_Hi _l1_there! | |
My name is _l2_Ben | |
I am a computer science student at _l1_UPI | |
_w1_ | |
I would like to have Developer Student Club on my campus | |
because I think Google brand would motivate people to join | |
and thus provoke an active community | |
_w1_ | |
I believe a good community is a key for improvement | |
and developer club might be a nice way to do it | |
_w1_ | |
I'm familiar with Google services JavaScript and web technology | |
I think that qualify me to be a lead for this club | |
_w1_ | |
Well that's a bit about me | |
_l1_bye! | |
_l3_:) | |
`.split(/\s/).filter(x => !!x); | |
{ | |
let start = 800; | |
const wait = 500; | |
const mult = 50; | |
let subs = []; | |
for (let text of words) { | |
let match = text.match(/_(\D+)(\d+)_(.*)/); | |
let end = start + syllable(text) * 50 + 250; | |
if (match) { | |
switch(match[1]) { | |
case `w`: | |
start += Number(match[2]) * wait; | |
continue; | |
break; | |
case `l`: | |
text = match[3]; | |
end += Number(match[2]) * wait; | |
break; | |
} | |
} | |
subs.push({ | |
start, | |
end, | |
text, | |
}); | |
start = end; | |
} | |
writeFileSync(`subtitle.srt`, stringify(subs)); | |
} | |
ffmpeg(`audio.m4a`) | |
.input(`color=c=EEDDDD:size=1280x500:d=36`) | |
.inputFormat(`lavfi`) | |
.videoFilter(`subtitles=subtitle.srt:force_style='FontSize=128,PrimaryColour=&H00111111,Alignment=10'`) | |
.format(`nut`) | |
.stream(process.stdout) |
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
{ | |
"dependencies": { | |
"fluent-ffmpeg": "^2.1.2", | |
"subtitle": "^1.0.1", | |
"syllable": "^3.0.0" | |
}, | |
"license": "MIT", | |
"author": "Ben N <[email protected]>" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment