Log <-

Archive for the ‘linux’ Category

RSS   RSS feed for this category

Recording Linux desktop with PulseAudio

For a while now I've been trying to record my Ubuntu desktop with various levels of success. I've been using recordmydesktop to do my recording. Recordmydesktop is a simple commandline tool that outputs an .ogv (Ogg Video) file which is a container format that uses the Theora video codec and the Vorbis audio codec. Most modern video/audio applications on closed-source desktops such as Windows and MacOS-X won't be able to read those, but we convert them to other formats using a range of open tools. We'll get to that later.

Recording the desktop

Recording the desktop is fairly easy. We can either record the entire desktop:

recordmydesktop -o /home/todsah/out.ogv

or we can record a single window. For this we need the window id, which you can get with a commandline tool called xwininfo:

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

Now we click on the window, and xwininfo will give us the window ID:

xwininfo: Window id: 0x9c00003 "[root@eek]/home/fboender$"

Now we can tell recordmydesktop that we want to record just that window by giving it the window ID:

recordmydesktop --windowid 0x9c00003 -o /home/todsah/out.ogv

Once you're done recording, simply press ctrl-c in the recordmydesktop terminal, and it will start encoding your recording to out.ogv.

Sound issues with PulseAudio

Okay, so far so good, except for the sound, which is simply missing. We can see that recordmydesktop did record some kind of sound by looking at the output of the encoding:

Done.
Written 1967932 bytes
(1845110 of which were video data and 122822 audio data)

So why isn't there any sound in the video? The problem is PulseAudio (again and again and again). PulseAudio acts as a layer between all the applications, all the different sound architectures (ALSA, OSS, etc) and between the hardware. In my case, the problem was that recordmydesktop was recording from the incorrect device. Of course the default Sound Preference of Ubuntu 10.04 didn't list any Recording devices, which is why it took me so long to find out what the problem was. To fix this, install the PulseAudio Volume Controller:

# aptitude install pavucontrol

You will now get a PulseAudio Volume Controller in the menu:

Start it up, and select the 'Recording' tab:

Now, make sure you've already started recording your desktop, or the application that's trying to record sound will NOT show up in this list! You should also start playing a song or generate some other audio so it's easier to spot when things are working. As you can see, it shows per application where that application is recording sound from. Select the source it will record from by clicking on the button that says 'Monitor of Internal Audio Analog Stereo'. A list will appear with options. Try each option until the volume bar below the application comes to life. I have not yet experimented with microphones, but I wouldn't be surprised if this was also the place to select that as a recording source.

recordmydesktop will now probably record sound also. You may have to tell it which channel to record sound from. This command at least worked for me:

recordmydesktop -o /home/todsah/out.ogv --fps 15 --channels 1 --freq 22050 --device pulse --v_quality 63 --s_quality 10 --workdir /tmp

You can also configure 'pulse' in the GTK front-end for recordmydesktop by going to AdvancedSoundDevice. Enter 'pulse' there.

Converting to other formats

Converting to other formats is, frankly, a real pain in the ass. There are basically three applications which you can use:

  • mencoder
  • ffmpeg
  • vlc

The main problem with encoding is codecs. A movie contains video and audio, and both of those are basically stuffed into a single file. Such a file is called a container. Examples of containers are Ogg, AVI and mp4. The video and audio files in these containers are called streams. The streams are almost always encoded in order to compress them or to allow for additional information to be embedded in the streams. Encoding these streams is done with codecs. And this is where we get in trouble. You see, most codecs are patented, trademarked, copyright and generally completely unsuitable for Free Software usages. This is why mencoder, ffmpeg and vlc usually have trouble with them.

Any of the above programs may not support the input container/codecs (Ogg container, Theora video, Vorbis audio) or may not support the output container/codecs such as the TS/Avi/Ogg/MP4/ASF containers which contain the Theora, Mpeg-4, Mpeg-2, WMV, etc video codecs and the AAC, MP3, etc audio codecs. VLC can usually play just about everything (because it provides many illegal decoding codecs), but it has trouble encoding in many format.

To my great regret, it's up to you to find out which combinatation of containers and codecs works for you. You can check the Medibuntu website for instructions on how to add illegal codecs to your Ubuntu installation.

For me, it seems mencoder works the best. For instance, to convert the out.ogv file to an AVI file:

mencoder -idx out.ogv  -ovc lavc -oac mp3lame -o output.avi

Excluding results of a 'find' command (inverting tests)

In kind of a follow up to my previous post on using find and sed to search and replace multiple files, I found out something else.

I needed to find and replace something in every file, except for any files which had ".svn" in them. After struggling for a few fruitless minutes with -regex, I stumbled upon this example in the manual page:

find /sbin /usr/sbin -executable \! -readable -print

   Search for files which are executable but not readable.

The \! allows us to invert the tests after it. Perfect! All we need to do is use -regex to do our excluding:

find . -type f \! -regex ".*\.svn.*"

And we can now search and replace in all files except those that have ".svn" in them:

find . -type f \! -regex ".*\.svn.*" -print0 | xargs -0 sed -i "s/foo/bar/"

Neat. Note that, again, -regex is a GNU find only construct.

Linux search and replace

I always kept a small Python script around for searching and replacing in Linux. Turns out that GNU sed has an inline edit mode which I didn't know about:

       -i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if extension supplied)

This makes searching and replacing in files as simple as:

find . -name "*.txt" -print0 | xargs -0 sed -i "s/foo/bar/"

This replaces all occurences of "foo" with "bar" in all the .txt files in or below the current directory.

Unfortunately, -i appears to be a GNU extension, so it won't work on *BSD or Solaris, probably.

Debian: MAC address changes: interface changes

Since Debian 4.0 or some such, when your MAC address changes, your interfaces changes too. So if you spoof the MAC address of your nic, or you clone a Debian 5.0 VirtualBox guest and assign it a new different random MAC address, or if your nic broke down and you replaced it, the new nic will be assigned to eth1 instead of eth0 (if you previously only had one network card in your machines, that is). Chances are your statically defined network settings (in /etc/network/interfaces) will not work anymore, because they refer to eth0, and not to eth1.

The reason behind this appears to be Udev. It keeps a list of MAC addresses and which interfaces they were assigned to, and when it sees a new MAC, it assumes that is a new network card, and so assigns it a new ethX interface. This is both a good thing, as it will keep your system from rearranging all the nic's if you add one or one dies, and a bad thing, as your network will not come up anymore if you've replaced the previous nic

To fix this, log in at the console as root, find a file named something like persistent-net.rules in the /etc/udev/rules.d/. The file may be prepended with some and remove all the lines in that file below the You can modify it... line.

When done, reboot. (I haven't yet found out how to regenerate the file. Running the executable the file mentions doesn't work for me).

Software Bashing

We started a new site where we can vent our rage on all things sucky about software:

Software Bashing: We hate software. With a passion:

Fact: All software sucks. We're here to show you exactly why, and just how much it truly sucks. We don't discriminate against vendor or development model; all software sucks. We are relentless. We show no mercy. If the software exists, we will find its suckage, no matter how much it leverages synergetic business potential. Be prepared.

Hopefully we can reach some software authors and make them see the light. If not, at least I was able significantly reduce my blood pressure through the site.

Ubuntu sucks!

I used to be real pleased with Ubuntu, because it got a couple of things right that Debian didn't. But I've upgraded my Ubuntu install three times now, and every time I upgraded everything broke.

The last time I upgraded, everything even remotely having anything to do with sound broke. This was because the geniuses at Ubuntu decided to include the shitty PulseAudio sound architecture in Ubuntu way before it was ready to be included. (Yeah, I know, not really PulseAudio's fault, but I'm just trying to get the PulseAudio crowd pissed at the Ubuntu crowd in the hopes that they'll gun them down).

Last time I upgraded, from Hardy to Intrepid, all my sound stuff broke again, flash didn't work anymore, my wireless broke (I've kind of fixed it now, but now NetworkManager keeps dropping the wireless connection when I push too much data through it, and can't get up again without a reboot – piece of shit), my hotkeys and all my keybindings broke, my sessions weren't saved anymore, my sound applet refuses to address the right mixer channel, my ~/.xinitrc is being ignored, I can't rm -rf / anymore (my favorite past-time thing in Linux :-( ).

Each time I upgraded Ubuntu, I found myself doing a clean install a couple of days later because too many things had broken. And even after that, many of the broken things were still busted.

I've had it with Ubuntu. It's a piece of shit. I'm going back to Debian Stable.

Terminator – Splitting Terminal Emulator

I use terminals a lot. Some years ago, there was a terminal emulator called Gnome-multi-terminal, which could be split horizontally and vertically, and thus giving optimum workspace usage when using many terminals. Gnome-multi-terminal wasn't being maintained anymore (or at least not regularly) and started displaying some buggy behaviour in newer versions of Debian and Ubuntu.

I've searched for a replacement for a long time, but was never able to find one. Now I finally have: Terminator.

Here's a screenshot:

.

Nice :)

This is nice: I would just like to say….

Apache 2.2: Multiple authentication providers

For a long time Apache only supported a single authentication provider per location. For instance, you'd have:

<Location />
    Require valid-user

    AuthType Basic
    AuthName "FooCoorporation"
    AuthBasicProvider ldap

    AuthzLDAPAuthoritative Off
    AuthLDAPURL ldap://192.168.1.1:389/ou=foo,o=electricmonk,c=nl
    AuthLDAPBindDN cn=ldapreader,o=electricmonk,c=nl
    AuthLDAPBindPassword PASSWORD
</Location>

In older Apaches, it wasn't possible to add another Authentication provider. So, in the situation above, you can run into problems when your LDAP server dies on you, and you won't be able to login to the / location anymore until the LDAP was fixed. Another problem with single authentication mechanisms is that there's no way to add authenticated users if they're not in the LDAP.

Since Apache 2.2 multiple authentication providers are now supported. This is nice, since now you can have an LDAP authentication provider with an htpasswd fallback authentication mechanism.

You can enable it by specifying multiple AuthBasicProvider providers:

    AuthBasicProvider ldap file

So the full Location section becomes, for example:

<Location />
    Require valid-user

    AuthType Basic
    AuthName "FooCoorporation"
    AuthBasicProvider ldap file

    AuthzLDAPAuthoritative Off
    AuthLDAPURL ldap://192.168.1.1:389/ou=foo,o=electricmonk,c=nl
    AuthLDAPBindDN cn=ldapreader,o=electricmonk,c=nl
    AuthLDAPBindPassword PASSWORD

    AuthUserFile /var/www/.htpasswd
</Location>

Transmission 1.x on Ubuntu 7.10

For some reason Ubuntu 7.10 has an ancient version of Transmission. Version 0.74 or somesuch. Unfortunately, that version of Transmission contained some bugs so it's blocked by certain bittorrent trackers. In order to install a more recent version:

You can download a more recent version from the gutsy backports package pool.

  • Uninstall transmission:
    sudo aptitude purge transmission transmission-gtk
  • Download transmission-common 1.04
  • Download transmission-gtk 1.04
  • Install the packages:
    sudo dpkg -i "transmission-common_1.04-0ubuntu1~gutsy1_all.deb"
    sudo dpkg -i "transmission-gtk_1.04-0ubuntu1~gutsy1_i386.deb"

And you'll have a more recent version of Transmission.