Archive

Problem
You have a video with an audio track (call it video.mp4). You have an audio file (e.g. audio.mp3) that you want to put on the video, replacing the original audio of the video file.

Solution
With Audacity, you can open both video.mp4 and audio.mp3 and you can synchronize the mp3 to match the original audio. Important points: speech/music should start at the same time, and its length should be the same or a little bit less than the original audio.

Once you have a good audio.mp3 file, do the replacement with the following command:

ffmpeg -i audio.mp3 -i video.mp4 -c copy final_video.mp4

Solution #2
Before the previous solution, I used Avidemux, but it tends to crash sometimes :) When I have such videos where Avidemux crashes, I use ffmpeg from the command-line.

Problem
There are some great audio codecs for FFmpeg which are open source but not completely compatible with GPL, thus they are not included in the FFmpeg package that you can install from the official repositories.

Solution
If you want these codecs, you must compile your own FFmpeg.

Here you can find a nice description of the available audio codecs. Which one should you use? In short, they come in this order: libfdk_aac > libfaac > Native FFmpeg AAC ≥ libvo_aacenc, i.e. libfdk_aac provides the best quality.

You can download static builds from here but they don’t include libfdk_aac and libfaac either :(

Compiling FFmpeg
Fortunately, compiling FFmpeg under Ubuntu is quite easy. You just need to follow this guide.

I have an installer script for Ubuntu called jabbatron. The new version of this script includes (1) compiling FFmpeg, and (2) updating FFmpeg. They are available under the menu point “(170) install from source (mc, tesseract3, ffmpeg)…”. This script automates all the steps that are described in the aforementioned guide.

Problem
You have an Android/iOS phone and you want to watch movies on it. However, if you transfer a movie to the phone, the media player may stop playing it or it may even freeze. Apparently, the movie is too big for your phone. What to do?

Solution
If the media player has problems playing the movie, then it’s too big, thus you should resize it. Then the phone will be able to play it nicely.

Under Windows there is a nice video converter called AVS Video Converter. But if we are under Linux, what can we do?

Well, ffmpeg can do the job for us. But the question is: how to parameterize ffmpeg? :) Here it is:

I like to see how much time the conversion takes, that’s why I added the “time” command.

Another advantage of this approach is that you can launch the conversion in batch mode. Say you want to convert all the episodes of your favorite TV show. No problem, just write a little script.

ffmpeg
I use Ubuntu and it comes with an old ffmpeg that fails for instance with the parameters above. So I downloaded a static ffmpeg build from http://ffmpeg.gusari.org/static/. FFmpeg exists under Windows too, so the method presented above should work on Windows (though I didn’t try it).