org.jcodec.mediainfo.MediaInfoMain Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcodec Show documentation
Show all versions of jcodec Show documentation
Pure Java implementation of video/audio codecs and formats
package org.jcodec.mediainfo;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jcodec.common.JCodecUtil;
import org.jcodec.common.JCodecUtil.Format;
import org.jcodec.containers.mp4.MP4Util;
import org.jcodec.containers.mp4.boxes.MovieBox;
/**
* This class is part of JCodec ( www.jcodec.org ) This software is distributed
* under FreeBSD License
*
* @author The JCodec project
*
*/
public class MediaInfoMain {
public static void main(String[] args) throws IOException {
File in = new File(args[0]);
Format format = JCodecUtil.detectFormat(in);
String property = args[1];
if (format == Format.MOV) {
movInfo(in, property);
} else {
System.out.println("Unsupported format");
}
}
private static void movInfo(File f, String property) throws IOException {
MovieBox movie = MP4Util.parseMovie(f);
System.out.println(extractors.get(property).getProperty(movie));
}
public static interface MovInfoExtractor {
String getProperty(MovieBox movie);
}
public static Map extractors = new HashMap();
static {
extractors.put("video.display.width", new MovInfoExtractor() {
public String getProperty(MovieBox movie) {
return String.valueOf(movie.getDisplaySize().getWidth());
}
});
extractors.put("video.display.height", new MovInfoExtractor() {
public String getProperty(MovieBox movie) {
return String.valueOf(movie.getDisplaySize().getHeight());
}
});
extractors.put("video.stored.width", new MovInfoExtractor() {
public String getProperty(MovieBox movie) {
return String.valueOf(movie.getStoredSize().getWidth());
}
});
extractors.put("video.stored.height", new MovInfoExtractor() {
public String getProperty(MovieBox movie) {
return String.valueOf(movie.getStoredSize().getHeight());
}
});
}
}