Entries : Category [ Hacks ]
Computer and electronics tricks and fooling around
[Miscellaneous]  [Computers and Technology]  [Travel]  [Education]  [Hacks]  [Robotics]  [Science]  [Programming and Software]  [iPhone]  [Digital TV and Video]  [Intellectual Property & Copyright]  [Personal] 

28 September

Code was added here to allow postings to be rated by visitors. This is AJAX based, so rating an item does not cause a page reload unless it's clicked before the page has finished loaded (in which case the required javascript may not have been launched).

It can be obtained here as an XML file for Zope. WARNING: THE VERSION HERE WILL NOT WORK IF YOUR ZOPE IS BEHIND AN APACHE SERVER ON A DIFFERENT MACHINE. I fixed the software to handle this case, but have not prepared a xml archive yet. [ Nov. 2007]

By Gregory Dudek at | Read (3) or Leave a comment |    
Rate item 79: Rating: 8.6/10 (10 votes cast)
15 October

Tricks and incantations for resizing for iPhone, Android and other things

These are shell incantations for transcoding video with ffmpeg, especially for the ipod or iphone. ffmpeg is one of several free open source video editing programs you can use. These recipes are here partly to make it easier for other people to find them, and partly for me to find them again.

The standard open-source programs for transforming video are ffmpeg and mencoder. Each is capable from reading video in many different files formats, and writing out video using many different video encoding options. Each is supported in some form on Mac OS X, Linux and probably Windows. Both use common source libraries. You can get ffmpeg at http://www.mplayerhq.hu/design7/dload.html in many forms, or else compiled for Win32 at http://sourceforge.net /project/showfiles.php? group_id=205275.

mencoder has more filters than ffmpeg for processing the video. ffmpeg supports more different input and output formats, including direct output to mp4 container files. mencoder support for non-avi files is new and questionable, so for use with Quicktime you need to post-process with mp4creator: that's too much hassle for me, but instructions can be found at: mplayerhq.

My preferred solution is simply to use ffmpeg.

Basic command for iphone-compatible video
ffmpeg -i input-file -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 480x320 output-file

iphone (better setting than above)
ffmpeg -i "$INFILE" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 480x320 -aspect 4:3 "$OUTFILE"

This should be fine with any ipod-like device, but it is customized for the iPhone screen size. The -s 480x320 refers to the size of the iPhone screen; customization for the video iPod would use the same incantation, but with a screen size of 320x240 to produce slightly smaller files. On the other hand, showing the video on TV would benefit from the larger size, or even 640x480. The Apple TV uses as much as 1280x720. (It is never worth using a larger size than your input footage, however, which is often limited to 640x480 for NTSC.) Thus, for the ipod video is might be:

ipod video
ffmpeg -i "$INFILE" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 "$OUTFILE"
Other more exotic settings are the following:

sample separate image frames to jpeg images
ffmpeg -i "$INFILE" -y -ss 5 -an -sameq -f image2 -r 1/4 frame%03d.jpg

remove logo(from) from commercial video with lavc mpeg4 codec, avi container
mencoder -vf "delogo=545:401:100:45" -ovc lavc -lavcopts vcodec=mpeg4:acodec=libfaac 002.mpg -o 002.avi

Contrast enhancement (not recommended, can confuse compression)
mencoder -ovc lavc -lavcopts vcodec=mpeg4:acodec=libfaac -vf pp=autolevels:f 002.mpg -o 002.avi

WARNING: note that the -i inputfile flag needs to come early otherwise the resize (resizing/rescaling) flag -s will not have any effect. This is incredibly stupid, yes. At one point I found it didn't work and it took me a long time to figure out the problem that caused my resize to fail.

If you want to play with these, a quick guide to the key (somewhat obscure) ffmpeg parameters are as follows:

`-title string'

Set the title.

`-b bitrate'

Set the video bitrate in bit/s (default = 200 kb/s).

`-ss position'
Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.

-r fps
Set to frame rate

`-s size'
Set frame size. The format is `wxh' (ffserver default = 160x128, ffmpeg 
default = same as source). A few of the many allowed appreciations are:
`-maxrate bitrate'
Set max video bitrate (in bit/s).
`-minrate bitrate'
Set min video bitrate (in bit/s).
`-ar freq'
Set the audio sampling frequency (default = 44100 Hz).
`-ab bitrate'
Set the audio bitrate in bit/s (default = 64k).
`-ac channels'
Set the number of audio channels (default = 1).
Disable audio recording.
`-acodec codec'
Force audio codec to codec. Use the copy special value to specify
that the raw codec data must be copied as is.

By Gregory Dudek at | Read (8) or Leave a comment |    
29 March

I recently configured a Linux (Ubuntu) web server for SSL support. I had not done this for a long time, and had largely forgotten how. Here is the recipe and a fix to this problem.

Prologue: making your own SSL certificates

The easy solution to generating self-signed certificates needed for SSL is the the CA.pl perl script, which is included in the openssl installation tar ball. You can find it at
or else Google for "openssl-0.9.8 tar gz".

You need to generate suitable security keys (certificates) before you can use SSL. This can be accomplished using these steps from a suitable configuration directory:

perl CA.pl -newca
perl CA.pl -newreq
perl CA.pl -sign

You will have to answer various questions. The questions are stored locally, so the actual answers do not matter much, except for the domain name.
In particular, you should enter your server host name (e.g. www.dudek.org) when asked for a "common name".
This should produce the files newcert.pem and newkey.pem in the current directory.

Setting up Apache to use SSL

The apache2 configuration section for SSL then needs to use these keys with lines like:

SSLCertificateFile /etc/apache2/ssl/newcert.pem
SSLCertificateKeyFile /etc/apache2/ssl/newkey.pem

Whoops: error -12227

After this I was getting the error in my log file

OpenSSL: Exit: error in SSLv3 read client certificate B

which leads to an error -12227 from Firefox when the site is accessed.

After searching Google I found other people complaining about this, but with no actual diagnosis. Well, I have the answer. Looking at the error logs, I found that it was due to having configured apache/ssl for client authentication without having provided suitable certificates (the detailed story is that apache needs to understand you are acting as your own certificate authority, and not depending on an external one).

Solution to error: SSLCACertificate

The fix is to change the line in the apache config file that reads:

SSLCACertificate require

to instead read

SSLCACertificate none

After that, it should all work.

CA.pl manual page: http://www.openssl.org/docs/apps/CA.pl.html

SSL configuration explanation:

Ubuntu instructions (good) which avoids using CA.pl:


More user's stories:

By Gregory Dudek at | Read (3) or Leave a comment |    
10 April

Python includes a uudecode and uuencode module (accessible via "import uu"), but the module only supports base32 uudecoding, and not base64. I needed base64. Although I have posted an official patch to the python2.4 library, python had already moved on to a later version. Here is my patch for python2.5 uu.py to make it able to decode and intrepret base64 data. Encoding in base64 is probably pretty easy too, but I don't need it and have not bothers. I encourage somebody to add it.

One problem in applying this patch, especially from a web page, is that the white space versus tabs might not match. The - l flag (that's a lower case L) tells patch to ignore white space, but since python is senseitve to white space, you might have to adjust things manually.

Also note that on OS X, the uu.py module can be found at

The patch file (input for patch -l) is as follows:

--- uu.py.orig 2007-08-25 23:42:35.000000000 -0400
+++ uu.py 2007-08-26 11:42:54.000000000 -0400
@@ -18,6 +18,9 @@
+# Modified by Gregory Dudek, April 2008:
+# - added support for decoding of base64 uuencoded files.
# Modified by Jack Jansen, CWI, July 1995:
# - Use binascii module to do the actual line-by-line conversion
# between ascii and binary. This results in a 1000-fold speedup. The C
@@ -81,7 +84,7 @@
out_file.write(' \nend\n')

-def decode(in_file, out_file=None, mode=None, quiet=0):
+def decode(in_file, out_file=None, mode=None, quiet=0, base64=0):
"""Decode uuencoded file"""
# Open the input file, if needed.
@@ -100,9 +103,10 @@
if hdr[:5] != 'begin':
hdrfields = hdr.split(" ", 2)
- if len(hdrfields) == 3 and hdrfields[0] == 'begin':
+ if len(hdrfields) == 3 and (hdrfields[0] == 'begin' or hdrfields[0] == 'begin-base64'):
int(hdrfields[1], 8)
+ if hdrfields[0] == 'begin-base64': base64=1
except ValueError:
@@ -130,11 +134,13 @@
s = in_file.readline()
while s and s.strip() != 'end':
- data = binascii.a2b_uu(s)
+ if base64: data = binascii.a2b_base64(s)
+ else: data = binascii.a2b_uu(s)
except binascii.Error, v:
# Workaround for broken uuencoders by /Fredrik Lundh
nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
- data = binascii.a2b_uu(s[:nbytes])
+ if base64: data = binascii.a2b_base64(s[:nbytes])
+ else: data = binascii.a2b_uu(s[:nbytes])
if not quiet:
sys.stderr.write("Warning: %s\n" % str(v))

By Gregory Dudek at | Leave a comment |    
Rate item 113: Rating: 16.4/10 (8 votes cast)
23 April

My iPhone has been syncing to the wrong calendar in iCal. Here is a simple procedure for merging two calendars together using iCal on OS X. This allows you delete one of the calendars after combining it with another.

1) Use the Export option in the File menu to export the calendar (A) data from the calendar that is to be removed. Export to a file.

2) Select the calendar (B) into which you want to merge the data.

3) Use the Import menu to import the file saved in step 1. This should bring all the events from the calendar A into calendar B.

3.5) Verify that the events in the to-be-deleted calendar is now appearing twice (once for each of the two calendars (A and B) it is now in).

4) Delete the now-redundant calendar B.

By Gregory Dudek at | Leave a comment |    
15 May

I was using the zope server to generate barcode images using PIL, and
found one of my PIL methods was throwing a python error when used in Zope (from an external method), but not otherwise.

The error is a follows:

Error Type: AttributeError
Error Value: 'module' object has no attribute '_save'

The reason for this is that JpegImagePlugin.py
called a module called ImageFile from the PIL library, but Zope also defined a (different) module called ImageFile. Argh!!

Fixing this (for me) involved going into JpegImagePlugin.py
and replacing the line "import ImageFile"
with "from PIL import ImageFile".

A quick fix that took a very long time to track down. This solution is provided here to help the next hapless soul who tries Googling for this error like I did. Now there is at least one solution out here, instead of just queries.

You can see the fixed method in action at


or use
to generate you own code, where the number after the s needs to be 12 digits for an EAN-13 barcode (the 13th checksum digit is computed automatically if not provided).

By Gregory Dudek at | Leave a comment |    
Prev  1   2   [3]   4   5   6   7   Next