Some Bits: Nelson's log

19 posts in February 2012

OSM “interesting” columns

To better understand the OSM schema, I did a bunch of queries to find out which columns in which tables actually contained meaningful data. Kind of like the query about highway types I did, but for every single column. Then I went through by hand and copied out the “interesting” columns, ones that seemed to have a lot of data.

Here’s a big list by table, then column, then  the distribution of the values in that column. SF Metro only. One thing that’s clear; even in SF the data’s not complete enough to be an unbiased sample. For instance you can’t tell from OSM how many Jewish synagogues there are vs. how many Christian churches, the data’s just not complete enough.

Table planet_osm_line has 62256 rows

aeroway
99% 62093 None
 0% 143 taxiway
 0% 16 runway
 0% 3 apron

bridge
96% 60376 None
 3% 1872 yes

foot
96% 60024 None
 3% 2060 yes
 0% 117 permissive

highway
46% 29165 residential
14% 8897 service
10% 6307 None
 8% 5252 footway
 3% 1870 motorway_link
 2% 1841 tertiary
 2% 1765 secondary
 1% 1150 motorway
 1% 1113 unclassified
 1% 1063 path

man_made
98% 61560 None
 0% 618 pier
 0% 62 pipeline
 0% 12 breakwater

oneway
85% 52927 None
14% 9163 yes
 0% 74 no

railway
97% 60397 None
 1% 787 rail
 0% 322 tram
 0% 314 subway
 0% 166 spur
 0% 79 platform
 0% 68 disused
 0% 58 abandoned
 0% 42 light_rail
 0% 19 monorail

route
98% 61516 None
 0% 420 bicycle
 0% 122 road
 0% 73 subway
 0% 39 tram
 0% 29 scenic
 0% 23 bus
 0% 18 ferry
 0% 8 hiking
 0% 4 railway

service
91% 56958 None
 5% 3588 parking_aisle
 1% 956 driveway
 0% 321 spur
 0% 191 alley
 0% 121 siding

tunnel
99% 62024 None
 0% 227 yes

waterway
97% 60497 None
 2% 1317 stream
 0% 345 canal
 0% 74 drain
 0% 12 river
 0% 7 dam
Table planet_osm_polygon has 39872 rows

aeroway
99% 39841 None
 0% 17 apron
 0% 9 terminal
 0% 3 aerodrome
 0% 1 serodrome
 0% 1 boundary

amenity
92% 36797 None
 5% 2098 parking
 1% 416 school
 0% 81 restaurant
 0% 71 place_of_worship
 0% 51 fast_food
 0% 30 library
 0% 27 hospital
 0% 25 bank
 0% 19 toilets

building
60% 24237 yes
19% 7585 None
12% 5165 residential
 5% 2196 house
 0% 228 school
 0% 106 tank
 0% 55 apartments
 0% 54 retail
 0% 35 garages
 0% 34 terrace

leisure
94% 37581 None
 2% 875 pitch
 2% 847 park
 0% 177 playground
 0% 113 common
 0% 71 swimming_pool
 0% 47 golf_course
 0% 47 garden
 0% 31 sports_centre
 0% 24 track
Table planet_osm_point has 30916 rows

aeroway
99% 30763 None
 0% 107 gate
 0% 36 helipad
 0% 8 aerodrome
 0% 1 seaplane_base
 0% 1 checkin

amenity
73% 22602 None
 3% 1225 restaurant
 3% 997 place_of_worship
 3% 945 school
 2% 687 fire_hydrant
 1% 500 post_box
 1% 421 cafe
 0% 266 fast_food
 0% 263 bench
 0% 256 parking

highway
68% 21209 None
13% 4047 turning_circle
 5% 1850 traffic_signals
 4% 1534 crossing
 3% 979 bus_stop
 2% 903 stop
 0% 189 motorway_junction
 0% 184 mini_roundabout

leisure
97% 30131 None
 1% 524 park
 0% 151 playground
 0% 27 sports_centre
 0% 13 garden
 0% 10 slipway
 0% 9 designated smoking area
 0% 8 common
 0% 8 swimming_pool
 0% 8 picnic_table

man_made
99% 30620 None
 0% 100 water_tower
 0% 85 tower
 0% 30 crane
 0% 22 pier
 0% 12 monitoring_station
 0% 10 water_tank
 0% 6 mine
 0% 5 survey_point
 0% 4 lighthouse

natural
99% 30718 None
 0% 86 peak
 0% 44 bay
 0% 28 beach
 0% 18 tree
 0% 8 wood
 0% 7 spring
 0% 4 wetland
 0% 2 cave_entrance
 0% 1 cliff

power
93% 28782 None
 6% 2038 tower
 0% 90 pole
 0% 3 sub_station
 0% 2 station
 0% 1 generator

railway
97% 30282 None
 0% 260 level_crossing
 0% 168 tram_stop
 0% 63 subway_entrance
 0% 60 station
 0% 54 switch
 0% 21 crossing
 0% 4 turntable
 0% 3 buffer_stop
 0% 1 stop

religion
96% 29948 None
 3% 937 christian
 0% 14 jewish
 0% 12 buddhist
 0% 3 muslim
 0% 1 unitarian
 0% 1 scientologist

OSM unclassified lines, etc

I had a little todo item today, “Edit OpenStreetMap”. Thought it’d be fun to try out the editor. After 10 minutes I declare failure with Potlatch; the Flash app on the main server is so terribly slow as to be unusable. I need to read the Beginner’s Guide and other editing options.

After a bit of patience, Potlatch loaded usefully. I ended up editing the map to put a name on the tiny little Duncan-Castro park. I hope I did this right, the UI for adding a name to a park is not clear. I ended up using the Advanced view to add a name=Duncan-Castro field to the list for the way.

My big plan was to edit one of the 6000+ entries in the SF Metro extract that have no “highway” tagged on them. Turns out that’s not necessary; they tend to be other features, like creeks or county boundaries or stuff. D’oh.

I did find one entry for an uncategorized “Center Street” in SF, osm_id 8489931. But there’s so many other overlapping “Center Streets” in the database I think the fact this one is untagged is not a problem.

select
  name,
  ST_Length(ST_Transform(way, 2163))/1609 as miles
from planet_osm_line
where
  highway is null
order by miles desc;

"Golden Gate National Recreation Area";50.114480677903
"";50.1127120036684
"San Francisco";50.1127120036684
"San Mateo County";49.8960294825062
"";49.6164354346274
"Alameda County";49.5445744035326
"";49.3526266530211
"San Francisco County";49.3158064558191
"";49.2591797769354
"";49.2302041734416
"";49.2049183432214
"";49.1809376585467
"";49.0948344172935

Playing with OSM data, in TileMill

I revisted my earlier OSM experiment only using TileMill instead of QuantumGIS to make the map. TileMill has much nicer output, particularly if you want to ship a set of slippy map tiles or frame out specific high quality images / prints. It’s also more of a textual programming kind of paradigm, which I like better. OTOH TileMill also has very specific limits on what it’s capable of doing; it’s not a generic GIS toolset.

It was pretty easy; the hardest part was remembering the weird way to filter a table with select in TileMill; their PostGIS support is a bit idiosyncratic. Also it guessed wrong on the SRS for my tracks; they’re in WGS84 but it was trying to draw them as if they were in Google Mercator, way out of scale. That seems like a bug.

Anyway, I remade my map of my walks around SF, here’s an image and some code.

        "table": "(select * from planet_osm_polygon\n where leisure = 'park'\n  and geometrytype(\"way\") in ('POLYGON', 'MULTIPOLYGON')\n) as parks",
        "table": "(select * from planet_osm_line\n where \"railway\" is null\n) as road",

@road: #444444;
@border: #222222;
@park: rgb(196, 243, 170);
@water: #b8dee6;
@bg: #ffffff;
@track: rgb(237,101,22);

Map { background-color: @water; }

#sanfrancisco {
  polygon-opacity:1;
  polygon-fill:@bg;
  line-width: 2;
  line-color: @border;
}

#tracks {
  line-color: @track;
  line-width: 3.0;
}
#road {
  line-color: @road;
  [highway='motorway'] { line-width: 3.0; }
  [highway='motorway_link'] { line-width: 2.0; }
  [highway='footway'] { line-width: 0.7; line-color: lighten(@road, 20%); }
}
#parks {
  line-color: @border;
  line-width: 1.0;
  polygon-opacity: 1;
  polygon-fill: @park;
}

OpenStreetMap schema griping

OpenStreetMap is all kinds of awesome, but boy the data schema is a mess. planet_osm_roads doesn’t really contain all the roads, you want planet_osm_line. (Yes, one name is singular, one is plural). planet_osm_line sure contains a lot of lines, what are they all? The “highway” column tells you. here’s the most popular types of “highway” in the San Francisco metro extract.

select
  count(*) as cnt, highway
from planet_osm_line
group by highway
order by cnt desc;

  cnt  |        highway        
-------+-----------------------
 29165 | residential
  8897 | service
  6307 | 
  5252 | footway
  1870 | motorway_link
  1841 | tertiary
  1765 | secondary
  1150 | motorway
  1113 | unclassified
  1063 | path
   959 | track
   890 | primary
   712 | steps
   594 | cycleway
   191 | trunk
   150 | primary_link
   116 | pedestrian
    65 | trunk_link
    44 | construction
    39 | road
    35 | secondary_link
    24 | tertiary_link
     3 | footway_unconstructed
     2 | raceway
     2 | proposed
     2 | bridleway
     1 | service; residential
     1 | platform
     1 | crossing
     1 | living_street
     1 | abandoned
(31 rows)

It’s not terrible; things that are correctly classified really are. But “all roads” requires identifying several classes, there’s some ambiguity, and some stuff clearly doesn’t belong there. Still the data exists and is free, so I shouldn’t complain too much!

(Migurski’s High Road is a set of SQL views that present a cleaner schema of roads. But just roads, nothing else.)

Playing with OSM data

I’m playing with OpenStreetMap data in PostGIS, drawing maps in QGIS. No serious cartography, mind you, just trying to get a feel for the data. I’m starting with Mike Migurski’s metro extracts, the .osm.bz2 file for San Francisco

Import that into PostGIS, which gives this schema which describes these map features.

osm2pgsql -d walks --style /usr/share/osm2pgsql/default.style san-francisco.osm.bz2

For the SF metro, there’s 8000 roads, 40,000 polygons, 31,000 points, and 62,000 lines. You can import all these tables directly from pgsql into QGIS and render them for a basic view. The lines contain the street grid; roads contains just the larger highways, etc.

QGIS makes it easy to explore the tables. When you add a new PostGIS layer and choose a table, you can then choose specific fields and sample their values. Exploring around you can find that “leisure=park” is an interesting subset of polygons, for instance.

Roads are terribly complicated, so to simplify I tried using Migurski’s High Road. It creates custom views with names like “planet_osm_line_z14” where just roads relevant at that zoom level are present. Also some fancy stuff to make drawing casings vs. road surfaces easier. z15plus is the big set of all roads (170,000); _big is 24000 roads and _small is the other 144,000 lines (footpaths and such). Unfortunately QGIS can’t use the High Road views; details in this issue I filed.

I was able to use the High Road code as a guide for categorizing road by size, though. The “highway” field is the key one. It’s a messy schema, there’s about 7 synonyms for “street”.

Here’s a map of the walks I’ve taken in my neighborhood, with streets and parks.

 

Scraping GPX files out of RunKeeper into Postgres and QGIS

I’ve been using RunKeeper to track my walking. I wanted to work with the 40+ GPS tracks they’ve logged for me and didn’t want to download them one at a time. Some quick notes on how to scrape them all out.

  1. Log into the website in your browser and go to your Activities page. It has a URL like http://runkeeper.com/user/USERNAME/activity/70000177
  2. Save that big HTML page to a file named activities.html
  3. Capture the IDs of all your activities from that page with a regexp like this:
    printMatches  ‘link=”/user/USERNAME/activity/([0-9]+)’< activities.html > ids
  4. You can now download a GPX for that ID with a URL like http://runkeeper.com/download/activity?activityId=70000177&downloadType=gpx. However, the download requires a URL, at least if your activities are private.
  5. Look in your browser for your JSESSIONID cookie. That’ll stand in for a login.
  6. Use wget with that cookie. Here’s my little shell script to get them all
cat ids | while read id; do
  wget --no-cookies \
       --header 'Cookie: JSESSIONID=C~2BF2D2156284732CE8D8BDA900000000' \
       -O $id.gpx \
       "http://runkeeper.com/download/activity?activityId="$id"&downloadType=gpx";
done

Set up a PostGIS database with all the data

  1. createdb walks
  2. psql -d walks -f postgis.sql
  3. psql -d walks -f spatial_ref_sys.sql
  4. psql -d walks -f postgis_comments.sql
  5. for f in *gpx; do echo $f; ogr2ogr -append -f “PostgreSQL” PG:dbname=walks $f; done

ogr2ogr will create a fancy schema for you that contains every field ever seen in a GPX file. For RunKeeper data, the salient things are:

  • tracks.wkb_geometry: one row per track, multiline string
  • track_points: one row per point with a point, elevation, timestamp, etc.

QGIS did a fine job rendering the tracks table for me. I also pulled in a raster OSM map for a base layer from http://wms.latlon.org/.

Here’s a quicky query to get the length of a track in miles. Need to understand the ST_Transform better, also join to something else to get proper data about each imported track.

select name, ST_Length(ST_Transform(wkb_geometry, 2163)) /1609 as miles from tracks order by name;

A quicky view to simplify the tracks a bit, plus a query that compares the length of the original and simplified views.

create or replace view simple as
select
 ogc_fid,
 ST_Simplify(wkb_geometry,0.00005) as track,
 name
from tracks;

select
  tracks.name,
  ST_Length(ST_Transform(simple.track, 2163)) /1609 as miles,
  ST_Length(ST_Transform(tracks.wkb_geometry, 2163)) /1609 as miles
from simple inner join tracks
on simple.name = tracks.name order by name;

Multimarkdown reference

I’ve finally got an editing tool that does enough with Markdown to be useful: Notational Velocity. No WYSIWYG, but the live preview is pretty great. Shockingly there’s no really concise quick reference to all of Multimarkdown; it’s full of ugly complex stuff. The Human Markdown Reference is pretty good, but I made my own.

# Header 1
## Header 2
### Header 3

Text can be _italics_ or **bold** or `fixed width`.

> This is a blockquote.

*  lists are
*  implicitly formed

We can make [basic links](http://www.somebits.com). You can also do this [Stupid link style][1].

[1]: http://www.google.com/

    code samples come
    by indenting four spaces
    
| Features | Advanced? |
- | -
Tables | Yes
Paragraphs | No

----

Multi-markdown link: <http://fletcherpenney.net/multimarkdown>

Header 1

Header 2

Header 3

Text can be italics or bold or fixed width.

This is a blockquote.

  • lists are
  • implicitly formed

We can make basic links. You can also do this Stupid link style.

code samples come
by indenting four spaces
Features Advanced?
Tables Yes
Paragraphs No

Multi-markdown link: http://fletcherpenney.net/multimarkdown

GeekTools to show iTunes current song

I wanted to display the current song playing on my desktop using GeekTools. I found some info on accomplishing this with AppleScript here. Pretty straightforward, but their script is clever in that I think it only runs if iTunes is running. I modified the script a bit, here’s what I have:

tell application "System Events"
	set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
	if powerCheck = 0 then
		return ""
	end if
end tell
tell application "iTunes"
	try
		set playerstate to (get player state)
	end try
	if playerstate = stopped then
		return "Stopped"
	end if
	set trackID to the current track
	set trackName to the name of trackID
	set artistName to the artist of trackID
	set albumName to the album of trackID
	set totalData to artistName & "
" & albumName & "
" & trackName
	return totalData
end tell

Coffee

All the Internet sources I read say coffee is best brewed at 195F – 205F. This fancy new Keurig cup brewer I got maxes out at 192F, the “optimal temperature” according to them. Most home drip makers struggle to get to 190F.

Adding album art to Thinner’s MP3

The Thinner netlabel included JPG images for all their albums but didn’t embed them in the MP3 files. Consequently iTunes can’t find them. Dealing with id3 is a bit of a black art, the tools and formats are varied and poorly documented. But I think this works and is safe:

eyeD3 --to-v2.3 --add-image thn018.jpg:FRONT_COVER *.mp3

That adds thn018jpg as a front cover to all MP3s in the current directory. The converstion to 2.3 is necessary; eyeD3 can read but not write the 2.2 tags that are in the early Thinner releases. Note that this will add a second image if one already exists. Only safe to run once :-P

Getting clever:

#!/bin/bash
for d in thn*; do
 JPG=$d/$d.jpg
 if [ ! -f "$JPG" ]; then
 echo "$JPG not found, skipping directory"
 continue
 fi

eyeD3 --to-v2.3 --add-image $JPG:FRONT_COVER $d/*.mp3 > /dev/null
done

Sad fact: iTunes won’t display GIFs, only JPGs.

MacOS top: “stuck” means “uninterruptible”

MacOS’ version of “top” reports a weird process state; “stuck”. According to top many of my processes are “stuck” including Postgres while it’s completing a table scan, and Growl, and many Google Chrome subprocesses. But checking the top sources indicates “Stuck” really means TH_STATE_UNINTERRUPTIBLE, which I believe is what ps reports as process state “U”. I’m guessing this is what Linux calls “D” for “Device Wait”. In which case, in most cases the process is fine, it’s waiting for some I/O to complete.

While I’m here, is there any good reason MacOS top defaults to sorting by process ID? I have to type “ocpu” every time to get it to sort by cpu.

 

Trying to recover a Postgres database

When my old server died I had some data in Postgres. I don’t think it was anything important but I can’t really be sure, I’d like to recover it. All I have are the binary files Postgres stores its data in. Turns out recovering from those sucks. Lesson learned: if you care about recovering your data, back it up into a SQL dump.

Postgres makes no effort to make its binary files compatible between versions. A 9.0 database can’t be used in a 9.1 install; when you upgrade, you have to run a funky recovery tool which dumps the 9.0 db and imports it to 9.1. A 9.0 database on a 32 bit machine can’t be imported into 9.0 built for a 64 bit machine, either. I’ve also seen problems in the past trying to work with data from a PostGIS database in a non-PostGIS install. I’m sure this format flexibility makes it easier to build a fast database engine, but it sure makes data recovery difficult.

I tried building 9.0 sources on my amd64 box and running it. That was easy enough, although setting up users and permissions is a bit finicky when installing by hand. But the DB was generated on an i386 box (32 bit) so it won’t load. At least it failed quickly, “FATAL:  incorrect checksum in control file”. Then I started looking in to cross-compiling and realized the last thing I want is to set up a whole separate build toolchain. (A quick try with the linux32 command didn’t work.)

So screw it, what was I really storing in Postgres anyway? Not much, I did a quick test to see:

find . -type f -name \*py | xargs egrep -i ‘psycopg2|postgres’

Only one Python program I wrote even imports the Postgres driver. And I can recover that data from original sources. I think I have some geodata I imported with shp2pgsql, too, but I can redo all that. So I give up on recovering data.

Cross-compiling

Maybe I gave up too fast. Building a 32 bit version of Postgres on Ubuntu was as easy as

./configure CC=’gcc -m32′ --prefix=/tmp/pgsql90i386  --without-readline --without-libz

(there’s probably 32 bit versions of readline and libz, but I don’t really need them). Building a server this way, my amd64 machine can load the database binaries generated on the i386 machine. I had no idea the 64 bit Linux distributions could build 32 bit code so easily.

And it works! “psql -l” to find what databases were there, then “pg_dump database” to get the data out, then “psql” to get the data back into my 9.1 database. Yay!

Backups

Lesson learned, I’m now doing some simple nightly SQL backups of my databases. There are fancy ways to do this, I’m going very simple:

DEST=/mnt/sdb1/BACKUPS/postgres

set -eu
renice 10 $$ > /dev/null

pg_dumpall --lock-wait-timeout=$[5*60*1000] | gzip -9 >| $DEST/dumpall-sql.gz

 

secure remote backups with rsnapshot

I’m trying to back up my machine in a datacenter to my home server, using rsnapshot. The home machine is behind a firewall and pretty secure but I don’t want to be stupid about it. The remote machine should be secure, but is not firewalled. (OTOH both run ssh and http, so the attack surface is about the same). I found two useful guides for doing remote backups securely: one, two.

My final config is a pastiche of the two. Here’s the concept behind what I did. Backups run as root on the backup server and as a special-purpose user on the client being backed up (who can sudo to root to run rsync).

  • On the backup server, tell rsnapshot to backup a remote host via rsync.
  • On the backup client, create a new user who has no special privileges
  • Set up ssh keys (with no passphrase) so that root on the backup server can login as the backup user on the client. Restrict that ssh key to only be allowed to run an rsync frontend.
  • On the client, give the backup user the right to sudo to root but only to run /usr/bin/rsync.

I feel pretty good about the security; the user would have to steal my private key from the backup server to access the client, and even then they’re only restricted to run rsync. However that rsync is run as root and I’m sure could pretty easily escalate by, say, overwriting /etc/sudoers.

It’d be more secure to run backups on the remote client as some user other than root. But I want to back up files only root can read, so I’m kind of stuck.

 

Sonos id3v2 tags

Over on the Sonos forums I asked about which ID3v2 tags the Sonos uses. I got a great reply that seems to be correct, reproducing it here. It’s from Rick Parsons aka “renowden”.

TIT2 [Title/songname/content description] - commonly called Track

On the Sonos this is called “Track” and is available in an index and on the controller screen when the track is playing.

TPE2 [Band/orchestra/accompaniment] - commonly called Album Artist

On the Sonos this is called “Artist” as an index but does not appear on the display at all when a track is playing.

TPE1 [Lead performers(s)/soloist(s)] - commonly called Artist.

On the Sonos this is called “Contributing Artist” as an index. It shown on the display as “Artist” when a track is playing. In theory multiple artists can be put in this field (separated by a “/” but some tag editors show it as a “;”). In practice the Sonos sometimes shows only the last one on the list. I haven’t been able to determine why.

TALB [Album/movie/show title] - commonly called Album

On the Sonos this is used as an index. It also shows on the display when a track is playing.

TRCK [Track number/position in set]

This is not displayed anywhere but is used to determine the track order in albums.

TCOM [Composer(s)]

This is used as an index but does not show on the display during playback.

TCON [Content type] - commonly called Genre.

This is used as an index but does not show on the display during playback.

COMM [Comments] {iTunNORM}

This is written by iTunes and is discussed at length elsewhere. In summary it can, in the right conditions, be used to level the volume of playback.

There is another tag written by Windows media Player which performs a similar function to iTunNORM but I haven’t discovered what it is.

Canonical music genres

Still wrangling the metadata on my music library. ReadyToPlay did a good job on the rip and categorized all music into a relatively small set of Genres. I’m taking this as canonical for now.

Avant-Garde • Ballet • Blues • Chamber Music • Choral • Christmas • Comedy\Spoken • Concerto • Country • Electronica • Folk • Jazz • Keyboard • Latin • New Age • Opera • Orchestral • R&B • Rap • Reggae • Rock • Soundtrack • Spoken Word • Symphonic • Vocal Music • World

Well, not entirely canonical; I’ll probably unify a couple of these. Also the classical feels wrong to me: I couldn’t tell you Orchestral from Symphonic. I’d prefer to break it down by Musical era: Early, Baroque, Classical, Romantic, Modern. Of course those are ambiguous too.

One thing that’s really annoying in my metadata; music is indexed by the composer’s first name. So Tchaikovsky is filed under “P”, for “Pyotr Il’yich Tchaikovsky”. It’s a bit of a trivia game.

 

Metadata for .m4a apple lossless (ALAC) files

My new music library is all nicely ripped Apple Lossless files in .m4a containers. These contain metadata, but it’s not id3v2 and the universe of mp3 tools mostly don’t work. ffmpeg’s ffprobe sort of works but doesn’t show all tags.

What does work for displaying m4a metadta is mp4v2, installable via Homebrew. Docs here. It seems pretty stable but still gets some updates.

(imac) = mp4file --list test.m4a
BRAND  COMPAT              SIZING  FILE
----------------------------------------------------------------------
M4A    M4A,isom,mp42       32-bit  test.m4a

(imac) = mp4info test.m4a
mp4info version 1.9.1
test.m4a:
Track	Type	Info
1	audio	alac, 260.806 secs, 562 kbps, 44100 Hz
 Name: Pastourelle (E passo de dossai: Ah! viens pres de moi), folksong for voice & orchestra (Chants d'Auvergne, Series 2, No. 1)
 Artist: Dawn Upshaw
 Composer: Joseph Canteloube
 Release Date: 1994
 Album: Canteloube: Songs of the Auvergne
 Track: 1 of 15
 Disk: 1 of 1
 Genre: Vocal Music
 BPM: 0
 Part of Compilation: no
 Cover Art pieces: 1
 Album Artist: Kent Nagano
 Media Type: Movie
 TV Episode: 0
 TV Season: 0

(imac) = mp4track --list test.m4a
track[0] id=1
  type           = audio
  enabled        = true
  inMovie        = true
  inPreview      = true
  layer          = 0
  alternateGroup = 0
  volume         = 1.0000
  width          = 0.00000000
  height         = 0.00000000
  language       = UNDEFINED(0)
  handlerName    =
  userDataName   = <absent>

(imac) = mp4art --list test.m4a
IDX     BYTES  CRC32     TYPE       FILE
----------------------------------------------------------------------
  0     11255  299646cd  jpeg       test.m4a

(imac) = mp4tags
mp4tags: You must specify at least one MP4 file.
usage mp4tags OPTION... FILE...
Adds or modifies iTunes-compatible tags on MP4 files.

      -help            Display this help text and exit
      -version         Display version information and exit
  -A, -album       STR  Set the album title
  -a, -artist      STR  Set the artist information
  -b, -tempo       NUM  Set the tempo (beats per minute)
  -c, -comment     STR  Set a general comment
  -C, -copyright   STR  Set the copyright information
  -d, -disk        NUM  Set the disk number
  -D, -disks       NUM  Set the number of disks
  -e, -encodedby   STR  Set the name of the person or company who encoded the file
  -E, -tool        STR  Set the software used for encoding
  -g, -genre       STR  Set the genre name
  -G, -grouping    STR  Set the grouping name
  -H, -hdvideo     NUM  Set the HD flag (1\0)
  -i, -type        STR  Set the Media Type(tvshow, movie, music, ...)
  -I, -cnid        NUM  Set the cnID
  -l, -longdesc    NUM  Set the short description
  -L, -lyrics      NUM  Set the lyrics
  -m, -description STR  Set the short description
  -M, -episode     NUM  Set the episode number
  -n, -season      NUM  Set the season number
  -N, -network     STR  Set the TV network
  -o, -episodeid   STR  Set the TV episode ID
  -P, -picture     PTH  Set the picture as a .png
  -s, -song        STR  Set the song title
  -S  -show        STR  Set the TV show
  -t, -track       NUM  Set the track number
  -T, -tracks      NUM  Set the number of tracks
  -w, -writer      STR  Set the composer information
  -y, -year        NUM  Set the release date
  -R, -albumartist STR  Set the album artist
  -r, -remove      STR  Remove tags by code (e.g. "-r cs"
                        removes the comment and song tags)

Using inline data: URLs for images

Looking at traffic stats and Google’s mod_pagespeed I thought of a way to optimize my blog a bit: replace some of the small images with inline data: URLs. According to Wikipedia this works in all modern web browsers. IE7 is out of luck, but it (kind of) works in IE8.

For example, this Creative Commons logo is a 1082 byte GIF. Small, but there’s a lot of overhead in doing an HTTP request just for that image used in one place on my page. Fetching with wget takes 11 packets and 3 or 4 round trips. (A little better in a real browser with HTTP keepalives).

As a base64 data: URL it’s only 1467 bytes. That adds 1-2 TCP packets to the request and 0-1 round trips. The downside of inlining is that the image is now served with every single HTML page. No caching and bots will have to pay for it too. In the end I think it’s more work for my server, less work for the client, which is a good tradeoff for small images. (It may be less work for the server in general; fewer client requests per page.)

I arbitrarily decided 3k was the cutoff for converting to data URLs. That results in 5 images:

I converted the images via this online encoder. I am too lazy to measure the actual impact the change had, too much trouble. The HTML size of my blog went up 10k (46k vs 36k), but I’m loading 5 fewer HTTP requests (16 vs 20) and not loading about 7k worth of image binaries. I’m optimistic.