Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have got two video files: .mp4, with a single (incorrect) audiostream, and an .mkv, with two audio streams (one incorrect, the other correct)

Is there a way to replace the audio of the .mp4 file with the second stream in the .mkv?


share|improve this question

2 Answers 2

You'd need to extract the audio from the MKV first and then combine remux the MP4 with the new track. Something like this should work:

ffmpeg -i vid.mkv -acodec copy -vn audio.ext
ffmpeg -i vid.mp4 -i audio.ext -vcodec copy -acodec copy -map 0:1 -map 1:0 final.mp4
share|improve this answer
Hey, I extracted the audio properly using ffmpeg -i vid.mkv -map 0:2 -ac 2 aud.wav but still can't merge it with the mp4 file for some reason... – CookieMonster Aug 11 '11 at 11:37

Sure, with avconv (same as ffmpeg)


avconv -i INPUT_FILE_WITH_BROKEN_SOUND.mp4 -i SECOND_INPUT_FILE.mkv -c copy -map 0:v:0 -map 1:a:1 OUTPUT.mp4

-c copy copies tracks instead of re-encoding them

-map 0:v:0 selects track to be copies to output: 1st file -> video tracks -> 1st video track

-map 1:a:1 selects track to be copies to output: 2st file -> audio tracks -> 2st audio track

Hope it helps!

share|improve this answer
Could down-voter tell why it is wrong? – Pisek Oct 20 at 11:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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