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.

Wednesday, March 3, 2010

Tablet M-ThinLine, wizardpen driver on Debian

I have a M-ThinLine pen tablet and I wanted to use it under my favorite OS, Debian. I summarize here what I did to make it work.

Apparently there is no driver package (yet?) for this tablet in the official Debian repositories. After a long search over the internet, where there are a myriads of installation tutorials but for Ubuntu, I found this project page which look like the most recent driver according to the version. There is a deb package available but unfortunately it has dependencies with some Ubuntu packages. But the driver sources are there.

After downloading the file 'wizardpen-0.7.0-alpha2.tar.gz', within the archive you will find enough information in the 'INSTALL' file to compile and install the driver. There is an another file 'README-XOrgConfig' for configuring the X-server so it recognizes the tablet. I followed the "HAL-based hotplugging" configuration, but this one did not work for me. So I edited the 'xorg.conf' file, which is a more straightforward way I think.

In the ServerLayout section , you have to add the line [InputDevice "WizardPen Tablet" "AlwaysCore"], so this section should look like this:

Section "ServerLayout"
Identifier     "Layout0"
Screen      0  "Screen0" 0 0
InputDevice    "Keyboard0" "CoreKeyboard"
InputDevice    "Mouse0" "CorePointer"
InputDevice    "WizardPen Tablet" "AlwaysCore"
EndSection

And you have to create a new InputDevice section:

Section "InputDevice"
Identifier      "WizardPen Tablet"
Option          "SendCoreEvents"        "true"
Driver          "wizardpen"
Option          "Name"          "UC-LOGIC Tablet WP5540U"
Option          "Device"        "/dev/input/by-id/usb-UC-LOGIC_Tablet_WP5540U-event-mouse"
Option          "TopX"          "2262"
Option          "TopY"          "3794"
Option          "BottomX"       "30363"
Option          "BottomY"       "30265"
Option          "MaxX"          "30363"
Option          "MaxY"          "30265"
Option          "TopZ"          "0"
Option          "BottomZ"       "1024"
EndSection

You can obtain the name by typing 'grep -i name /proc/bus/input/devices'. The TopX/Y and BottomX/Y can be obtained by running the calibration tool 'wizardpen-calibrate', which is located in the 'calibrate' directory. In order to enable the pen pressure, you have to add the TopZ and BottomZ option, the current value correspond to the maximum range but you can tweak it at will.

Happy pen tablet installation!