ffmpeg Add audio (wav) to video (mp4) without reencoding video

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

John Smith

Posted 2019-09-27T14:00:43.130

Reputation: 1

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 – 2019-09-27T14:30:15.067

Sorry for being unclear I meant mix the two audio streams. – John Smith – 2019-09-27T14:34:45.057

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 – 2019-09-27T16:16:56.133

Thanks K7AAY, apologies I'm a little new to stackexchange – John Smith – 2019-09-28T14:51:42.953

Answers

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

John Smith

Posted 2019-09-27T14:00:43.130

Reputation: 1