Cyrus Harmon's new completely useless blog


iso-media (MP4) files

posted by cyrus in Lisp

A couple of weeks ago, I wanted the ability to parse MP4 media files, and I couldn't find a parser in Common Lisp, so I wrote iso-media. iso-media, like the new version of retrospectiff, uses Peter Seibel's binary-data library. iso-media can be used to read and write MP4 audio and video files.

For example, the following code snippet loads an MP4 song into the special variable *cc*:

(eval-when (:compile-toplevel :load-toplevel :execute)  
  (ql:quickload 'iso-media))  
(cl:defpackage #:iso-media-scratch  
  (:use #:cl #:iso-media))  
(cl:in-package #:iso-media-scratch)  
(defparameter *cc*  
   #p"/Users/sly/Music/iTunes/iTunes Music/The Clash/Live At Shea Stadium/02 London Calling \\[Live].m4a")) 

And to see the name of the track:

ISO-MEDIA-SCRATCH> (track-name *cc*)  
"London Calling [Live]" 

Getting meaningful audio data out of the MP4 files is left as an exercise to the reader, but there are a number of handy functions for getting and setting iTunes metadata, for instance.

iso-media (MP4) files