Created
May 11, 2023 05:19
-
-
Save mcnaveen/249c6bbddbfeea92f88ca55b7b19a3f4 to your computer and use it in GitHub Desktop.
Creating Videos Programatically using Nodejs and FFMpeg
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 { spawn } = require("child_process"); | |
const outputFile = "output.mp4"; | |
const duration = 4; // Duration in seconds | |
const inputImage = "photo.jpg"; | |
const outputDimensions = "1080:1920"; // Output video dimensions | |
const ffmpegCommand = `ffmpeg -loop 1 -t ${duration} -i ${inputImage} -i ${inputImage} -filter_complex "[0:v]scale=${outputDimensions},setsar=1:1[bg];[bg]boxblur=5:2[bg];[bg][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -c:v libx264 -preset superfast -pix_fmt yuv420p -t ${duration} ${outputFile}`; | |
const ffmpegProcess = spawn(ffmpegCommand, { shell: true }); | |
ffmpegProcess.on("error", (error) => { | |
console.error("Error creating video:", error); | |
}); | |
ffmpegProcess.on("exit", (code, signal) => { | |
if (code === 0) { | |
console.log("Video created successfully."); | |
} else { | |
console.error( | |
`FFmpeg process exited with code ${code} and signal ${signal}` | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment