ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
13.47k stars 776 forks source link

add audio to video with FFMPEG bug #664

Open jesseice opened 6 months ago

jesseice commented 6 months ago

ffmpeg.exec(['-i', 'test.mp4', '-i', 'bgm.mp3', 'test1.mp4']);

报错: [stderr msg] ---> [libx264 @ 0xe31190] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

tini2n commented 5 months ago

more details? ¯_(ツ)_/¯

jonahsebright commented 4 months ago

It worked for me like this:

import { FFmpeg } from '@ffmpeg/ffmpeg'
import { FileData } from '@ffmpeg/ffmpeg/dist/esm/types'
import { fetchFile } from '@ffmpeg/util'

export const mergeVideoAndAudio = async (
    video: string | File | Blob | undefined,
    audio: string | File | Blob | undefined,
): Promise<FileData> => {
    let ffmpeg = new FFmpeg()
    await ffmpeg.load()
    ffmpeg.writeFile('video.mp4', await fetchFile(video))
    ffmpeg.writeFile('audio.mp4', await fetchFile(audio))
    await ffmpeg.exec([
        '-i',
        'video.mp4',
        '-i',
        'audio.mp4',
        '-c',
        'copy',
        'output.mp4',
    ])
    return await ffmpeg.readFile('output.mp4')
}