Kagami / ffmpeg.js

Port of FFmpeg with Emscripten
Other
3.29k stars 335 forks source link

Merge Mp3 to mp4 #165

Open Hassnain243A opened 3 years ago

Hassnain243A commented 3 years ago

I need to merge mp3 to mp4 in the browser with js. Is there any documentation here for that?

ghost commented 2 years ago
var fs = require('fs')
var ffmpeg = require('ffmpeg.js/ffmpeg-mp4')

const audioPath = './res/433834921.mp3'`
const videoPath = './res/433834921.mp4'
const resultPath = './result/433834921.mp4'

const audioData = new Uint8Array(fs.readFileSync(audioPath))
const videoData = new Uint8Array(fs.readFileSync(videoPath))
// ffmpeg -i input.flv -i input.mp3 -c:v copy -c:a aac -strict experimental output.mp4
const result = ffmpeg({
    MEMFS: [{name: '433834921.mp3', data: audioData}, {name: '433834921.mp4', data: videoData}],
    arguments: ["-i", "433834921.mp3", "-i", "433834921.mp4", "-c:v", "copy", "-c:a", "aac", "-strict", "experimental", "out.mp4"],
})
const out = result.MEMFS[0];
fs.writeFileSync(resultPath, Buffer(out.data))