I am a first-time ffmpeg user trying to mux h.264 .mp4 video with separate/secondary .wav audio, without re-encoding anything on the video side. Would like the final audio to come out as .aac (same codec as the audio on the h.264 file).

Essentially, I just want to layer an additional audio track (commentary) of equivalent length onto the video. I'm trying to get around Premiere's inability to import h.264 properly by editing the .wav audio separately and combining it with the original file without ever running it through Premiere or any editor. This program seems to be the best way to do it quickly.

I would be doing this in batches, so any suggestions on how to queue up multiple jobs would be appreciated. Only queuing advice I've found used Linux code.

If you have the time to answer, explain it like I'm 5, please. I am an experienced user, but totally new to this command-line-oriented way of working with content. Not sure I'm doing anything right.

Also: I'm using Windows.

1 Answer 1


The basic FFmpeg command line for your required use is

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

-map 0 means include all streams from the first input - FFmpeg index starts from zero. Similarly, map 1:a means include all audio streams from the 2nd input. -map 1 would have sufficed since WAV files contain only audio streams.

-c:v copy means that any and all video streams being included in the output should be copied, so no re-encoding.

-c:a:0 copy means the first audio stream in the output should be copied as well. The order of output streams here is decided by the order of the map arguments. Since -map 0 is placed first, the audio and video streams from that file will be stacked first in the output. So, the first audio stream in the output will be the one from the first input i.e. video.mp4

-c:a:1 aac means encode the second audio stream in the output with the (native) AAC encoder.

On Windows, you can use the Avanti GUI front-end to carry out batch operations. Read the link for setup instructions - pretty straightforward.

Your main GUI window settings should look like this:

enter image description here

After you perform a single job from the main window, you can load the Job Control Manager, available from the drop-down menu when you click on the top-left icon.

That should look like this:

Avanti Job Manager

For each corresponding video/audio pair you add, make sure to unmark the audio file so that Avanti knows it's part of the same job as the video entry above it. Select your destination path (4th icon at top from left) to be different than the folder containing your source files. Avanti will the name the output file the same as the first input (the video) so you'll be in for a nasty surprise if you don't take care of this.

That pretty much covers it.

  • This is SO helpful. Thanks for the link to Avanti; if this ends up working, the GUI will make streamlining my workflow so much more straightforward. Where I am still having an issue is that I need the original audio to be preserved so that the commentary track I'm layering in plays alongside it. So far, whether using this GUI or simple command line prompts before I posted this... I have been unable to accomplish this.
    – Hadrian
    Jul 27, 2016 at 23:52
  • Then the source audio needs to be merged with the commentary. The command would be ffmpeg -i video.mp4 -i audio.wav -filter_complex "[0:a][1]amix[a]" -map 0:v -map "[a]" -c:v copy -c:a aac video-new.mp4
    – Gyan
    Jul 28, 2016 at 4:35
  • That worked perfectly with the test files! If it works with my full-length videos, you've just saved me so much time. Thank you so much!
    – Hadrian
    Jul 28, 2016 at 16:16
  • Just wanted to say thanks again for your help. Your exact directions perfectly accomplish what I needed and I will be using this for the foreseeable future in all of my content. Thank you SO much.
    – Hadrian
    Aug 12, 2016 at 19:14
  • Hi Mulvya. I'm seeking your wisdom, hopefully for the last time. Really tried to find a solution before coming back to this thread.I've been successfully using this technique for a few months, but have noticed that, in some cases, I get the following error: "Input buffer exhausted before END element found." When this error happens, it offsets my commentary by milliseconds. When it happens multiple times, it noticeably offsets the commentary to each video. Any idea how to prevent this from happening in avanti?
    – Hadrian
    Sep 11, 2016 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .