sMeta: FAQ

Here is a collection of frequently asked questions about sMeta:

How do I get started?

Here's some of the source of magoffin.matt.meta.MetadataResourceExample:


  public static void main(String[] argsthrows IOException {
    if ( args == null || args.length < 1 ) {
      System.err.println("Pass files to read metadata from.");
    }
    
    // 1: get a MetadataResourceFactoryManager instance
    MetadataResourceFactoryManager manager 
      = MetadataResourceFactoryManager.getDefaultManagerInstance();
    
    for ( String filePath : args ) {
      File oneFile = new File(filePath);
      
      // 2: get a MetadataResourceFactory for this file type
      MetadataResourceFactory factory 
        = manager.getMetadataResourceFactory(oneFile);
      
      try {
        // 3: get a MetadataResource for this file
        MetadataResource metaResource 
          = factory.getMetadataResourceInstance(oneFile);
        
        // 4: print out all available metadata
        Iterable<Stringkeys = metaResource.getParsedKeys();
        System.out.println("\nMetadata for file [" 
          +oneFile.getAbsolutePath() +"]:");
        for ( String key : keys ) {
          System.out.println(key +" = " 
            +metaResource.getValue(keyLocale.getDefault()));
        }
      } catch ( MetadataNotSupportedException e ) {
        System.err.println("File [" +oneFile.getAbsolutePath() 
            +"] is not supported by the [" 
            +factory.getClass().getName() +"] factory");
      }
    }
  }

A sample of the output from this program is:

Metadata for file [src-test/magoffin/matt/meta/audio/id3v1.mp3]: SONG_NAME = Macgyver Theme ARTIST = Macgyver ALBUM = Macgyver (An ABC TV show) COMMENT = Almost as cool as the A-Team GENRE = Other Metadata for file [src-test/magoffin/matt/meta/image/IMG_1218.jpg]: APERTURE = 4.0 CAMERA_MAKE = Canon CAMERA_MODEL = Canon PowerShot G5 DATE_TAKEN = Thu Nov 13 18:10:25 NZDT 2003 EXPOSURE_BIAS = 0 EXPOSURE_TIME = 1/60 F_STOP = F4 FLASH = true FOCAL_LENGTH = 20.6875 ORIENTATION = 1 SHUTTER_SPEED = 1/60
How can I extract the album cover image from an MP3 file?

Look for a magoffin.matt.meta.MetadataImage object in the metdata returned for your MP3 file. This API provides an easy way to either get a java.awt.image.BufferedImage from the embedded image data, or write the unaltered image data to an java.io.OutputStream.

For example, running the magoffin.matt.meta.MetadataResourceExample on an MP3 with an embedded PNG image results in this:

Metadata for file [src-test/magoffin/matt/meta/audio/id3v2_4.mp3]: ALBUM = Album Name Here ALBUM_COVER = MetadataImage{image/png; 26781} ARTIST = MUSICMATCH SONG_NAME = MUSICMATCH Jukebox Plus Upgrade GENRE = Unclassifiable TRACK_NUM = 1 TRACK_TOTAL = 2 YEAR = 2002 BIT_RATE = 160 kbps (VBR) SAMPLE_RATE = 44.1 kHz AUDIO_FORMAT = MPEG-1, Layer 3

Note the ALBUM_COVER metadata key, which is an instance of magoffin.matt.meta.MetadataImage and is showing the image format (PNG) and size (26,781 bytes).

How can I extract a still frame from a video file?

This is handled in the same fashion as extracting the album cover from an MP3 file (above). The POSTER metadata key will contain a magoffin.matt.meta.MetadataImage if sMeta is able to extract a still frame from the video. For video formats with the ability to specify a poster frame (i.e. QuickTime) sMeta will extract that frame. For other video formats sMeta will extract the first frame.

Metadata for file [VideoTest-01-QuickTimeMetadataResource-8.mov]: WIDTH = 320 HEIGHT = 240 POSTER = MetadataImage{[image/png]; 320x240} DURATION = 167327 DURATION_TIME = 2:47.327 AUDIO_FORMAT = RTP MPEG4 Audio Packetizer, 32000.0 Hz, 16 bit, stereo FPS = 14.985 VIDEO_FORMAT = MP4V, 24 bit
SourceForge.net Logo