Skip to content

A wrapper around popular libraries for extracting metadata from images, video and audio files.

License

Notifications You must be signed in to change notification settings

finikm/mediachecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Build Status

MediaChecker Library

MediaChecker was developed as a collection of static functions that wrap around some of the best media analysis libraries available today. These libraries include ImageMagick for images, FFMPEG for audio/video and iTextPDF for PDF files.

Helper Functions

public static String getMimeType(String filename) throws IOException, FileNotFoundException

This is the core function, since it returns the mime-type of any file. This should be used in a switch block, to redirect the files to the appropriate analysis function.

public static long getFileSize(String filename) throws IOException, FileNotFoundException

A helper function that returns the size of a file (regardless of type) in bytes.

public static String getVersion()

Another helper function that returns the version of MediaChecker. This should be saved along with the extracted metadata; this will allow for metadata to be updated when newer versions are released, without having to re-processes everything.

Images

public static ImageInfo getImageInfo(String filename, String colormap) throws IOException, FileNotFoundException, InfoException, InterruptedException, IM4JavaException

The function above takes as input the filename of the image to be processed, and the filename of a colormap to be used for reducing the number of colors in the image, and for selecting the 6 most common colors. A sample colormap (based on X11 Colors) can be found in the resources directory (named colormap.png).

Processing an image through this function results to an ImageInfo object with the following properties:

public int getWidth()
public int getHeight()

This functions return the dimensions of the image in pixels (by returning Width and Height respectively).

public String getMimeType()
public String getFileFormat()

The first function returns the MIME type of the image, while the second returns the file format of the image (the complete list of file types identified, can be found on ImageMagick website).

public String getColorSpace()

This function returns sRGB for color images and grayscale for grayscale images.

public String[] getPalette()

Finally, this function returns an array with upto 6 colors (in the HEX code used for web applications). To achieve that, the image is dithered using a pre-defined color map and the 6 most common colors in the image (based on the number of pixels of each color) are selected.

Video Files

public static VideoInfo getVideoInfo(String filename) throws IOException, FileNotFoundException, IllegalArgumentException

This function takes as input the filename of the video to be processed, examines the first (video) stream, and returns an object of the VideoInfo class with the properties below. Keep in mind that if multiple video streams are present in the container, only the first one is examined.

public int getWidth()
public int getHeight()
public String getResolution()

These functions return the dimensions of the video in pixels (by returning Width, Height and a concatenation of both, respectively).

public String getMimeType()
public String getCodec()

The first function returns the MIME type of the video, while the second returns the Codec the video is encoded with.

public long getDuration()
public double getFrameRate()
public int getBitRate()

Finally, these three functions return the duration of the video (in milliseconds), the frame-rate (in frames per second) and the bit-rate (in bits per second), respectivelly.

Audio Files

public static AudioInfo getAudioInfo(String filename) throws IOException, FileNotFoundException, IllegalArgumentException

This function takes as input the filename of the audio file to be processed, examines the first (audio) stream and returns an object of the AudioInfo class with the properties below. Keep in mind that if multiple audio streams are present in the container, only the first one is examined.

public String getMimeType()
public String getFileFormat()

The first function returns the MIME type of the audio, while the second returns the Codec the audio is encoded with.

public int getSampleRate()
public int getBitRate()
public int getBitDepth()
public int getChannels()

Functions to get the quality of the audio file: Sample Rate, Bit Rate, Bit Depth and number of Channels, respectively. Keep in mind that FLAC files return a bit-rate of 0 since they are loselessly compressed.

public long getDuration()

Finally, this function returns the duration of the audio file (in milliseconds).

Text Files

For text files, the available information is minimal.

protected static boolean isSearchable(String filename) throws IOException, FileNotFoundException

This function can be used on any text file (txt, epub, pdf, xml, rtf). With the exeption of PDF, the rest are by definition searchable, and the function returns true. For PDF files, we check if the file contains only images (returns false) or any text (returns true). Keep in mind that a PDF file that contains images and even a single character (in the form of plain text) is marked as searchable.

protected static int getDPI(String filename) throws IOException, FileNotFoundException

With this function, the user can obtain the DPI of a PDF file, IF and ONLY IF the file contains a single image. If the file contains more than one image, then -1 is returned, while no image results to a returned value of 0.

MediaChecker Daemon

In addition to MediaChecker, a simple daemon to extract metadata from media files using MediaChecker is availabe. The queries are made by writting the (full) filename of the media file to a simple socket, and returns the metadata through the same socket, in the form of a JSON string.

Daemon starts with:

java -jar MediaChecker-1.0.jar PORT

where PORT the listening port.

Examples Responses

Note: The responses were pretty printed for illustration purposes only. The actual responses are contained in a single line.

Image

{
  "colorspace": "sRGB",
  "format": "JPEG",
  "width": 1280,
  "mimetype": "image/jpeg",
  "palette": [
    "#000000",
    "#DC143C",
    "#800000",
    "#B22222",
    "#A52A2A",
    "#FF1493 "
  ],
  "height": 1024
}

Audio File

{
  "duration": 5000,
  "bitdepth": 16,
  "channels": 2,
  "mimetype": "audio/x-flac",
  "bitrate": 0,
  "fileformat": "flac",
  "samplerate": 44100
}

Video File

{
  "duration": 4966,
  "codec": "mpeg4",
  "framerate": 30,
  "width": 190,
  "mimetype": "video/mp4",
  "bitrate": 341948,
  "height": 240
}

LICENSE

The project is licensed under the terms of the MIT license.

About

A wrapper around popular libraries for extracting metadata from images, video and audio files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages