Extracting Recording Date & Time from AVI film clips.

Last updated: 11 Jan 2010

Introduction

There seems to be little information around on the web over how to extract the recording-date and time from film clips. As digital film and photos allow people to record larger quantities of visual data, we also become dependent on having efficient ways of archiving this material. One important step in this process is to be able to identify the date and time a particular photo or film clip was taken. This page attempts to give some help on doing this in the Java language.

Relevant links

Read Eden's latest article:
Empowering Teenage Girls in Africa

The eden-avi-lib library

This page presents Eden Foundation's library for extracting the dates out of AVI film clips. It is a small Java library, supporting files with DV encoding and MJPEG encoding. Clips encoded in MJPEG format tend to store their date stamps in different ways, depending on the manufacturer, and this code is capable of extracting the recording times stored by FujiFilm and Samsung cameras. It may work for other brands as well, but has not been tested on them.

Click here to download the library (Version 0.1.4, published 2010-01-11)

You are free to use this library, including the source code, in any way you see fit.

Command-line useage:
java -jar eden-avi-lib-0.1.4.jar /my_path/my_film.avi

The date stamp formats

Here is a technical discussion over how eden-avi-lib extracts various dates:

DV-AVI

DV-AVI files can be encoded in two subformats: ivas-dvsd (Type 1) and vids-dvsd (Type 2). The difference between the two types is that the Type 1 encoding lets the video and audio share the same track, whilst for Type 2, the video and audio data are on separate tracks in the AVI file. Eden-avi-lib only supports DV-AVI files using the Type 2 encoding. It searches for the first frame in the file, and reads the date stamp encoded there.

MJPEG-AVI

MJPEG-AVI files store their date stamp in a chunk in the header of the file, rather than in the video track itself. However, there are several different ways of storing this stamp, depending on the manufacturer of the camera used to record the film clip. Eden-avi-lib is currently capable of reading three such chunks:

Doing it for QuickTime movies

QuickTime movies (mov files), at least those recorded by Konika Minolta cameras, store the recording date in the "mvhd" atom. To access the different atoms, Chris Adamson has written an article and a piece of code. The format of the "mvhd" atom is described on Apple's developer site. Basically, we want to extract the 5th to 8th bytes of the atom, and then convert those four bytes to a Calendar object. Here is a method that performs such a conversion:

 private Calendar bytesToCal(byte[] buffer) {
   int i = 0;
   int pos = 0;
   i += unsignedByteToInt(buffer[pos++]) << 24;
   i += unsignedByteToInt(buffer[pos++]) << 16;
   i += unsignedByteToInt(buffer[pos++]) << 8;
   i += unsignedByteToInt(buffer[pos++]) << 0; 
   long l = unsignedIntToLong(i);
   
   long days = l / 86400;
   long time = l % 86400;
   long hours = time / (60 * 60);
   long minutes = (time % (60 * 60)) / 60;
   long seconds = time % 60;
   
   GregorianCalendar cal = new GregorianCalendar(1904, 0, 1);
   cal.add(Calendar.DAY_OF_MONTH, (int)days);
   cal.set(Calendar.HOUR_OF_DAY, (int)hours);
   cal.set(Calendar.MINUTE, (int)minutes);
   cal.set(Calendar.SECOND, (int)seconds);
   
   return cal;
 }
 private static int unsignedByteToInt(byte b) {
   return b & 0xFF;
 }
 private static long unsignedIntToLong(int i) {
   return i & 0xffffffffL;
 }

Special Thanks

Special thanks go to Johan Stäck, who solved the puzzle of extracting the recording date out of DV-AVI frames, a task that requires quite some binary acrobatics. His code was written in Visual Basic, and I ported it to Java. Unfortunately, Johan's page is down now (lightweightvideo.com).

Contact

For feedback, please contact Josef Garvi on "josef at eden-foundation dot org". If anyone has tips on how to extract these time stamps from other types of film clips, please let us know!


Eden Foundation Home Page