How can you create a video from given images in Node.js?
I tried using the ffmpeg
npm module but it won't work for me, and I also tried using the videoshow
npm module and that also did not work for me.
Can anyone suggest how to create video from images and also give me some basic code to run?
Using ffmpeg directly is challenging and I don't recommend it. Instead, I do recommend the videoshow npm that you reference. It too can be tricky, but after plenty of fiddling, I was able to get videoshow working within our project nicely.
Here is my code (just fill in your own paths and it should work)
var videoshow = require('videoshow')
var secondsToShowEachImage = 1
var finalVideoPath = '/whatever_path_works_for_you'
// setup videoshow options
var videoOptions = {
fps: 24,
transition: false,
videoBitrate: 1024 ,
videoCodec: 'libx264',
size: '640x640',
outputOptions: ['-pix_fmt yuv420p'],
format: 'mp4'
}
// array of images to make the 'videoshow' from
var images = [
{path: path1, loop: secondsToShowEachImage},
{path: path2, loop: secondsToShowEachImage},
...etc
]
videoshow(images, videoOptions)
.save(finalVideoPath)
.on('start', function (command) {
console.log('encoding ' + finalVideoPath + ' with command ' + command)
})
.on('error', function (err, stdout, stderr) {
return Promise.reject(new Error(err))
})
.on('end', function (output) {
// do stuff here when done
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With