Monday, March 15, 2010

ffmpeg & audacity - 5.1 audio to 2.0

There is a feature that is not implemented (yet) in ffmpeg (version 0.5): down-sampling from 5.1 audio to 2.0, that is from surround sound to stereo. When you try it, you get the following error message:

Resampling with input channels greater than 2 unsupported.
Can not resample 6 channels @ 48000 Hz to 2 channels @ 48000 Hz
Which is quite clear.

Apparently, it will be necessary to have a 2 channels audio file as input. This is where Audacity will help us to bypass that problem. Suppose we have a movie file named 'original.ogg' format that embedding a movie stream and a six channels audio stream.

First we have to extract the audio stream from our file with the following command :

ffmpeg -i original.ogg -vn -acodec copy audio5.1.ogg
The '-vn' option switch means that the video stream is ignored and '-acodec copy' means that the encoding will be the same as the input file.

Now we can editing the 'audio5.1.ogg' using Audacity. We can see the six tracks In the editor. According to the vorbis spec, these tracks are ordered with respect to the speaker locations as follow:

  1. front left
  2. center
  3. front right
  4. rear left
  5. rear right
  6. LFE

To have a stereo audio, we have to merge those six tracks to two tracks, actually named left and right (a bit obvious =) ). We can drop the LFE (Low Frequency Effect) track, since this one is a bit useless for a stereo system. Indeed, we have to duplicate the center track, this one is often used for the voices. So it has to be present in both left and right track. That far we have six tracks. We have to merge them by selecting (shift + click) some of them using the Mix and Render command from the Tracks menu. The front left, rear left and center will be merge into the left track, and front right, rear right and center will be merged into the right track.

We end up with two tracks. We still have two set their property: "Left Channel" for the first track and "Right Channel" for the second track. Export the project to audio2.0.ogg, and we have our stereo audio file.

What is left now is to combine this stereo file with the movie file and encode them into a divx file. Here is the command:

ffmpeg -i original.ogg -i audio2.0.ogg -map 0.0:0 -map 1.0:1 \
-vcodec mpeg4 -vtag DIVX -vb 800kb \
-acodec mp2 -ar 44100 -ab 128kb converted.avi

The '-map' options are used to indicate that we are ignoring the audio stream for the first file and that instead we are using the audio stream from the second file. The '-vtag DIVX' is an option to force the file being tagged as divx. Here we are, we have our 5.1 movie convert to a 2.0 one.

Hope that help.

No comments:

Post a Comment