Sunday, 13 July 2008

Mythtv and DVDs

Mythtv supports the playback and ripping of DVDs. Under ubuntu the mythdvd package supports playback of dvd, ripping and transcoding. (There used to be a separate myth transcoding package which mythdvd supersedes.)

Mythdvd assumes the dvd device is /dev/dvd, however the udev rules in Ubuntu don't necessarily generate a /dev/dvd link to the cdrom which has lead to a number of questions on Ubuntu forums about being unable to playback dvds.

Under ubuntu the /dev devices (nodes and symlinks) are automatically generated under udev, so even if a link is made by a user it will be lost on reboot. Instead, what you'd like to do is make sure udev generates its own symlink from /dev/dvd to the real device.

Udev (in Ubuntu) uses rules in /etc/udev/rules.d. The two pertinent rules sets are:

/etc/
/etc/udev/rules.d/70-persistent-cd.rules
/etc/udev/rules.d/75-cd-aliases-generator.rules


The cd-aliases-generator rules file automatically generates the persistent-cd rules file which is executed to create cd link aliases.

The short solution to this for me was to edit the persistent cd rules file and duplicate one of the entries which created symlinks

# This file maintains persistent names for CD/DVD reader and writer devices.
# See udev(7) for syntax.
#
# Entries are automatically added by the 75-persistent-cd-generator.rules
# file; however you are also free to add your own entries provided you
# add the ENV{GENERATED}=1 flag to your own rules as well.
# TSSTcorpCD-RWDVD-ROM_TSL462C (pci-0000:00:1f.1-ide-0:0)
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-ide-0:0", SYMLINK+="cdrom", ENV{GENERATED}="1"
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-ide-0:0", SYMLINK+="cdrw", ENV{GENERATED}="1"
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-ide-0:0", SYMLINK+="dvd", ENV{GENERATED}="1"
# CDRWDVD_TSL462C (pci-0000:00:1f.1-scsi-0:0:0:0)
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-scsi-0:0:0:0", SYMLINK+="cdrom1", ENV{GENERATED}="1"
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-scsi-0:0:0:0", SYMLINK+="cdrw1", ENV{GENERATED}="1"
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-scsi-0:0:0:0", SYMLINK+="dvd1", ENV{GENERATED}="1"
ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.1-scsi-0:0:0:0", SYMLINK+="dvd", ENV{GENERATED}="1"


Note that the last line was one I created by copying the previous line and editing the 'dvd1' down to 'dvd'. This exact file isn't going to work on your machine since the path identifier ("pci-0000:00:1f.1-scsi-0:0:0:0") is hardware dependent so likely to be different on different machines, but the principle is the same.

As far as I can tell the 'ENV{GENERATED}="1"' tag at the end of the line prevents the entry from being deleted.

For a better understanding of udev rules you might try this link.

Saturday, 12 July 2008

Ubuntu Removable Drives and Media

I have had a photo importing script that worked very well- automatically executed when plugging in the SD card from my camera, importing photos, rotating, filing in date folders and copying to a network drive. The automatic behaviour was kicked off by changing the default application in the Preferences control panel 'Removable drives and media' in Ubuntu.

This worked very well- until it didn't. I just worked out what went wrong and this post is basically Google fodder for any other poor unfortunates who may have been struck by the same problem.

Basically in Ubuntu Hardy (8.04) Nautilus was changed over to use GVFS (the gnome virtual filesystem) and GIO (Gnome I/O abstraction layer) it also took over the functionality of handling certain media types- including removable media like photo CDs, digital cameras and so on. You can find this from the menus in any Nautilus window: Edit > Preferences > Media. Sadly this functionality is significantly less functional for my purposes. Where before I could simply substitute the path to my import script to get similar functionality I had to:

  1. As root create a new 'my-import.desktop' file in /usr/share/applications (example contents see below)
  2. Open nautilus media preferences (from the menus in any Nautilus window: Edit > Preferences > Media) and select 'Ask What To Do'
  3. Plug in the memory card and select the 'Open My Import Script' option and click the 'always use this option' checkbox

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=My Import Script
GenericName=Import Script
Comment=Run my import script
NoDisplay=true
Exec=import_script %u
Icon=f-spot
MimeType=x-content/image-dcf;x-content/image-picturecd
StartupNotify=true
Terminal=false
Type=Application
Categories=Graphics;Photography;GNOME;GTK;



These bug reports led me to the solution. There is some discussion about a fix for this backward step in functionality- hopefully their feedback will lead to an upstream fix in Gnome or a standing patch in Ubuntu to return something like the old behaviour.