0

I was just wondering how to add audio while keeping the pre-existing audio on the video intact: I have done some research and it seems there was a similar question here:

Add audio to video using ffmpeg

So I'm looking at using this code segment taken from slhck:

ffmpeg -i input.mp4 -i input.wav -c:v copy -map 0:v:0 -map 0:a:0 -map 1:a:0 -c:a:0 copy -c:a:1 aac -b:a 192k output.mp4

As slhck said the audio codec wav is incompatible with mp4 so it must be re-encoded, however I just want to make sure the video is not re-encoded, which I think is happening, because ffmpeg is doing the process at 200x speed.

Edit: The only problem is there are two different audio streams and I was thinking if I could have one combined audio stream (mixing the two together).

Edit: With the help of a very generous reddit user I have managed to combine the two streams into one through the amix-filter. And it now works!

ffmpeg -i input.mp4 -i input.wav -filter_complex [0:a:0][1:a:0]amix=inputs=2:duration=longest[aout] -c:v copy -map 0:v:0 -map [aout] -c:a aac -b:a 192k output.mp4
  • Not sure what you mean by one combined stream. You mean you want to mix the two audio streams? Or eliminate the one that comes with the video? – Tom Yan Sep 27 '19 at 14:30
  • Sorry for being unclear I meant mix the two audio streams. – John Smith Sep 27 '19 at 14:34
  • 4
    @John Smith, suggest you turn your last edit above into an answer to show others there's a solution. When you add an answer and later accept it with a checkmark, search here shows an accepted answer with a white-on-blue icon, and folks look for those first. – K7AAY Sep 27 '19 at 16:16
  • Thanks K7AAY, apologies I'm a little new to stackexchange – John Smith Sep 28 '19 at 14:51
0

With the help of a very generous reddit user I have managed to combine the two streams into one through the amix-filter. And it now works!

ffmpeg -i input.mp4 -i input.wav -filter_complex [0:a:0][1:a:0]amix=inputs=2:duration=longest[aout] -c:v copy -map 0:v:0 -map [aout] -c:a aac -b:a 192k output.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.