7

I have an mp4 video file created from images and would like to add mp3 sound to it. I am not familiar with video editing at all, but read somewhwere that aac sound is preferred, so I got sound in aac form as well.

The preferred form of the result is also mp4 or flv. My Operating System is Ubuntu (Saucy Salamander).

I have Googled a lot for avconv and mencoder trying to transform the found examples to my case without any success.

Will you be kind enough any of you, experts, to drop me a command line example how can I do it?

14

It depends a bit how your streams are mapped within the mp4 file. Something like this should work:

ffmpeg -i video.mp4 -i audio.aac -map 0:0 -map 1:0 -vcodec copy -acodec copy newvideo.mp4

Usually the videostream is mapped as first stream in the container.
If it isn't mapped as first stream, change the mapping:

ffmpeg -i video.mp4 -i audio.aac -map 0:1 -map 1:0 -vcodec copy -acodec copy newvideo.mp4

To find out how the streams in your video file actually were mapped in the first place you can use mediainfo which is in the standard Ubuntu repositories nowadays.

If we break down the commandline here it works like this:

-i video.mp4  -> first media file
-i audio.aac  -> second media file
-map 0:1      -> use the second stream from the first mediafile
-map 1:0      -> use the first stream from the second mediafile
-vcodec copy  -> leave the video as is
-acodec copy  -> leave the audio as is
newvideo      -> resulting videofile

Make sure that the audiofile and the videofile have the same duration. Not every player is accepting tracks with huge duration differences.

Please be aware that avconv and ffmpeg are almost the same thing. In fact, this command using avconv also works like the same command using ffmpeg:

avconv -i video.mp4 -i audio.aac -map 0:0 -map 1:0 -vcodec copy -acodec copy newvideo.mp4  

avconv program belongs to the Libav project, a fork from the FFmpeg project. You also can safely ignore the following error message:

*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

An alternative for muxing files in MP4 format is MP4Box from the gpac package.

  • Thank you for the fast reply. However none of the commands resulted audible sound with totem. – user2469202 Nov 2 '13 at 16:11
  • I tested the commands before I committed my answer to make sure that it would work. Therefore I suspect the problem must be something else. Could you please check your inputfiles and outputfile in totem and in mediainfo ? Also if you did got any error messages would you be so kind to post them ? – thom Nov 2 '13 at 16:19
  • I am sure the error is at me and I am very graceful for helping me. I have tried copy here the outputs, but tthose are too large so i put there: evoran.hu/tmp/mediainfo - And thanks agaig for your help. – user2469202 Nov 2 '13 at 16:29
  • Yes, I see you have issued both ffmpeg commands. The first command worked and gave you the valid file. The second command had the mapping wrong and gave you a file without sound and, of course, did overwrite the first file. So please just invoke the first command and forget about the second at the moment. – thom Nov 2 '13 at 17:13
  • Unfortunately it was not overwritten. After the 1st attempt I have started totem to check the result. What is strange, the newvideo.mp4 is reported by mediainfo as an mp4 containing aac audio. However totem plays no sound. Here is the resulted mp4: evoran.hu/tmp/newvideo.mp4 (Rather large, 39 MB) – user2469202 Nov 2 '13 at 17:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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