November 2006

FFmpeg, Flash movies, and bad frame counts

For work stuff, I’ve been needing to set up a script to convert videos from whatever form they come in as to SWF (or, really, FLV embedded in SWF). The best thing for this that I found was FFmpeg. It does just about anything. One thing it doesn’t seem to do however is produce SWF files with the right frame count. It always writes the header with a count of 15,000, no matter the length of the incoming video. 15,000 is the maximum number of frames that the flash player can handle, and is used as a placeholder value when the file is created.

I tracked the problem down to the output not being correctly flushed, and the following patch fixes it:

Index: libavformat/swf.c
===================================================================
--- libavformat/swf.c   (revision 7093)
+++ libavformat/swf.c   (working copy)
@@ -689,7 +689,6 @@
     put_swf_tag(s, TAG_END);
     put_swf_end_tag(s);

-    put_flush_packet(&s->pb);

     /* patch file size and number of frames if not streamed */
     if (!url_is_streamed(&s->pb) && video_enc) {
@@ -699,7 +698,7 @@
         url_fseek(pb, swf->duration_pos, SEEK_SET);
         put_le16(pb, video_enc->frame_number);
     }
-
+    put_flush_packet(&s->pb);
     av_free(swf->audio_fifo);

     return 0;

In case you’re working on a substantially different version of swf.c, this goes towards the end of static int swf_write_trailer(AVFormatContext *s), and is just moving the put_flush_packet call to after where the frame number is written into the file, rather than before.

Pretty simple eh? I mentioned this on the ffmpeg-users list, but noone seems interested. No matter, I don’t mind too much keeping a custom build with this change. I need to do it anyway, the Ubuntu FFmpeg version doesn’t have MP3 encoding support, and that’s a must for creating FLV.

Software
Work

Comments (1)

Permalink

Fixing broken dates

When I was home over the weekend, I was working on helping my parents sort out the photos they took while they were in Europe. Doing this, I noticed that the date on the camera was out by a month. Being a stickler for correct metadata, I tried to figure out a way to fix this. This is the command line that I came up with. I’ve broken it into multiple lines here for clarity.

for f in *.jpg ; do
    NEWDATE=`exiftool -CreateDate $f |
        perl -pe 's/.*: 2006:([^:]+):/sprintf "2006:%02d:", ($1+1)/e'`;
    echo $f: $NEWDATE;
    exiftool -CreateDate="$NEWDATE" -DateTimeOriginal="$NEWDATE" $f;
done

This will modify the month field in the EXIF data of each file by increasing it by 1. It doesn’t handle wrap around or anything, I didn’t need to do that. The fanciest it gets is making sure there’s the correct number of zeros padding the number.

You don’t want to run this twice.

Linux
Photos

Comments (2)

Permalink

Ubuntu and the Epson Stylus CX5900

I spent some time over the weekend getting my parent’s new Epson CX5900 printer/scanner to work. It seems to be either so new or so uncommon that Ubuntu didn’t really know what to do with it. So here I’ll document what I had to do (and then I’ll go file some bug reports so the right people get to see it :))

All this was done on Edgy, I upgraded them to that just before trying, in the hope that it would have drivers for it already. no such luck.

This is split into two parts because the functions are in no way related to each other.

The Printer
When you attempt to set the printer up with the Ubuntu printer interface, it detects it correctly, but has no driver for it. Instead, it suggest you use the CX5100 driver. This doesn’t work, instead it spits out blank pages. [Bug report]

After spending a while poking around, I eventually created a PPD file for the CX5800, and loaded that in through the CUPS web interface. It’s quite possible that simply selecting the CX5800 driver would work too. Once I got it going, I didn’t try to change it. Here’s what I did in case it’s necessary. Update: apparently generating the PPD is quite unnecessary, and just picking the CX5800 will do the job just the same. That’s not surprising at all.

Create the PPD file:
cups-genppd.5.0 -v ‘Epson Stylus CX5800′ -p .
Then add printer in the web interface, and use this driver. Note that I had added the package foomatic-filters-ppds before doing this. It may or may not be necessary.

After this, it seems to work fine. I still don’t know how to make it pick colour or grayscale, a quick glance at the properties box didn’t show anything obvious, but it may be there and I didn’t notice.

The Scanner
Making the scanner work was a bit trickier, but actually took me less time. Credit where it’s due, this thread on the Ubuntu forums was a big help.

First, make sure all the extra sane stuff is installed (libsane, libsane-extras and sane-utils).

Running sane-find-scanner spits out a fair amount of text, but also includes this line, which is key:
found USB scanner (vendor=0×04b8 [EPSON], product=0×082e [USB2.0 MFP]) at libusb:001:003

This gives the USB details of the scanner. Then add them into udev. I put them in /etc/udev/rules.d/45-libsane.rules, but in hindsight, it would be best to put them into a custom rules file so you don’t get messages about upgrades wanting to replace changed files.

This is the line to add:

# Epson CX-5900
SYSFS{idVendor}=="04b8", SYSFS{idProduct}=="082e", MODE="664", GROUP="scanner"

[Bug report]

Note that you can’t add them into /etc/udev/libsane-extras.rules because it’s a symlink, and so the changing file doesn’t get picked up by udev (it’s documented in the readme, so I guess it’s a bug with libsane-extras). It would work after a reboot, but that’s just annoying.[Bug report]

You also need to tell sane about the scanner. This is done simply by adding:
usb 0×04b8 0×082e to the file /etc/sane.d/epson.conf. [Bug report]

To test it, unplug the printer’s USB connection and put it back in, to allow the new rule to be used. Now a ’scanimage -L’ should cause the scanner part to move a bit, and it should report that it’s found something. It seems to detect it as a CX6000 or something.

Linux

Comments (2)

Permalink

No longer a skeptic

Fake moon landing pic

Well, I’m forced to admit now that the evidence is undeniable. It has become clear that the moon landings were faked by NASA. Why else do you think they wouldn’t be able to find those ‘missing’ tapes? More details on the fraud are here.

Photos

Comments (0)

Permalink

Moving server

I’ve finally gotten around to putting all my kallisti.net.nz stuff onto a real server. Well, I guess it’s not a real server, as it doesn’t actually exist anywhere. But it’s a real virtual server, as opposed to the quaint Pentium Celeron 466 that was doing the job.

It’s now hosted by TekTonic, who do a pretty good deal for a fairly minimal unmanaged virtual server. It’s the first one of those listed that I’ve got. The CPU is more than enough for what I’m going to be doing, and the bandwidth is many times better than the 256k/128k that the old server was on. The only catch really is the disk, I have not too far off 10G of stuff to put on it. Of course, I guess I could delete some email or something…

I’m hoping that someone builds a system that lets me use Amazon S3 to store the photos in gallery, that’ll make life a lot easier, as then I won’t have to worry about space on it at all.

Anyway, the migration is still in progress. Jabber.kallisti.net.nz was moved first, as that was pretty easy, and I now have www.kallisti.net.nz on there, except gallery. Now it’s just the other websites that are hosted there, and finally the mail. Mail is going to be the most tricky, as new mail will always be coming in, and it has a fairly complex setup. A curious side-effect of it being split up like this, is that if one webmail user sends an email to another webmail user, it will travel to the US and back up to four times, as it’s stored in NZ, the webmail runs in the US, and then that’s likely to be viewed in NZ again. However, this will become a little more sane soon I hope.

The eventual upshot of this is that for the first time in years, I won’t have to have a computer running in my bedroom 24/7 :)

Linux
Sysadmin

Comments (0)

Permalink