I'm trying to create a video file using multiple images using ffmpeg-stream.
Here's my code,
const { Converter } = require("ffmpeg-stream")
const frames = ["open.jpg", "close.jpg", "open.jpg", "close.jpg"]
// create converter
const converter = new Converter()
// create input writable stream (the jpeg frames)
const converterInput = converter.createInputStream({ f: "image2pipe", r: 30 })
// create output to file (mp4 video)
converter.createOutputToFile("out.mp4", {
vcodec: "libx264",
pix_fmt: "yuv420p",
})
// start the converter, save the promise for later
const convertingFinished = converter.run()
// pipe all the frames to the converter sequentially
for (const filename of frames) {
// create a promise for every frame and await it
new Promise((resolve, reject) => {
fs.createReadStream(filename)
.pipe(converterInput, { end: false }) // pipe to converter, but don't end the input yet
.on("end", resolve) // resolve the promise after the frame finishes
.on("error", reject)
})
}
converterInput.end()
Code in the ffmpeg-stream docs, https://github.com/phaux/node-ffmpeg-stream#how-to-create-an-animation-from-a-set-of-image-files
They are using s3, I just changed it to my local file in my code. Everything else is almost same. But when I run it I get the following error,
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error: spawn ffmpeg ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:477:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn ffmpeg',
path: 'ffmpeg',
spawnargs: [
'-f', 'image2pipe',
'-r', '30',
'-i', 'pipe:3',
'-vcodec', 'libx264',
'-pix_fmt', 'yuv420p',
'out.mp4'
]
}
What am I doing wrong :(