Created
March 8, 2018 23:41
-
-
Save jonathanmv/b79976f713bad4810833d8644efefb5a to your computer and use it in GitHub Desktop.
Take a screenshot of a webpage. Make a video from a single image and single audio
This file contains 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 webshot = require('webshot') | |
const util = require('util') | |
const exec = util.promisify(require('child_process').exec) | |
const screenshot = (url, file) => new Promise((resolve, reject) => { | |
const screenSize = { width: 1920, height: 1080 } | |
webshot(url, file, { screenSize }, error => { | |
if (error) { | |
return reject(error) | |
} | |
resolve(file) | |
}) | |
}) | |
const takeScreenshot = url => { | |
const fileName = './images/' + new Date().getTime() + '.png' | |
return screenshot(url, fileName).then(() => fileName) | |
} | |
const createVideo = (image, audio) => { | |
const fileName = './videos/' + new Date().getTime() + '.mp4' | |
const command = [ | |
'ffmpeg -loop 1 -i ', | |
image, | |
' -i ', | |
audio, | |
' -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest ', | |
fileName | |
].join('') | |
return exec(command).then(() => fileName) | |
} | |
module.exports = { | |
takeScreenshot, | |
createVideo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment