December 2, 2009

Burning AVIs to DVDs under Linux

Converting AVIs to DVD-compatible MPEGs

ffmpeg -i foo.avi -target ntsc-dvd foo.mpg

I love ffmpeg, by the way.

Two-pass encoding

ffmpeg -i foo.avi -pass 1 -target ntsc-dvd -an /dev/null
ffmpeg -i foo.avi -pass 2 -target ntsc-dvd foo.mpg

-pass 1 writes out a “log file.” Two-pass encoding only applies for video, so you -an to ignore audio on the first pass. -pass 2 then reads the log file that -pass 1 created for it.


-threads 2. That was easy.

Aspect ratio

If your movie is in 4:3 or 16:9 (the only two aspect ratios that seem to be common—if not the only two allowed—for [NTSC?] DVD video) then ffmpeg seems to pick up the aspect ratio right. Sometimes you do need to hint it with -aspect 4:3 or -aspect 16:9 though? Play around. If the resulting MPEG file doesn’t look right in your media player, it probably won’t look right on your screen.

You can pass other aspect ratios to ffmpeg, like -aspect 2.33:1, but don’t expect anything to like putting that on a DVD, and don’t expect your (my) old Sony player to play it at all.

Now say you have a movie in 2.35:1, a 1280×544 image. I was hoping ffmpeg would do “magic” to turn it into letterbox anamorphic widescreen. It did not. Instead, I had to do it by hand.

NTSC (this is all NTSC by the way) DVD video is 720×480. Anamorphic PAR is 32:27, so using square pixels 16:9 video with 480 lines would be 854×480. (That’s actually a lie: it’s closer to 853×480; but 854 seems to be the accepted number.)

Now imagine fitting your 1280×544 image into an 854×480 box. Since 2.35:1 is wider than 16:9 (1.77:1) we’ll have to pad the top and bottom. How much? 544 * 854 / 1280 = 362.95, so lets say we’re aiming for a height of 363 pixels.

480 – 363 = 117 pixels of padding needed, that’s 58.5 lines of black bars each for the top and the bottom of the image. Of course, you can’t have a fractional line (pixel). What’s more, ffmpeg requires padding to be a multiple of two, so we’re going to say 480 – 362 = 118, 118 / 2 = 59, so we’ll put 58 lines of padding on the top and 60 lines of padding on the bottom.

This leaves us with the following command line:

ffmpeg -i foo.avi -target ntsc-dvd -s 720x362 -padtop 58 -padbottom 60 -aspect 16:9 foo.mpg

-s 720x362 says to make the input movie that size. Then the -padtop and -padbottom are added to that size: 362 + 58 + 60 = 480 (720×480).

If you’re curious how we got back to 720 from 854, remember that NTSC DVD video is always going to be 720×480; the DVD player stretches the picture to 854×480 for you. So while 720×362 screws up our aspect ratio, anamorphic widescreen will stretch it back out to make it right.

(There is an additional restriction on the size of the video, but I don’t recall what it is; when you run into this ffmpeg will tell you, and you’ll have to slightly shrink/expand the video and adjust padding accordingly.)

DVD authoring

mkdir dvd
dvdauthor --title -f foo.mpg -o dvd
dvdauthor -T -o dvd

Automatically making chapters

I used makexml for this. Should be something like:

makexml -chapters 5 foo.mpg -out foo  # creates foo.xml
dvdauthor -x foo.xml -o dvd
# I don't remember if this last step is necessary when using an XML
# file, actually:
dvdauthor -T -o dvd

This makes chapters every five minutes in the movie. When you see the format of the XML file you’ll actually be embarrassed; I think you could write a shell script to do this very easily (faster and with fewer dependencies than makexml).

Making an ISO


mkisofs -dvd-video -o dvd.iso dvd

(Is mkisofs now deprecated? I think it calls some other program on my machine.)


hdiutil makehybrid -udf -udf-volume-name <label> -o dvd.iso dvd

I think the -dvd-video switch might toggle something a little special in the ISO, but I don’t have any concrete information on that. If I’m right, though, I’m betting the OS X version doesn’t toggle that magic bit. So if you have problems with the hdiutil-generated ISO, try making the ISO with mkisofs instead.

January 27, 2009

Reset your keyboard in X

I was using VMware and my keyboard went to Horkytown. My recipe for resetting the keyboard (at least on Fedora 10):

  1. egrep -i 'rules|layout|model' /var/log/Xorg.0.log to find out your rules, layout, and model for your keyboard.
  2. setxkbmap -rules xorg -layout us -model pc105 substituting the values from step 1 where appropriate.

If you have to SSH in and do this, like I did, prepend DISPLAY=:0 to setkbmap of course.

January 19, 2009

Where’s the packaging calculator?

So we’re moving, and I’m selling a bunch of stuff on (e.g.) eBay. There are plenty of shipping calculators—eBay has some of their own. But where the fuck is the packaging calculator? I had to call my local UPS store to find out how much it costs to have them pack things like a turntable or a cordless phone. Totally dumb.

By the way, a lot of the estimates I’m seeing online for packing are far too low, it seems to me. I see people talking about $1, $5, etc. for packing; UPS store says my turntable will cost at least $13-$15 for packing. $8 for the phone, they estimate.

December 27, 2008

Charge rate for NiMH batteries

I got a Maha MH-C9000 WizardOne battery charger for Christmas. This charger lets you charge/discharge rates appropriate to your batteries (and your needs, such as how fast you need the batteries). However, the documentation isn’t really clear about just what rates I should use for, say, it’s “Refresh and Analyze” mode; so I went looking.

  • The charger’s “manual” says 0.3C to 1C.
  • Servaas Products says 0.5C charge, 0.25C discharge, although I have no idea how reputable they are.
  • PowerStream kind of says 1C, at least in a “smart charger” like this one that (I think…) senses temperature as well as voltage drop. (But maybe I’m giving this Maha charger too much credit? Will have to look back at the docs.)
  • Panasonic says 0.5C to 1C (PDF). I actually like this document: specifies charging behavior from start to finish, and it agrees with other things I found.
  • Duracell says 1C, or 0.5C to 1C. Starting to see a trend here. Duracell seems to primarily recommend 1C rate, watching temperature, but at the bottom they also list other methods, including less than 1C charge rate with basically the same termination conditions.
  • Isidor Buchmann says 1C more or less. “Nickel-based batteries prefer fast-charge.”

I started thinking I would charge at 0.5C, but now I’m thinking 1C.

What about discharge rates?

  • The charger’s manual says not to discharge above 1C. The charger’s “break-in” mode does discharge at 0.2C, and it seems to indicate that this is an IEC standard.
  • Servaas says 0.25C. I still don’t know who these people are, but I am pre-disposed to liking them since they’re answering the exact questions I’m trying to answer.
  • The NoBS Batteries FAQ says 300mA-500mA. For what capacity? Who knows! For the AA’s I’m looking at right now, 300mA would be less than 0.2C.
  • A thread on suggests 1C but I suspect they’re nuts (and/or dealing with sufficiently different NiMH batteries used in (really big?) RC planes).
  • Mr. Buchmann doesn’t offer concrete answers, but has some nice graphs which seem to suggest that lower discharge current means less capacity loss over time (or, more accurately, over cycles).

I don’t think I found as much concrete information about good discharge rates for NiMH batteries, but I think I’m going to be discharging around 0.2C.

December 6, 2008

Installing Fedora 10

Finally whacked my old Fedora 7 install and I’m starting over with a fresh install of Fedora 10. Some things I ran into:

  • I’ve got this fairly bizarre setup where my desktop has two NICs that need to be bridged. Fedora 10 throws out the old network service in favor of NetworkManager. However, the release notes pretty much tell you that NetworkManager isn’t for people that want bridging. No problem, just switch back to the old network service.

    I copied in my F7 ifcfg-* files verbatim and things seem to be working.

  • Either I’m on drugs or F7 used to rename network interfaces based on the HWADDR variable in your ifcfg-* files. In any case that doesn’t happen on F10: instead it just says “this MAC doesn’t match the MAC on the interface!” and doesn’t do anything at all with that interface. (Welcome to a bridge device trying to DHCP with no slave interfaces.) The new way of doing this isn’t bad, though: edit /etc/udev.d/rules.d/70-persistent-net.rules and set the NAMEs you want.

  • Apparently RPM Fusion is the new hotness: Freshrpms,, and “Dribble” (never heard of it) collaborating together for a single third-party RHEL/Fedora repository. At this point in my re-installation this sounds good to me: I used Freshrpms and together before, and I did have some confusion around whose packages were better. Unfortunately it sounds like there was some disagreement over the people running RPM Fusion (and maybe EPEL?) so Dag, Dries, and ATrpms are still around. There was RPMForge, but now they seem to have tucked that into rpmrepo along with ATrpms and some vague reference to “the CentOS project”.

    O, the confusion.

    Anyway, I’ve configured the RPM Fusion repositories in Yum via their directions. I also installed yum-protectbase, per a guide’s suggestion not to clobber Fedora base package. (We’ll see how that works out as I go on.)

  • Installed the NVIDIA binary drive for my GeForce 6500 (no, not a typo of 6600) from RPM Fusion. Pulled in stuff including system-config-display, which doesn’t want to run. I get an error like AttributeError: 'NoneType' object has no attribute 'device'. My gut tells me this is temporary breakage in Fedora, but I really haven’t investigated it much. I started with some directions on installing the NVIDIA driver in Fedora and went from there. Process was something like:

    1. yum install kmod-nvidia
    2. Ran livna-config-display, found that it picked the correct settings.
    3. Reboot to make sure I get the NVIDIA driver. (I did.)
    4. Find out that system-config-display won’t be helping me set my resolution, et al today.
    5. Find that /etc/X11/xorg.conf doesn’t describe much of anything: only sections were Files, ServerFlags, and Device (probably added/modified by the driver package), and Extensions.
    6. Find my xorg.conf which I backed up from Fedora 7 and copy its sections for the Monitor and the Screen into F10’s xorg.conf.
    7. Log out and back in to get new settings.

    After that everything was right as rain. Moving on.

  • Actually, while I was in there I also added the config section for my PS/2 Microsoft IntelliMouse Explorer through my KVM. (My KVM apparently screws up the mouse signals, so Linux/X sees some extra buttons when I use the scroll wheel. Maybe I should get a new KVM.)

    Re-using the mouse stanza from my F7 xorg.conf proved more difficult than I thought. I had to add a couple ServerFlags:

    Option      "AllowEmptyInput" "off"
    Option      "AutoAddDevices" "off"

    Apparently new wants to ask hal what your input devices are, so without turning AllowEmptyInput off Xorg will just ignore anything using the mouse driver. Of course, after just turning off AllowEmptyInput and with just my mouse stanza in xorg.conf I started getting all my mouse inputs happening twice; that is, click once and you get a double click. This is because it was auto-detecting my mouse and also using my explicitly configured mouse. So then you have to turn off AutoAddDevices. Note that this probably means plugging in new input devices won’t make them “just work” in, but that’s purely speculation.

    Of course, after adding the two above I found out that I didn’t have a keyboard anymore, so I had to copy in the keyboard InputDevice stanza from my old F7 xorg.conf as well.

    Are we having fun yet?

  • Oh, and I also added DontZap, which probably exists primarily for the benefit of Emacs users.

  • I spent hours toying with Compiz Fusion configuration. (I was doing it through gconf-editor, but I’m told ccsm is a good configuration tool for Compiz Fusion–not installed by default, at least on my box.)

    To use Compiz Fusion you have to turn on “Desktop Effects.” Compiz Fusion plugins I’m using: core, glib, gconf, dbus, png, svg, text, video, screenshot, place, minimize, wall, move, resize, switcher, scale, decoration, resizeinfo, snap, vpswitch, scaleaddon, showdesktop. Note that order can be important: text needs to come before scaleaddon.

    • Between wall, scale/scaleaddon, and showdesktop, I’ve got keys basically just like Expose.
    • switcher switches more or less like I want it (i.e. like Sawfish.
    • place could stand to be a little smarter but I’ll live.
    • Note that you don’t need wobbly (too much eye candy, methinks) to get window snapping, you just need snap.
    • vpswitch lets you go jump directly to specific virtual desktops, so I can have C-1 through C-4 just like I do with Spaces.
    • resizeinfo fulfills my need to see my terminal geometry while I’m resizing it.

    All in all I’m pretty happy. There are even ways to do things like bring up the run dialog. One thing I would like to see fixed is the title filtering in scaleaddon: apparently broken, though I think someone might have realized this per some Googling I did.

    For now, no Sawfish for me.

    (I will note here that my Super (i.e. Windows) key seems to be behaving strangely in some applications. For example, if I try to make <Super>n open a new terminal in gnome-terminal, it secretly makes it so any time I hit n I open a new terminal. Duh.)

It was about this time that I decided to try and switch from writing this entry on my MacBook to writing it on my new F10 box. This meant I had to get at least Emacs and Pandoc working, and that probably meant that I was going to need Firefox to work so I could download/configure those things.

  • Funny thing: the proverbial “last straw” that led me to upgrade Fedora was that I wanted Firefox 3 and Weave. Unfortunately F7 was old enough that I just had Firefox 2.x. The Firefox 3 binaries from wouldn’t run Weave, complaining that Weave couldn’t initialize its crypto module ( So I figured I’d just upgrade to a distribution that has Firefox 3 by default.

    I bet you can already guess where this is going.

    I fired up Firefox, installed Weave, restarted Firefox and… same error about not being able to load the crypto module. Go to the Weave Forums, see that a new Weave seems to be out (finally): Weave 0.2.92. Cool! Lets read the notes:

    1. This is the first release after some really major changes, so expect rough edges (even more than usual).
    2. Only bookmarks sync is currently implemented.
    3. You will need to set up your own instance of the 0.3 server.

    I’m thinking some really harsh things right now. I really just want Google Browser Sync back. I don’t have any right to bitch about nice people doing a somewhat complicated task and doing it entirely for free; but I will say that it’s a really big deal for me to be able to keep Firefox synchronized between the 2-4 computers I use it on.

    I will simply say: Weave is nowhere near ready for prime time–just like (I believe) it advertises, if only through the version number.

    So fuck it: I’m now a Foxmarks user. They just added password synchronization, and most importantly the shit seems to work on both my Mac and this new F10 install. Now all I think I want is cookie synchronization (I like for my login cookies to get propagated around, it makes for nice “seamless” browsing when I switch which computer I’m on).

  • So I know that one of the few packages I elected to install right at install time was Emacs. Lets start it up. WTF, where is my 10×20 font? Turns out I had bitmap-fonts installed, but I couldn’t use them (except for a few sizes–WTF?) until I installed the xorg-x11-fonts-misc package. (In fact, now that I look at that package, I’m not sure bitmap-fonts is important here at all, since xorg-x11-fonts-misc seems to have 10x20 font files itself.)

  • Time to get Pandoc installed, which means getting Haskell stuff. I use Pandoc to convert between Markdown and HTML: I compose blog posts in Markdown, then convert to HTML before uploading to WordPress (all in Emacs, of course). When I want to edit a post, I use Pandoc to convert from HTML back to Markdown. So far it’s working pretty well, and it gives me the option of using syntax highlighting. I’ll probably have a longer post about Pandoc (and Haskell) in the future.

    Today I just want the pandoc program. I’ve got a couple patches against Pandoc so I don’t even bother to check if it’s in one of my configured repositories. I did yum install ghc.

    No cabal-install in Yum. (It was in MacPorts, which made my first installation of Pandoc somewhat easier.) The Real World Haskell book apparently has instructions on installing cabal into your home directory. Don’t follow these! What they don’t tell you is that you can just go grab cabal-install (conveniently the last package on their list…) and run its script, which nicely leaves you with ~/.cabal/bin/cabal.

    Pandoc needs utf8-string, zip-archive, and highlighting-kate. zip-archive needs the zlib-devel RPM installed, and highlighting-kate needs (indirectly) pcre-devel; so yum install zlib-devel pcre-devel. Then I can just cabal install utf8-string zip-archive highlighting-kate. Now I can compile Pandoc. This worked well.

Now I’m blogging on my F10 install. Hooray. But now I want some tunes.

  • F10 comes with amarok-1.98-1.fc10. As far as I can tell this entirely unusable. For example, I could never get the Phonon backend for Xine to work properly. Fedora aside, looks like I’m not the only one having problems with Phonon and Amarok. Woe be on to me for not running KDE? Perhaps.

    In any event I think this was a serious boner on the part of the Fedora maintainer. Amarok 1 was a very popular, and very feature-full application. To toss it out for the barely functional beta of the next version at this point seems foolish.

    Thankfully some kind soul made Amarok 1.4 RPMs for Fedora 10. yum localinstall these. Don’t forget to add something like exclude=amarok to, say, /etc/yum.conf so your nice working Amarok doesn’t get clobbered by the new broken Fedora one.

    If you then want to change your fonts in Amarok, you need to change them in the KDE theme. Where the fuck did kcontrol go? No idea. Someone posted a little snippet to go into your ~/.kde/share/config/kdeglobals file to change the fonts in Amarok (and KDE3?). I just used Sans Serif instead of UnDotum and changed 10 to 12 to get bigger fonts.

  • Somewhat surprisingly, sound basically worked. I managed to do a minimal enough installation that I didn’t even have the Gnome mixer, gnome-volume-control. Needed to install gnome-media for this, as well as aumix. Then I could turn up my volume, set my mixers appropriately, etc. Amarok worked with the ALSA output. Not sure if PulseAudio is involved here or not.

  • I’ve actually been using mDNS ever since I got a Mac. To enable this I:

    1. Went into system-config-firewall and opened the mDNS port (UDP 5353 IIRC).
    2. Installed nss-mdns, which nicely adds the appropriate configuration into /etc/nsswitch.conf.
    3. Restarted nscd (I use LDAP, lookups take too long if they’re not cached) and then ran nscd -i hosts to clear out the cached negative responses from my earlier tests.
  • Of course, shortly after using system-config-firewall, I decided it will still be easier in the long run to just maintain my iptables rules in a shell script, like I always have. So no more use of system-config-firewall for me.

  • My e-mail comes to me through a relay via SMTP. Delivery happens the good ol’ Unix way, through through mailfilter instead of procmail. I mostly copied the old setting from my F7 setup. I did remove Exim in favor of Postfix. (Exim, not Sendmail by default now, I guess?) TMDA was in Fedora, which is nice, and so was mailfilter. I also grabbed all the usual suspects like SpamAssassin, ClamAV (and set up a clamd for it), Razor, and Pyzor. (I don’t think Pyzor is working, due to failing sort of messages in /var/log/maillog. Oh well.)

    Everything pretty much worked smoothly. Only catches were SELinux stuff. Needed to restorecon -Rv /var/run/clamd.local /usr/sbin ~ to get all the contexts right. I also needed the following policy:

    require {
            type postfix_local_t;
            type unconfined_t;
    # This is probably way too broad, but I don't understand how to fix it
    # and Google isn't helping.  So long, security!
    allow postfix_local_t unconfined_t:unix_stream_socket connectto;

    Apparently the newer SELinux stuff comes with the policy sources and development Stuff on-board? In any case I had /usr/share/selinux/devel/Makefile already, so it was a snap to make the policy and then semodule --install it.

  • Installed a bunch of media players. I used an mplayer-codecs RPM I made for the all-20071007.tar.bz2 bundle of MPlayer codecs.

    I will mention one thing I ran into while building the MPlayer codecs:

    *** ERROR: No build ID note found in

    Turns out this is some new feature semi-recently shoved in to, which is part of the normal process for building an RPM. To skip this check for this big tarball of binaries, I put %undefine _missing_build_ids_terminate_build at the beginning of the spec file.

  • Installed Flash. (In case you can’t tell, I’m digging Mauriat Miranda’s guide. It’s reducing the task of reinstalling from actual thought to copy/paste.)

  • I copied over my .purple directory from my F7 install and expected to start Pidgin up and get going. Wrong: the #1 protocol I use on this box is Bonjour, and it didn’t work. Oddly, other PCs were seeing my announcement, but no one came up on my buddy list. Running Pidgin from the console (in debug mode? I can’t remember now) showed that it was refusing messages from anyone that wasn’t on my buddy list; as I just mentioned, that effectively meant it was refusing messages from everyone.

    This turns out to be a pain in my ass: they apparently found an insecure configuration in DBus, and the fix was to lock down what types of messages can be sent back in response to a DBus message (as far as I can tell, which may not be very far). For more information, see:

    The “broken services tracking bug” doesn’t list Avahi yet, but sure enough the DBus change breaks Avahi as well as all those other things listed. Pidgin/libpurple depend on Avahi to tell them who’s announcing presence (Bonjour) capabilities. No response from Avahi, no buddies in Pidgin.

    There is a quick, dirty, and insecure fix to the DBus problem which basically un-does the security fix as far as I can tell. Far from ideal, but (A) I don’t think that I’m particularly vulnerable, unless Fedora sucks in a malicious package, or unless I give someone else access to my box (ergo DBus); and (B) an local security problem is better than a box where a bunch of shit (i.e. Pidgin) doesn’t work.

  • VMware installed pretty easily, except in 6.5 you don’t have /usr/bin/ anymore. Now you apparently do sudo /usr/bin/vmware-modconfig --console --install-all. Network configuration is (I guess) done with sudo /usr/bin/vmware-netcfg. My XP VM is booted and running, so I guess it can’t be that bad.

Post script: I started this installation Saturday, December 6th, and I’m posting this on Wednesday, December 10th. Sigh.