Quantcast

How To Compile FlowPlayer on Ubuntu 8.04

Here is how I compiled FlowPlayer on Hardy:

NOCODE:
  1. sudo apt-get install ant
  2. sudo apt-get install java-gcj-compat-dev
  3. #without java-gcj-compat-dev, ant throws this error: Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.5.0-gcj-4.2-1.5.0.0/lib/tools.jar
  4.  
  5. sudo apt-get install mtasc
  6.  
  7. #need old version of swfmill; version in repo is 0.2.12
  8. wget http://swfmill.org/releases/swfmill-0.2.11.tar.gz
  9. tar xvzf swfmill-0.2.11.tar.gz
  10. cd swfmill-0.2.11
  11. ./configure
  12. make
  13. #install in /usr/local/bin
  14. sudo make install
  15.  
  16. cd ..
  17. wget http://internap.dl.sourceforge.net/sourceforge/flowplayer/flowplayer-2.2-src.zip
  18. unzip flowplayer-2.2-src.zip
  19. cd flowplayer-src
  20. emacs build.properties #edit DEPLOY_DIR
  21. ant

How to tunnel VPN over SSH

Today I had to use VNC to debug a remote machine, but firewalls were blocking VNC ports.

After I failed to get my VNC client (Chicken of the VNC) to use a SOCKS proxy, I was able to use SSH port forwarding to get it working. On your local machine type:

NOCODE:
  1. ssh user@remotehost -L 5900/localhost/5900

This forwards port 5900 on localhost to port 5900 on the remotehost. Then in Chicken of the VNC, open a new connection to localhost. That’s it! EEZ!

It turned out that Xorg was eating all available memory and invoking the oom killer. Sigh.

I guess I could have figured this out without VNC, but I couldn’t reproduce the bug locally, so I watched as a remote user was working on the machine.

How To Quickly Find the Size of an Image

To find the size of an image, I usually use ImageMagick’s identify command. Unfortuantely, identify is horribly slow, especially for JPEG 2000 images (thanks to a very slow libjasper).

So instead of using identify:
identify -format "%wx%h" image.jp2

Use exiftool instead:
exiftool -s -s -s -ImageSize image.jp2

exiftool is 62.5 times faster(!!!) than identify for finding image size on my dual 2.0Ghz Athlon.

Timelapse: OSS Secrets

I thought I would share a couple of helpful GPL command lines that really get the job done if you want to animate a sequence of images.

First (via Mike) is news of the jhead project. Unbelievably the ImageCapture.app application that ships with Mac OS X cannot handle more than several thousand images. ImageCapture.app will copy all of the image files, but the number sequence wraps around and it overwrites thousands of the earlier images in the sequence!! jhead fixes all that by renaming all of the image files based on the EXIF timestamp in the JPG file. brilliant! Here is the commandline he recommends:

CODE:
  1. jhead -nfpx%Y%m%d-%H%M%S -dt -ft $*

Now you have a nifty sequence of hopefully hi-res images. One of the cool things about timelapse is you can shoot 5 megapixel images and then scale them down to NTSC (720×480) or HD (1920×1024) resolution. In fact if some crazy 5 megapixel video format comes out 10 years from now, you will be able to support that as well! (As an aside, the Digital Cinema releases that are dribbling out to theaters these days are at 2,000 pixels wide. Eventually that will go up to 4,000 pixels wide, but there are not currently projectors that can support that resolution!)

So anyway, megapixels. How do you scale the images without fudging it up? A little known fact is that most video that looks crappy because of “the video compression” actually looks crappy because of the way the video was scaled down to its postage stamp resolution. So here is what you do: Use the fantastic ImageMagick “convert” command to scale your images down at even higher quality than photoshop! for free! and without using a dumb GUI scripting language. You can read about image scaling in laborious detail or you can just use this command line:

CODE:
  1. convert  -filter sinc -resize 720×480 foo.JPG foo_ntsc.JPG

I put the following bash script into a makefile to process my timelapse library:

CODE:
  1. for i in *; do  if [  ! -e “$i/ntsc_jpg/” ]; then  mkdir “$i/ntsc_jpg”; for i in orig_jpg/*.JPG; do echo $i; echo convert  -filter sinc -resize 720×480 ntsc_jpg/`basename $i`;  done fi done

And finally I would like to share the “ghetto HD” format that VJ Science came up with for doing 16:9 format on an XGA projector. This command includes cropping to get my 1600×1200 images into 16:9 aspect ratio … if you have a different source resolution, I’m going to leave it to you multiply your image width by 9 and divide by 16 to figure out the how many pixels to crop on top and bottom. The idea is to crop first and then scale down. Although I guess in terms of quality it doesn’t matter the order.

CODE:
  1. convert  -crop 1600×900+0+150 -filter sinc -resize 1024×576 foo.JPG foo_xga.JPG

Now you’ve got a nifty sequence of beautifully scaled images. Time to make video! Which of the 7 bajillion video codecs are you going to use? My recommendation is to use ffmpeg to make an mpeg-2 “master” that you can distribute by uploading to youtube, archive.org, and so on. ffmpeg understands image sequences! So here is a quick way to get your mpeg-2 video (no audio). This command assumes your images are named like “IMG_0001.JPG” and so on … I know that doesn’t jive with the jhead naming I’ve outlined above, but you are a big unix haxor and can figure that out.

CODE:
  1. ffmpeg  -i “IMG_%04d.JPG” -b 10000 test.m2v

For my purpose I am building up a video library for doing VJ/video mixing stuff. In this use case video quality and decode speed is much more important than bitrate. Since decoding mpeg-2 “I” frames is about 3x faster than decoding “P” or “B” (difference) frames I use this command to get a high quality I-frame only mpeg-2 stream:

CODE:
  1. ffmpeg  -i “IMG_%04d.JPG” -vcodec mpeg2video -intra -qscale 4 test.m2v

You can get higher quality by dropping qscale down even lower, but I think if you do qscale=1 your video basically won’t be compressed at all :-) rajbot?

So there you have it! The basics of an Open Source timelapse production pipeline. I use these tools on Mac OS X. Of course they are available on GNU/Linux. And you can also get them working under windows using Cygwin … We need more timelapse!

Link to jhead project
Link to ImageMagick project
Link to FFmpeg project

How to quickly convert a bunch of JPEG2000s to JPEGs

Let’s say you have a directory full of jp2 files, and you want to convert them to jpg. The usual way of doing something like this is to use ImageMagick’s mogrify command:
mogrify -format jpg *.jp2
ImageMagick uses JasPer to decompress the jp2, and it is unbelievably slow. If you want to do the same conversion, but five times faster, use the free Kakadu software instead.

Here is a script that will quickly convert the jp2s in the current directory to jpegs. You will have to edit the paths to the Kakadu binary and library.

PYTHON:
  1. #!/usr/bin/python
  2.  
  3. “”
  4. mogrify -format jpg *.jp2 is taking 24.5 seconds/image.
  5. The same jp2->jpg process takes 4.5 seconds/image on the same box when using
  6. Kakadu, even when creating a temporary ppm file.
  7. You can get the free Kakadu binary here:
  8. http://www.kakadusoftware.com/
  9. This script operates on jp2 files in the current dir.
  10. “”
  11.  
  12. import commands
  13. import glob
  14.  
  15. files = glob.glob(“*.jp2″)
  16.  
  17. for file in files:
  18.     print “Processing “ + file
  19.    
  20.     cmd = “LD_LIBRARY_PATH=/usr/local/lib/kakadu /usr/local/bin/kdu_expand -i %s -o tmp.ppm” %(file)   
  21.     retval = commands.getstatusoutput(cmd)[0]
  22.     assert (0 == retval)
  23.  
  24.     cmd = “pnmtojpeg tmp.ppm> %s” % (file.replace(‘.jp2′, ‘.jpg’))
  25.     retval = commands.getstatusoutput(cmd)[0]
  26.     assert (0 == retval)
  27.  
  28. from os import unlink
  29. unlink(‘tmp.ppm’)

Simple Timer for OS X

Jess needed a simple timer that would beep after 10 minutes, and asked if one shipped with OS X. Sadly, there isn’t one, and my first thought was to search VersionTracker for a timer. But I was feeling lazy and didn’t want to have to test 50 different crappy timers written in RealBasic and another fifty MyFirstCocoaApp projects. Also, I was feeling too cheap to shell out $50 for EnterpriseTimer.jar.

My next thought was to just echo ^G (the beep character) in Terminal after sleeping for 10 minutes, but how was I going to explain to Jess that you have to type ‘echo control-v control-g’ to put the beep character on the command line? So on a lark I tried typing ’say beep’ on the command line and it worked.

So here is your absolutely free 10 minute timer for OS X. Launch Terminal, which is the Utilities Folder inside your Applications folder, and copy/paste this line into the command line:

sleep 600; say beep

Hit return to start the timer. When it’s done, you can start another one by hitting the up-arrow and then hitting return. 600 is the number of seconds to sleep, and you can change this to be larger or smaller.

From across the living room I occasionally hear Jess’ mac saying ‘beep’ in the Vicki voice. It’s very cute :)

How to render text using HTML Canvas

I’ve been using HTML5 Canvas for a few web apps, and for the last year I’ve been avoiding rendering any text because Canvas lacks text support. Over the last year, several people have come up with workarounds.

  • Firefox decided to add a non-standard method called drawWindow(), which lets you composite a hidden iframe with html text.
  • The TextCanvas project adds a drawString method to the canvas api, which positions a HTML element on top of the canvas.
  • The Variable Width Canvas Fonts project pre-generates an image containing characters at known locations and then uses drawImage to display the necessary characters.
  • The very cool CanvasPaint project went nuts and implemented vector fonts in canvas! (more info here)
  • None of the above links work in Safari. Despite being the original developers of Canvas, Safari’s Canvas support is extremely buggy. Things work better with the nightly builds, but even then, many things are broken.

I’ve been thinking about giving up on supporting Safari completely, and maybe trying out dojo’s gfx 2D graphics API, which has text support but uses SVG/VML instead of Canvas. For the time being though, I found a silly workaround. Since I only need to display numbers, I can just create 10 pngs, one for each digit. Here is a bash script that creates the number pngs using ImageMagick:

CODE:
  1. for ((i=0;i<10;i++)); do
  2.      convert -size 75×100 xc:transparent -quality 100 -font Courier-Bold -pointsize 144 -fill green -draw “text -5,95 ‘$i’” g$i.png;
  3. done

Here’s a blurry screenshot of how it looks:
6.jpg

The best WordPress theme ever!

This guy gave his WP blog a command-line interface! It’s really well done.. I love how even the graphics look like they are on a green monocrome display!

I Just Hosed My System

Hey, probably not a good idea do this on your Mac OS X machine:

sudo mv Security.framework Security-1046.framework

Good lord, every process uses PAM, which links to Security, so basically you won’t be able to launch or use any programs, even command line. In particular you can’t use “sudo mv” to fix what you broke because sudo, of course, uses Security.framework for authentication. It’s pretty hilarious, kind of like messing with ld.so or libc.so on a Linux system.

To fix it, reboot, hold down command-S to boot into single user mode, follow the directions to make the filesystem read/write, and then use “mv” to fix it.

I’ve been dorking around more with /System days, just like I did with Linux lo those many years ago (well, it was /lib on Linux). I need to start watching TV or something.

How to create transparent PNGs

I wanted to create a transparent PNG, and couldn’t figure out how to do it easily until I remembered about netpbm. Here is how to create a transparent PNG on unix or OSX with the netpbm tools installed:

pngtopnm in.png | pnmtopng -transparent white -compression 9 > out.png

The -transparent white option specifies the color in your PNG file that should become transparent. You can also specify a RGB tuple by using -transparent rgb:ff/ff/ff

If the color you specified doesn’t exactly match an existing color in your image, netpbm will try to find the color that is closest to the one you specified and make that color transparent. If you don’t want netpbm to do this, you can use the =color syntax: -transparent =white

The -compression 9 option tells netpbm to use the maximum PNG compression level. If you are a compression nerd and want your PNGs even more efficiently compressed, check out OptiPNG.

Finally, if you need to find the RGB tuple of a particular pixel in your image, check out the DigitalColor Meter app in /Applications/Utilities/ on OS X.

reverse-menu-complete in bash

Shag helped me add reverse-menu-complete to my bash setup. It’s really easy, but undocumented. To get shift-TAB to menu-complete backwards, add the following line to your .inputrc:
\C-y:"\M--\C-i"

The \M– is actually a -1 argument to menu-complete (aka TAB, aka Ctrl-I). The info for Readline arguments describes how to pass numeric args to readline commands.

Reverse-menu-complete is useful to me since I have a FingerWorks keyboard with gestures for tab and shift-tab. The gesture stuff saves a ton of typing, which is good if you have RSI.

Here is my full .inputrc:
\C-y:"\M--\C-i"
TAB: menu-complete
set completion-ignore-case On