audiovideoffmpeg

How to add a new audio (not mixing) into a video using ffmpeg?


I used a command like:

ffmpeg -i video.avi -i audio.mp3 -vcodec codec -acodec codec output_video.avi -newaudio

in latest version for adding new audio track to video (not mix).

But I updated the ffmpeg to the newest version (ffmpeg version git-2012-06-16-809d71d) and now in this version the parameter -newaudio doesn't work.

Tell me please how I can add new audio to my video (not mix) using ffmpeg.


Solution

  • Replace audio

    diagram of audio stream replacement

    ffmpeg -i video.mp4 -i audio.wav -map 0:v -map 1:a -c:v copy -shortest output.mp4
    

    Add audio

    diagram of audio stream addition

    ffmpeg -i video.mkv -i audio.mp3 -map 0 -map 1:a -c:v copy -shortest output.mkv
    

    Mixing/combining two audio inputs into one

    diagram of audio downmix

    Use video from video.mkv. Mix audio from video.mkv and audio.m4a using the amerge filter:

    ffmpeg -i video.mkv -i audio.m4a -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest output.mkv
    

    See FFmpeg Wiki: Audio Channels for more info.

    Generate silent audio

    You can use the anullsrc filter to make a silent audio stream. The filter allows you to choose the desired channel layout (mono, stereo, 5.1, etc) and the sample rate.

    ffmpeg -i video.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
    -c:v copy -shortest output.mp4
    

    Also see