Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a MP4/h.264-video with no sound. With ffmpeg or similar, how can I apply an audio track to that MP4-file without degrading the quality of the video (i.e. without recoding the video-track)?

I'd prefer solutions involving free software, available for either Win7, Ubuntu or FreeBSD.

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

The correct FFmpeg command is:

ffmpeg -i video.mp4 -i audio.mp4 -map 0:0 -map 1:0 -c copy output.mp4

This will supply two input streams, the video you already have and the audio, e.g. from an MP4 file with AAC audio, and merge them together using the -map options.

Here, the first number in 0:0 is the input file (0 for the video file and 1 for the audio file), and the second number is the stream from that file (0 since there's only one stream each, video or audio). The two streams will be mapped to the one output file, so first video, then audio.

The bitstreams will be copied and not re-encoded using the -c copy option. You can observe this in the FFmpeg output:

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
share|improve this answer
    
Sweet! Especially nice that you explained the arguments and the usage of the mapping. –  poplitea Nov 30 '12 at 17:20
4  
Also you may want -shortest if you want it only to be the duration of the shortest input (helpful if the audio is music that is longer than the video). –  mark4o Nov 30 '12 at 17:34
add comment

You can use ffmpeg to accomplish that. I'm just doing it from the back of my weakened brain but maybe something like this would work:

ffmpeg -i movie-file.mp4 -i audio-file.mp3 -c:v copy -c:a copy output.mp4
share|improve this answer
    
This is what I'm looking for. Although I've used ffmpeg before, I can't remember its arguments. I suppose they have to do with codec/format, but what do -v:c, -a:c and -an stand for? –  poplitea Nov 30 '12 at 17:14
2  
The options should be -c:v and -c:a, not -v:c and -a:c. Also, with -an you disable audio output, so the result file will have no audio again. If you merge files, you will have to map them explicitly unless FFmpeg can guess what you want (e.g. merging AVI video + WAV audio) /cc @poplitea –  slhck Nov 30 '12 at 17:17
    
Ooops - got those switched in my brain. Nice to learn something new about the mapping. Thanks. –  thornomad Nov 30 '12 at 18:10
add comment

There are a few open source video editors.

On windows there's Windows movie maker or microsoft live movie maker. I don't have experience qith these though.

On linux there's OpenShot which is quite easy to use.

share|improve this answer
    
The problem with nonlinear editors is that they won't allow you to do a bitstream copy very easily. If you could show an example of how to do that, it'd be very helpful though – I'm not sure it's doable. –  slhck Nov 30 '12 at 21:47
    
You import your video file and your audio file. Then you simply drag it to the bottom (the timeline). You do the same with your audio file. Then you export your project, selecting the settings you desire. you may preview it before exporting. Not sure if this is what you ask. –  To Do Dec 1 '12 at 22:13
    
What I mean is, when you export the project, most editors will re-encode the video and audio streams (based on the export settings, e.g. to some h.264 / AAC). They won't however copy the bitstream as-is. Re-encoding makes the quality worse, and the OP wanted to do a bitstream copy. Do you know any editors that do this, or can Windows Movie Maker / OpenShot do it? –  slhck Dec 1 '12 at 22:25
    
I used pitivi on Ubuntu which had a "direc" output option for both video and audio. I think that this simply copies the original format because the encoding was over much quicker than with the normal settings. Said that Pitivi was very unstable, at least back then (1 year ago). –  To Do Dec 2 '12 at 13:56
add comment

Your Answer

 
discard

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.