Skip to content

Instantly share code, notes, and snippets.

@meetAhmed
Last active August 31, 2019 17:22
Show Gist options
  • Save meetAhmed/1cf8a0014a2155e1bf2040fe95b4f394 to your computer and use it in GitHub Desktop.
Save meetAhmed/1cf8a0014a2155e1bf2040fe95b4f394 to your computer and use it in GitHub Desktop.
Demo

Demo : Create two folders curr and frames in current directory where all these files will be saved. Add 8 images to frames folder with name sequence

Add audio. Currently it only loads local file. Later it can be made to select user choice file.


f_1.jpg
f_2.jpg
f_3.jpg
f_4.jpg
f_5.jpg
f_6.jpg
f_7.jpg
f_8.jpg

Images must be all jpg. Images can be any random pictures.
This code was taken from the series https://gist.github.com/cliffhall/09af8ba728659a3fc81ba21d16c9a6d1
var command;
const fs = require('fs');
function some(){
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
var ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
command = ffmpeg();
createVideo(command);
}
function createFrames(length){
var counter = 1;
for(var i=0;i<length;i++){
var file = "f_"+counter+".jpg";
var c = __dirname+"/frames/" + file;
var newFile = "f_"+(i+1)+".jpg";
doFile(c,__dirname + "/curr/" + newFile);
if(counter == 8){
counter = 1;
}else{
counter++;
}
}
}
function doFile(c,s){
fs.readFile(c, function (err, data) {
if (err) throw err;
fs.writeFileSync(s, data, function (err) {
if (err) throw err;
});
});
}
function createVideo(command) {
command
.on('end', onEnd )
.on('progress', onProgress)
.on('error', onError)
.input(__dirname+'/curr/f_%1d.jpg')
.inputFPS(1/1)
.input(__dirname+"/Awari.mp3")
.output(__dirname+"/test.mp4")
.run();
}
function onProgress(progress){
timemark = progress.timemark;
console.log('Time : ' + timemark);
}
function onError(err, stdout, stderr) {
console.log(err);
}
function onEnd() {
console.log("ended");
}
//createFrames(320);
some();
{
"name": "audiotovideo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.19",
"async": "^3.1.0",
"express": "^4.17.1",
"fluent-ffmpeg": "^2.1.2",
"nodemon": "^1.19.1",
"save": "^2.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment