2010-07-06

Intro to Video Streaming and Video Audio Codecs

Perm url with updates: http://xahlee.org/comp/streaming_video_notes.html

Intro to Video Streaming and Video Audio Codecs

Xah Lee, 2010-07-04

This page provides a survey of the current video/audio codecs, file formats, streaming tech, for streaming multimedia.

I need to setup embedded videos on my site as well sites i work for. So, today, i started a comprehensive study on video streaming. Here's some learning notes. (The last time i worked with video is in 1995-1997. At the time video streaming is still pretty much science fiction)

The technology involved for playing a video from a browser from a site, such as youtube, involves several separate technologies. Here's a summary of the basics:

  • video codec. The video file must be encoded into a standard format (i.e. sequence of bits). Usually this means using a praticular compression scheme. The encoding and decoding algorithm and format is called a codec. (examples are: H.264, MPEG-4, WMV, QuickTime, DVD-Video, ...)
  • audio codec. The audio part for the video must also be encoded, usually treated and stored separately from the video. (examples: MP3, AAC, WAV, AC-3 (Dolby Digital), FLAC, ...)
  • multimedia container format. The encoded video/audio file(s) is saved in in a container file format. That is, a file format that contains video, audio, and other items such as subtitle. (examples: QuickTime's “.mov”, Microsoft's “.avi”, “wmv”, Adobe Flash, DVD, mpeg, ...)
  • streaming protocol. The file must be served in a special network protocol, e.g. by a streaming server. Because, it's not a normal file. You want users be able to watch the movie as it start to download, and usually play/pause the movie anytime.
  • application support. The web browsers must have special code/plugin for movie files so that for example a movie file will display screenshot even when not playing, and show the play/pause buttons, view in full screen, etc. (popularly done with Adobe Flash plugin. Or Java, or HTML5's video tag.)

Video Codecs

H.264

H.264 (aka MPEG-4 part 10, AVC (Advanced Video Coding)). It is currently the most popular video codec. It is used in Blu-ray Disc, YouTube, iTunes, and many nation's broadcasting and other video related applications. See: List of video services using H.264.

First version of H.264 was completed in 2003-05.

VP8

A competitor to H.264 is the VP8. Currently owned by Google and released as open source. VP8 is endorsed by FSF.

The associated container format with VP8 is WebM. WebM format is also free, and is based on the free Matroska container format.

WebM file format, is competing to be the default video format for HTML5 video.

WMV (VC-1)

Windows Media Video (WMV), refers to several video codecs from Microsoft, but mostly the latest WMV 9 (aka VC-1). WMV 9 is released to standard body and standardized as VC-1, in 2006. It is widely supported, and is used in Blue-ray Discs, Xbox 360, PlayStation 3. It's a competitor to H.264.

Besides WMV 9, there's 2 other codecs: WMV Screen and VMV Image. The screen one is optimized for screenshots, e.g. tutorials on using a application. The Image one is optimized for slideshows.

QuickTime

Another widely used one is from Apple's QuickTime. (see below)

Others

Sorenson codec

Sorenson codec refers to 2 proprietary codecs. Quote:

  • Sorenson Video (aka Sorenson Video Codec, Sorenson Video Quantizer, SVQ). Used by Apple's Quick Time, but is phased out in mid 2000s.
  • Sorenson Spark (aka Sorenson H.263). Used by Adobe Flash, but is phased out in mid 2000s.

Theora

Theora is a free lossy video compression codec. The technical quality of Theora is not as good as H.264 or VP8. It is based on VP2 format of 2002, then a proprietary format by On2 released as free. It is not widely supported. Theora is usually stored in the Ogg container format, together with the free lossy audio codec Vorbis.

DivX and xvid

DivX started as a open source project in ~2000 but became proprietary, and Xvid is forked from it. Both are usually used as the format from ripped DVDs. Both do not particularly define new codecs or container formats, rather, they are based on some subset of MPEG-4 standard and other container formats. It began as a reverse-engineer of Microsoft's MPEG-4 version 3 codec.

Audio

There are tens of audio codecs, some are lossy, some lossless. Here's some popular lossy ones:

  • MP3, from the standard MPEG-1 Audio Layer 3. Most popular. Started the digital music era in late 1990s.
  • AAC, lossy. Used in iTunes, iPod, iPhone, etc. Much better than mp3.
  • Windows Media Audio (WMA). Microsoft's answer. WMA is part of Microsoft's Windows Media framework. WMA can refer to 4 codecs: WMA, WMA Pro, WMA Lossless, WMA Voice.
  • Vorbis. Open source. Typically used together with the Ogg container format. Superior to mp3, and probably inferior to AAC.

There are a number of free and lossless codecs for audio. Most popular is probably FLAC. Lossless audio codec typically compress a music file by 50%.

For audio file formats (not compresed), the most popular ones are: Microsoft's WAV and Apple's AIFF. These are pretty old, starting in early 1990s. Note that both formats actually support compression, but audio stored in these formats are almost always not compressed.

Note that 300 kilo bits per sec gets you CD quality audio (using a lossy compression). While a DVD quality video is about 5 mega bits/s. That's about 17 times more.

The need for audio codec research has past. Computer storage and processing power today can deal with audio no problem, and use of lossless codec for audio is increasingly popular. So, for issues of movie streaming, the video part is the primary concern.

Multimedia Container Formats

QuickTime (“.mov” or “.qt”) is Apple's container format. Widely used.

AVI is Microsoft's tech, fairly old, started in early 1990s. Widely used.

Advanced Systems Format (ASF) is Microsoft's container format, part of the Microsoft's Windows Media framework.

Matroska (“.mkv”) is free container format. Recently adopted by Google and re-branded as WebM, to be used together with VP8.

Ogg is another free multimedia container format. Its tech quality is often in dispute. It is used by Wikipedia.

QuickTime

Quicktime (QT) is Apple's multimedia framework. It supports audio and video, as well as interactive panoramic images, and including such things as midi. It supports many codecs for audio and video.

The file format of QT is “.mov”. Quote:

The QuickTime (.mov) file format functions as a multimedia container file that contains one or more tracks, each of which stores a particular type of data: audio, video, effects, or text (e.g. for subtitles). Each track either contains a digitally-encoded media stream (using a specific codec) or a data reference to the media stream located in another file. Tracks are maintained in a hierarchical data structure consisting of objects called atoms. An atom can be a parent to other atoms or it can contain media or edit data, but it cannot do both.[11]

QT 7.x is around from 2005 (OS X 10.4) to version 7.6 in 2009 (OS X 10.6). After that, the next version is QT X (10), which is supposedly completely rewritten for 64-bit computing and somewhat incompatable with past QT versions. Though, QT X relies on QT 7 for dealing with older codecs and other files such as MIDI.

Some more Wikipedia quotes:

QuickTime X is a combination of two technologies: QuickTime Kit Framework (QTKit) and QuickTime X Player.

... many Apple products (such as iTunes and Apple TV) still use the older QuickTime 7 engine.

QT Streaming

QuickTime Streaming Server (QTSS) is a server or service daemon built into Apple's Mac OS X Server that delivers video and audio on request to users over a computer network, including the Internet. Its primary GUI configuration tool is QTSS Publisher and its web-based administration port is 1220.

QuickTime Broadcaster is an audio and video RTP/RTSP server by Apple Computer for Mac OS X. It is separate from Apple's QuickTime Streaming Server, as it is not a service daemon but a desktop application.

Qtch

FFmpeg and VLC

FFmpeg is a open source project on video and audio tech. Three notable component from FFmpeg are:

  • libavcodec, an audio/video codec library used by several other projects.
  • libavformat, an audio/video container mux and demux library
  • ffmpeg command line program for transcoding multimedia files.

One interesting thing about the project is that it has a command line tool “ffmpeg” that lets you convert one video format to another.

VLC is a movie player. Originally designed as a server/client for streaming multimedia, but now is just a single application the VLC. Was at one point used by Google at Google Video until they switched to Flash. VLC can also be used on the command line.

Streaming Technologies

The following are the most commonly used protocols for Streaming media. Each with a particular purpose:

  • RTSP. e.g. send the play, pause, request from client.
  • RTP. e.g. the streaming media payload.
  • RTCP. e.g. monitor transmission statistics and QoS information.

The above combo are usually referred to as “RTSP/RTP”.

Adobe Flash uses its own Real Time Messaging Protocol (RTMP).

Microsoft was using Microsoft Media Server (MMS), but is preprecated in 2003. Now Microsoft uses RTSP.

HTTP Live Streaming is Apple's tech, new in 2009 with QuickTime X. It is different than others because it is HTTP based. Proposed as a internet standard.

Some detail: apple.com.

Here's a list of video hosting services: Comparison of video services. Contains some detail of what protocol they use.

See also: Comparison of streaming media systems.

Some References

Besides Wikipedia, here's some other articles i used for this article.

Comparison of codecs:

  • First Look: H.264 and VP8 Compared (2010-05-20), by Jan Ozer. Source
  • The first in-depth technical analysis of VP8 (2010-05-19), by Jason Garrett-Glaser. (a x264 and ffmpeg developer; college student) Source
  • Video on the Web (2009-03), by Till Halbach. (comparison of Dirac, Dirac Pro, Theora, H.264) Source
  • “[whatwg] H.264-in-<video> vs plugin APIs” (2009-06-13), by Chris DiBona (google employee) whatwg.org

Comparison of container formats:

  • Ogg objections (2010-03-03), by Mans Rullgard (ffmpeg developer). Source
  • In Defense of Ogg's Good Name (2010-04-27), by Christopher Montgomery (ogg designer). Source

Audio codecs comparison:

Misc:

  • Apple proposes HTTP streaming feature as IETF standard (2009-07-09), by Chris Foresman. arstechnica.com

2010-07-04

emacs camelCase movement

Perm url with updates: http://xahlee.org/emacs/blog.html

Want the cursor movement to stop between camelCaseLetters? Use “global-subword-mode” or “subword-mode”. (Thanks to Deniz Dogan for the tip.)

This tip is added to: Emacs Advanced Tips.

2010-07-03

Space Oddity by David Bowie

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/sanga_pemci/space_oddity_david_bowie.html

Space Oddity by David Bowie

Space Oddity, released in 1969, the same year human animals landed on the moon. It is one of the greatest ballad in music history. Eerily serene and catastrophic. Depicting love, and human animal's spacy aspiration, vuneralbility, and the beauty of the earth (in a anthropic perspective). A vernacular record of Human Space program. “check inignition and may God's love be with you”. God, this can put tears in my eyes.

Space Oddity, words and music by David Bowie.

Ground Control to Major Tom
Ground Control to Major Tom
Take your protein pills and put your helmet on
Ground Control to Major Tom
Commencing countdown, engines on
Check ignition and may God's love be with you

  (Ten, Nine, Eight, Seven, Six, Five, Four, Three, Two, One, Liftoff)

This is Ground Control to Major Tom
You've really made the grade
And the papers want to know whose shirts you wear
Now it's time to leave the capsule if you dare

This is Major Tom to Ground Control
I'm stepping through the door
And I'm floating in a most peculiar way
And the stars look very different today
For here, Am I sitting in a tin can
Far above the world
Planet Earth is blue
And there's nothing I can do

Though I'm past one hundred thousand miles
I'm feeling very still
And I think my spaceship knows which way to go
Tell my wife I love her very much she knows

Ground Control to Major Tom
Your circuit's dead, there's something wrong
Can you hear me, Major Tom?
Can you hear me, Major Tom?
Can you hear me, Major Tom?
Can you....

Here am I floating round my tin can
Far above the Moon
Planet Earth is blue
And there's nothing I can do.

CD version.

Thi song is a humanistic view of going into space. It elicits the weakness of human animals, the love in us, and the yearning and aspirations, in the backdrop of the vast expanse and mysteries of the universe.

Let's look at some of the words. The opening verse sets up the feeling of a historical undertaking, of going into far away in the sky, the distance involved, the danger.

Ground Control to Major Tom

This line notes the distance involved. Human communication, in lieu of talking face to face, now takes the unnatural form of “Ground Control to Major Tom”.

Take your protein pills and put your helmet on

Helmet's primary function is protection. The “protein pill” elicits food, a fundamental human need, in a advanced sci-fi form.

Commencing countdown, engines on
Check ignition and may God's love be with you

The line on “checking” ignition, reinforces the idea of danger. You wouldn't check it unless it is critical. And ignition means starting, a initiation. God is a conception tied to birth and function of the universe. In between these lines lie the clear message of the possibilities of never return, and our fundamental quest for the mysteries of the universe.

  (Ten, Nine, Eight, Seven, Six, Five, Four, Three, Two, One, Liftoff)

Then, the lyrics starts a explicit counting down. Count down is a activity done usually for events that's critical and or of major importance, sometimes with heavy emotional ties. Actually counting down makes you feel it. In new years we have count down. If you have seen NASA space shuttle liftoff, the counting down and liftoff is a emotional moment, making many involved teary, especially if for the first time. When you see something that weights tons hover and moves upwards by sheer human's work, in front of your eyes, it makes you feel nature, and our achievements.

You've really made the grade

Here, it uses the phrase “made the grade” to describe success. Quite funny. Making the grade refers to children's success in grade school. So now, going into space successfully, with regards to the universe, is “made the grade”.

And the papers want to know whose shirts you wear

A aspect of human animals, is gossip, and fawn around the powerful and successful, and hear and follow what the successful have to say. This is captured by the funny line of wanting to know whose shirt you wear. Note that T-shirts advertising a company is typical in modern capitalism states.

Now it's time to leave the capsule if you dare

In space missions, it's not a matter of daring. It's all carefully planned. By using “Now it's time” and “if you dare”, it invokes challenge. The complex scientific process and procedure is now translated into a children's line of “now it's time” and “if you dare”.

This is Major Tom to Ground Control
I'm stepping through the door
And I'm floating in a most peculiar way
And the stars look very different today
For here, Am I sitting in a tin can
Far above the world
Planet Earth is blue
And there's nothing I can do

The space capsule, a device that took human animals thousands of years to be able to build, is now described as a tin can. Tin is one of the cheapest and weakest metal. Calling it a tin can shows our vulnerability, and pettiness, with respect to the expansive universe.

The “Planet Earth is blue, And there's nothing I can do” shows our helplessness with regards to nature.

Though I'm past one hundred thousand miles
I'm feeling very still
And I think my spaceship knows which way to go
Tell my wife I love her very much she knows

Here the lyrics takes a tragic turn. When spaceship is dead, drifting in space, like a ship, it doesn't go anywhere meaningfully. When death is approaching, it is not uncommon to make ironic remarks.

Human animals have a binding love, that even one is to die, it is critical to communicate this metal state to the target, even if the target already deeply aware of the fact, and even no behavior or action whatsoever of this mental state of the sender will take place henceforth. However, such message will have significant impact on the receiver, a high-powered mental boost, that usually results in behaviors that increase the receiver's prosperity.

The ending reminds me of the ending of H G Wells's final chapter of Time Machine. That even with a tragic ending, one greatest element of humanity, is instilled in our minds. Quote:

And I have by me, for my comfort, two strange white flowers— shrivelled now, and brown and flat and brittle—to witness that even when mind and strength had gone, gratitude and a mutual tenderness still lived on in the heart of man.

Life on Mars (David Bowie)

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/sanga_pemci/david_bowie.html

Life on Mars (David Bowie)

Xah Lee, 2005-06, 2010-07-03

David Bowie (b1947) is a true artist in all the glory of that word.

“Life on Mars?” (1971), this is a great song. The lyrics is just fantastic. If i were to list top 20 greatest songs (not counting classical music), this would be in it.

Both lyrics and music are by David Bowie.

「• Lennon = what does Lennon refers to? Some web discussion suggest it may be John Lennon and or Vladimir Lenin. The suggestion for Lenin cites the line “the workers have struck for fame” inferring the proletariat in communism. While, Lennon connotes captilism, with his big records success. Some suggest it's a pun on both, since Lennon is a major peace activist in the Vietnam war era, running afoul with the US Government and FBI at the time, and have sympathies for communism. (For more about Lennon, see: I Met the Walrus.) 」
「• Ibiza = a island east of Spain. Ibiza
「• Norfolk Broads = A network of mostly navigable rivers and lakes in the English counties of Norfolk and Suffolk. (above London) Norfolk Broads
Ibiza Norfolk Broads
「• Rule Britannia = a British patriotic song. Rule, Britannia!
It's a god-awful small affair
To the girl with the mousy hair
But her mummy is yelling “No”
And her daddy has told her to go
But her friend is nowhere to be seen
Now she walks through her sunken dream
To the seat with the clearest view
And she's hooked to the silver screen
But the film is a saddening bore
For she's lived it ten times or more
She could spit in the eyes of fools
As they ask her to focus on

Sailors fighting in the dance hall
Oh man! Look at those cavemen go
It's the freakiest show
Take a look at the Lawman
Beating up the wrong guy
Oh man! Wonder if he'll ever know
He's in the best selling show
Is there life on Mars?

It's on Amerika's tortured brow
That Mickey Mouse has grown up a cow
Now the workers have struck for fame
'Cause Lennon's on sale again
See the mice in their million hordes
From Ibiza to the Norfolk Broads
Rule Britannia is out of bounds
To my mother, my dog, and clowns
But the film is a saddening bore
'Cause I wrote it ten times or more
It's about to be writ again
As I ask you to focus on

This vid is directed by Mick Rock, 1973.

Note the distinguished mark of David's pupils. Commonly thought to be a genetic condition known as Heterochromia, e.g. each iris has different color. That's not true. According to Wikipedia, the appearance of David's eye is a result of injury of the left eye. At age 15, he got punched by his friend George Underwood over a girl. Operation prevented it from being blind but left with imperfect vision and permanently dilated pupil.

Wikipedia has quite some detail about the meaning and background of the song. See: Life on Mars?.

胭脂泪 (Girl's Tears) by Teresa Deng

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/sanga_pemci/yan1_zhi3_lei4.html

胭脂泪 (Girl's Tears) by Teresa Deng

Xah Lee, 2010-06-17, 2010-07-03

This poem is composed by 李煜 (Li Houzhu) (936-978), known as the master of free-form verse. His topics is often pleasure making and womanizing.

Title: 胭脂泪 (yan1 zhi3 lei4)
Lyrics: 李煜
Music: 劉家昌
Translation: 李杀 (Xah Lee)
林花謝了春紅
太匆匆
無奈朝來寒雨晚來風

胭脂淚
留人醉
幾時重
自是人生長恨水長東
spring flowers have gone
so hasty
then morn rain, eve storm

girl's tears
ravishing and intoxicating
when again?
only seanons change, and time flies

For another of Li Houzhu's work sung by Teresa, see: 相见欢 (Union Joy).

How to View Comments in JPEG, PNG, MP3 files?

Perm url with updates: http://xahlee.org/img/metadata_in_image_files.html

How to View Comments in JPEG, PNG, MP3 files?

Xah Lee, 2010-07-02

This page shows you how to get the textual comments embedded in jpeg, png, gif, files.

The JPEG is actually just standard compression scheme. It does not actually define a file format. The file formats we usually associate with the name “jpeg” is actually the and Exif, JFIF.

JFIF format is the file format for images compressed using jpeg. Other than digital cameras, vast majority of jpeg images are stored in the jfif file format.

Exif is used by basically all digital cameras. The file contains info such as date time, camera settings, and thumbnail.

Metadata is also stored is various different formats, for files other than image files. For example, video files, and even text files. Two popular general-purpose metadata formats are: IPTC, XMP. There's also the ID3 format for MP3 audio files. There's also Mac OS X Extended Attributes.

What Info Are Embedded?

Metadata can be arbitrary, especially when using IPTC and XMP formats. There may be a lot info embedded in a image files, some can be a privacy issue. For examples:

camera model, camera serial number, camera settings (exposure, shutter, etc.), earth location coordinates (GPS), copyright info, description, summery, character encoding used, keywords (tags), ...

For audio files, it can be song name, composer, artist, album name, rating, sample rate, bps, encoding used, ...

How to View and Change Metadata?

Most good image editors or photo software should be able to show the metadata. On Windows, usually pressing “Alt+Enter” shows the metadata. Here's some example of software that will show metadata:

  • Picasa
  • Microsoft's Explorer (the folder viewer)
  • Microsoft's Windows Photo Gallery
  • Mac OS X Finder (Cmd+i)

Note: if you are not using a dedicated software, the info displayed by the above may not be ALL there is.

ExifTool

The ExifTool, by Phil Harvey, is a widely used popular tool for dealing with metadata in image files. It's available as a command line tool for Windows and unix, but also as a Perl module.

Download at: ExifTool home page.

On Windows, to display metadat, just drag and drop the file onto the icon. Though, it's best used as a command line tool. Just double click to read the doc on how.

To show metadata of a image file on command line, do for example:

exiftool myPhoto.jpg

To show metedata for all images in a dir, you can do for example:

exiftool *jpg

The file name ending can be “*png”, “*mp3”, etc.

Full documentation at: exiftool man page. Plain text version at: exiftool_man_page.txt

Sample Outputs

2010-07-02

OS X Extended Attributes and xattr

Perm url with updates: http://xahlee.org/comp/OS_X_extended_attributes_xattr.html

OS X Extended Attributes and xattr

Xah Lee, 2010-07-02

This article explains Mac OS X's Extended Attributes and the command line utility xattr.

So, i was working on OS X again. ( OS X 10.5) When i do “ls -l”, i noticed the “@” sign, e.g.:

-rw-rw-r--@  1 _www    admin  1046505 Nov 10  2007 collection.jpg

What the fuck is that? 10 years working in unixes, i haven't seen that before. So, some web search found me: Extended file attributes, and the new command line utility “xattr”.

What's Extended Attribute?

Here's a quote from Wikipedia:

Extended file attributes is a file system feature that enables users to associate computer files with metadata not interpreted by the filesystem, whereas regular attributes have a purpose strictly defined by the filesystem (such as permissions or records of creation and modification times). Unlike forks, which can usually be as large as the maximum file size, extended attributes are usually limited in size to a value significantly smaller than the maximum file size. Typical uses can be storing the author of a document, the character encoding of a plain-text document, or a checksum.

Mac OS X 10.4 and later support extended attributes by making use of the HFS+ filesystem Attributes file B*-tree feature which allows for named forks. Although the named forks in HFS+ support arbitrarily large amounts of data through extents, the OS support for extended attributes only supports inline attributes, limiting their size to that which can fit within a single B*-tree node. Any regular file may have a list of extended attributes. HFS+ supports an arbitrary number of named forks, and it is unknown if the Mac OS imposes any limit on the number of extended attributes. Each attribute is denoted by a name and the associated data. The name is a null-terminated Unicode string. The Mac OS X APIs support listing[2], getting[3], setting[4], and removing[5] extended attributes from files or directories. The xattr utility may be used from the Terminal as well.[6]

Extended Attributes are used to store author name, character encoding used, short comments, security/quarantine status, ... and basically any small amount of info about the file.

Note that standard data such as creation date, modification date, permission, are in contrast the normal attributes supported by the whole system. While, HFS/HFS+ file system's resource fork, widely used before Mac OS X , can be considered as a more elaborate extended attribute system, that it also hold main data of the file. (See: Mac OS X Resource Fork and Command Line Tips)

How to use Command Line for extended Attribute

Use “ls -l@ filename”

Apple also made some changes to “ls”. When you do a “ls -l” on a file, if the file has extended attributes, it'll display a “@” sign. You can also use “ls -l -@ filename” to show extended attributes. Example:

-rw-rw-r--@  1 _www    admin  1046505 Nov 10  2007 collection.jpg

Here's a quote from “man ls”:

If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a '@' character. Otherwise, if the file or directory has extended security information (such as an access control list), the permissions field printed by the -l option is followed by a '+' character.

Use xattr

There's no man page for xattr, but “xattr -h” gives a usage summary:

usage: xattr [-l] [-r] [-v] [-x] file [file ...]
       xattr -p [-l] [-r] [-v] [-x] attr_name file [file ...]
       xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...]
       xattr -d [-r] [-v] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
  -h: print this help
  -r: act recursively
  -l: print long format (attr_name: attr_value and hex output has offsets and
      ascii representation)
  -v: also print filename (automatic with -r and with multiple files)
  -x: attr_value is represented as a hex string for input and output
vmm:vmm xahlee$

What to Put in Extended Attribute?

Extended Attributes are name/value pairs. The names are Unicode characters of less than 128 bytes. (they are probably encoded in utf-8 or utf-16) The values can be text or binary, recommended to be less than 4kb.

There's not standardize structure for names. Anyone can add a attribute named for example “xyz” to a particular file. Apple recommends the use of reverse DNS naming scheme to prevent attribute name conflicts. This is the same scheme adopted by Java. Example:

com.apple.FinderInfo

If you have a domain name, such as “example.com” then your attribute name for file of author can be “com.example.author”. If you don't have a domain name, just make sure the name is not likely used by others.

2010-07-01

Google Analytics Asynchronous Tracking Code

Perm url with updates: http://xahlee.org/js/google_analytics_tracker_code.html

Google Analytics Asynchronous Tracking Code

Xah Lee, 2010-07-01

Few months ago, google released a new tracking code for Google Analytics, featuring asynchronous javascript. If you haven't updated yet, you should do it now. It increases your page load speed noticeably. When during busy times such as morning or noon, it speeds up 1 second or more.

Note that saving a fraction of a second matters. See: Speed Matters (2009-06-23) by Jake Brutlag. Source

This is their old code, in 2 blocks of javascript:

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-xxxxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}

This is their new code:

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
  })();

Some Analysis of The New Code

Let's study this new code a bit.

You can see that it first creates the variable “_gaq” if it is not already defined. Then it defines a anonymous function by:

function() {...}

then call it at the same time by

(function() {...}) ()

This is commonly known as lambda function or function expression.

The function basically constructs the following html code and insert it into the page.

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>

(or https version at “https://ssl.”.)

Now let's look at the js code “ga.js”. It is a condensed and obfuscated js code. It has a total of 25k chars. It has 839 “;”, and 383 “{}” pairs, and the “function” definition happens about 254 times. If you expand the code into lines, it's about over 1k lines, more likely close to 2k lines. See the files here:

The code seems to use a lot advanced functional programing, with lots of function expressions.

Strut, by Sheena Easton

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/sanga_pemci/strut_Sheena_Easton.html

Strut, by Sheena Easton

Xah Lee, 2010-07-01

Strut (1984).

「• Nations go to war = Do nations go to war over women? Sure, particular in the older times. Nations don't go to war, men do, powerful man. Male animals fighting for mates, is common in animal kingdom. We can see highschool boys fighting over girls, or even in corporate, and just about anywhere. The difference is a matter of civility. When society is still primitive, powerful men are tribe leaders. When they want a chick from yonder that may not belong to them, they go and grab it, with the support of his underling. You can see gangsters do it today. Chinese history and culture, is filled with stories of emperors going war with neighbor states to grab the wives or princesses. This is written in a poem for example: 佳人歌 (The Beauty Song).」
He said, “Baby, what's wrong with you?
Why don't you use your imagination
Nations go to war over women like you,
it's just a form of appreciation

Come on over here, lay your clothes on the chair
Now let the lace fall across your shoulder
Standing in the half light, you're almost like her
So take it slow like your daddy told you”
Strut pout, put it out, that's what you want from women
Come on baby, what'cha taking me for
Strut pout, cut it out, all taking and no giving
Watch me baby while I walk out the door
「• girl for hire = prostitute. It is not uncommon in animal kingdom, that females offer sex in exchange for food. (see: Demonic Males) In particular, this practice is common in human animals, taking many forms, from outright prostitution to concubine to trophy wives. Duo to biology, it is males that give provision to females for sustenance. And in courtship, males providing gifts to females, ultimately for the goal of sexual union. When this is done in a form like a business transaction, it is called prostitution. (See also: A Close Encounter With A Prostitute In Las Vegas.) 」
I said, “Honey, I don't like this game,
you make me feel like a girl for hire
All this fascination with leather
and lace is just the smoke from another fire”
He said, “Honey, don't stop a speeding train
before it reaches its destination
Lie down here beside me, oh, have some fun too
Don't turn away from your true vocation”

I won't be your baby doll, be your baby doll

The song is written by Charlie Dore (b1956) and Julian Littman. (not sure if it's the music composition or lyrics or both.)