'How to convert gif in mp4 video with Nodejs?
Is there a way to convert a .gif uploaded image into .mp4 with only Nodejs? How do I integrate that with a MEAN app? I want to be able to store the converted .mp4 file to S3.
Using : https://www.npmjs.com/package/fluent-ffmpeg-extended but get error : Invalid Input
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'mybucket',
key: function (req, file, cb) {
var extension = file.originalname.substring(file.originalname.lastIndexOf('.')+1).toLowerCase();
if(extension == "gif"){
console.log(file);
var proc = new ffmpeg({ source: file })
.usingPreset('podcast')
.saveToFile('/path/to/your_target.m4v', function(stdout, stderr) {
console.log('file has been converted succesfully');
});
}
else{
cb(null, file.originalname);
}
}
})
});
Many thanks.
Solution 1:[1]
you can use this library. it's a wrapper for ffmpeg executable, so you'll need to have it as well.
https://www.npmjs.com/package/fluent-ffmpeg-extended
This thread will be helpful as well,
Solution 2:[2]
var ffmpeg = require('ffmpeg');
var ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
var ffprobePath = require('@ffprobe-installer/ffprobe').path;
var ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);
export let UPLOAD_PATH = 'public';
// video : any live video url or any video path from your local storage
public createGif (video, fileName){
ffmpeg(video)
.setStartTime('00:00:03')
.setDuration('10')
.output(`${UPLOAD_PATH}/${fileName}`)
.on('end', function(err) {
if(!err) { console.log('conversion Done') }
})
.on('error', function(err){
console.log('error: ', err)
}).run()
}
You can use "ffmpeg" npm package to convert video to gif complete code written over here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kalana Demel |
| Solution 2 | vishal sharma |
