So I am trying to combine a mp3 file and png with nodejs to make a mp4 file. I tried searching for modules and such, but cannot find one.
CodePudding user response:
I do recommend using ffmpeg, by using this npm package https://www.npmjs.com/package/ffmpeg.
I think this answer would help you creating mp4 from png images and audio How to create a video from images with FFmpeg?
CodePudding user response:
You can use the fluent-ffmpeg
package:
For example of how ot work, here is an example of resizing a mp4:
var ffmpeg = require( 'fluent-ffmpeg' );
ffmpeg( path.join( toDirectory, newVideo._id '.orig.mp4' ) )
.size( '1024x576' )
.fps( 25 )
.videoCodec( 'libx264' )
.videoBitrate( '1024k' )
.output( path.join( toDirectory, newVideo._id '.mp4' ) )
.audioBitrate( '92k' )
.audioFrequency( 48000 )
.audioChannels( 2 )
.run();
For creating a mp4 from image with sound (Not tested):
var ffmpeg = require( 'fluent-ffmpeg' );
let newMp4 = ffmpeg();
newMp4
.input("./test.png")
.input("./another.png")
.addInput('/path/to/audio.file')
.save("./test.mp4")
.outputFPS(1) // Control FPS
.frames(2) // Control frame number
.on('end', () => {
console.log("done");
});