April 5, 2007

HOWTO: ALSA line-in capture with MPlayer

Filed under: Blog — krkhan @ 5:34 pm

I had an MSI TV @nywhere Plus card, and although it worked perfectly under Windows, I never got its sound working on my Linux box. The main reason for it was that the TV-Tuner card outputted sound through a separate cable to ALSA-line in. One way of getting around the mess was to launch MPlayer for video, and then capture audio through this separate command:

arecord -D hw:0 -r 44100 -c 2 -f S16_LE | aplay -

The solution wasn’t only ugly per se, but was also quite annoying because of a second’s lag in audio. After some searching in the mailing list archives of MPlayer, I combined various tricks in the following command which did the magic (relevant switches are highlighted):

mplayer -tv driver=v4l2:width=640:height=480:outfmt=i420:alsa:adevice=hw.0:
:norm=PAL tv://

The adevice, amode and audiorate are dependent on your tuner card, whereas the alsa, forceaudio and immediatemode=0 are mandatory if you’re trying to capture sound from line-in.

That’s it. Now I don’t have to boot to Windows every time I want to do some video-recording. The profusion of capturing options in mencoder compared to MSI’s bundled software comes as an additional bonus for me.

Tags: , , , , , , , , , ,

April 2, 2007

HOWTO: Use xwd for screenshots

Filed under: Blog — krkhan @ 10:22 pm

If you’re using KDE, KSnapshot can do the job for you. If you’re using GNOME, gnome-screenshot can also achieve the task with quite perfection. So why would someone ever need tinkering with command-line utilities to generate screenshots?

The answer is: xwd is useful because not everyone uses KDE or GNOME and those who don’t usually despise installing needless extra applications for something as trivial as capturing a screenshot. xwd comes with the server itself, while almost all distributions by default provide the necessary software needed to convert xwd screenshots into more popular formats. Moreover, KSnapshot and gnome-screenshot have a plethora of dependencies on their relative desktop environments whereas xwd is a small, neat and efficient solution for capturing. Let’s start with the requirements:


The first thing that you need to be sure of is that you have either ImageMagick or Netpbm installed on your system. The quickest (generic) way for checking their existence is to issue man ImageMagick and man netpbm commands in a terminal. If you receive “No manual entry for …” errors for both commands, head over to your distribution’s website and download a package for ImageMagick since it would be relatively easier to find.


If you want to capture the whole screen, you can safely skip this section. However, if you want to target a particular window, some extra information shall be needed. Open a terminal and issue the command:

$ xwininfo
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.

Click on the window for which you’d like to take the screenshot. You’ll be shown lots of details about your choice. Only the first line is important. It would be containing a window id. Something like:

xwininfo: Window id: 0x1a00003 “1. Rammstein – Mutter – Ich will (3:39) – Audacious”

Copy the window id. You’ll be needing it in the next section.


Now comes the real part. If you want to capture the whole screen and have ImageMagick installed, use the following command:

$ xwd -root | convert xwd:- capture.png

A file named ‘capture.png’ shall be created in your current directory. You can change the png extension in the command to generate a variety of other formats (e.g. jpg, gif, tiff).

To capture a particular window, you have to provide the window id that xwininfo provided you. The final command will look something like:

$ xwd -id window id | convert xwd:- capture.png

Someone might start wondering here why didn’t I use import command from the ImageMagick suite. Actually, the problem with import is that it really doesn’t work well with all compositing window managers. For example, Emerald’s decorations are always chopped off whenever I take a screenshot with it.

If you have Netpbm installed, you can use these commands instead:

$ xwd -root | xwdtopnm | pnmtopng > capture.png

$ xwd -id window id | xwdtopnm | pnmtopng > capture.png

Finally, if you don’t like the terminal window in full-screen captures, you can insert sleep 3; before any command given above to give yourself some time for minimizing it.

Happy capturing!

Tags: , , , , , , , ,
« Previous Page