Tuesday, June 19, 2007

Ubuntu: Enabling USB audio

The other day, I managed to break my speaker jack plug and get one piece of it stuck in the soundcard's speaker output, thus rendering it useless. My efforts to get this piece out of there led nowhere, so I started thinking of other alternatives and I ended up getting a USB external soundcard.

The cheapest one I could find was this and there was no way that I would look for anything more expensive as there was the risk that it wouldn't work under linux. However the fact that the device supports MacOS-X was an encouraging fact towards portability. A quick research on the internet also revealed that (at least theoretically) all USB audio devices should work fine as they all use the USB protocol, so no special drivers are required.

Indeed enabling USB audio was very straightforward:

  1. I first opened the Sound Preferences (System→Preferences→Sound) and I selected 'USB Audio' where it was available.
  2. Then I double click on the speaker icon on the top right corner, which brings up the Volume Control window, I muted out all tracks for my old sound device and I closed this window.
  3. Finally, I right-clicked on the icon mentioned above, and I selected Preferences. Then I set the device that this icon controls to 'USB Audio', so that mouse scrolling over this icon will control the volume of the USB audio device.

This whole process was enough to get audio playback to work, but getting sound to work while playing movies required a little bit of additional effort. I actually had to manually change the output device on all video players. Here are the steps required for each one of them.

totem-gstreamer
The configuration for totem-gstreamer is handled by a utility called gstreamer-properties. On the Audio< tab, I set the plugin to 'ALSA' and the device to 'USB Audio'.

VLC player
Go to Settings → Preferences → Audio → Output Modules → ALSA and select USB audio: USB audio (hw:1,0) as the device name. Hitting the Refresh button might be required for this option to appear.
This whole process is important because it reveals to us the actual name for the USB audio device (hw:1,0).

mplayer
Preferences → Audio → ALSA → Configure driver
and set the Device to 'hw=1,0'.

xine
First we need to enable advanced configuration options:
Settings → Setup → GUI Configuration Experience Level
and set it to 'Master of the Universe'.
Then, in order to specify the output device, select the Audio tab and set 'hw=1,0' as the value for the fields Device used for mono/stereo... output.

The only thing I still haven't got to work is the Fn+↑ and Fn+↓ combinations, which really bothers me, since this was the main method I used to control the volume.

Update 1:
Actually these combinations suddenly started working, but I can't remember doing something that I hadn't tried before... I believe the important part is to have the correct device selected in the "Select the device and tracks to control with the keyboard" field under the Sound Preferences window, but as it can be seen in the first screenshot, I had the correct option selected right from the beginning.

Update 2:
Another problem that I forgot to mention in the main article, was that I didn't have sound in Flash, which meant that I couldn't use YouTube and all other video sites. I had tried to solve this problem quite a few times before, but I only succeeded today. The only thing I did was to check that the correct device is selected in gstreamer-properties (which I am not absolutely sure if it plays a role after all) and just re-install the Flash plugin.

Sunday, June 17, 2007

Ubuntu: Hot to add subtitles to an AVI file.

All major Linux media players (Totem, mplayer, VLC player) allow you to add subtitles to a movie while watching it. This post describes how you can permanently add the subtitles in an AVI file, which is useful if you want to burn the movie to a video DVD. (Notice however that this technique does not allow you to add more than one subtitle streams to the movie, or disable the subtitles while watching the movie; the subtitles are hard-wired to the movie).

The software package we are going to use is called avidemux and it can be easily installed through aptitude if the universe/multiverse packages are enabled.

The procedure required to add the subtitles is this:

  1. Launch avidemux.
  2. Open the .avi file. With all files I have tried so far, I get these warnings:
    It is best to let avidemux do what it wants to do - it only takes a few seconds.
  3. Select a video encoder from the pull-down menu on the left pane, where it says Video. I believe this can be anything, but it is preferable to choose the same encoder as the one used in the original movie. I normally use Xvid4 and it works just fine.
  4. Configure the encoder by clicking the "Configure" button. In my opinion, no configuration is actually require in order to get an acceptable result. Even one-pass encoding works fine. The only thing that you might want to adjust is the size of the output file.
  5. Add a subtitler filter. First click on the "Filters" button in the left pane (under Video). This brings up the following window:
    Select Subtitles→Subtitler. You can now configure your subtitles using the window shown in the image below.
    This window allows you to select the subtitles file, the encoding (it supports UTF-8, so it works fine with non-latin alphabets), and the font, color, size and position of the subtitles.
  6. It appears that there is no need to select an audio encoder; "COPY" works just fine (since we do not wish to make any changes to the sound). Make sure that the "Format" is set to "AVI". The result can be previewed by clicking on the far right icon and then pressing play.
  7. To finalize the process, click Save and type in a name for the output file. Note that the whole process can take a while. For example in my laptop it took maybe more than an hour to encode a 40min movie file, at an average speed of 16FPS (while doing other stuff as well).

Monday, June 11, 2007

Deploying web applications that use different Java versions.

If you have a Tomcat installation that uses, say, Java 1.4.2, you can only deploy web application that are built with Java <= 1.4.2. If you need to run a Java 5.0 web application, you need to set tomcat to use JRE 5.0 (by setting the JAVA_HOME or JRE_HOME enviroment variables), but this might possibly break older applications that use Java 1.4.2.

Most probably, you'll need to have a separate installation of tomcat, that will use Java 5.0. It is possible to have two or more instances of tomcat running, and these can be either the same version or different versions. However, the two instances need to listen to different ports. The server port is specified in file $CATALINA_HOME/conf/server.xml. I noticed however that in order to get it to work, we need to change all the ports and not just the server port.



This needs cleanup/rewritting

Tuesday, June 5, 2007

Javascript: Button redirect

An eas way to redirect to another page (in the same window) is through the parent.location Javascript variable.
<INPUT TYPE="button" onClick="parent.location='url'">
The URL can be either relative or absolute.
Note: Credit to this site: http://winfolinx.com/tips/howto/redirect/redirbut.htm