From 21e8a3c67d52419599448a5150b151646cffb596 Mon Sep 17 00:00:00 2001 From: yukihane Date: Tue, 2 Aug 2011 02:50:42 +0900 Subject: [PATCH] =?utf8?q?MediaInfo=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97?= =?utf8?q?=E3=81=A6=E3=82=B5=E3=82=A4=E3=82=BA=E3=82=92=E5=8F=96=E5=BE=97?= =?utf8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- build.xml | 74 ++ manifest.mf | 3 + nbproject/build-impl.xml | 1041 ++++++++++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 72 ++ nbproject/project.xml | 15 + src/yukihane/mediainfowrapper/Info.java | 26 + src/yukihane/mediainfowrapper/MediaInfo.java | 69 ++ src/yukihane/mediainfowrapper/Size.java | 26 + 9 files changed, 1334 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/yukihane/mediainfowrapper/Info.java create mode 100644 src/yukihane/mediainfowrapper/MediaInfo.java create mode 100644 src/yukihane/mediainfowrapper/Size.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..7b0a4c6 --- /dev/null +++ b/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project MediaInfoWrapper. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..1c6283b --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..c6bf9f9 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d35cfe9e +build.xml.script.CRC32=31e56aca +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d35cfe9e +nbproject/build-impl.xml.script.CRC32=16d6a9fc +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..b0abe23 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=MediaInfoWrapper +application.vendor=yuki +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MediaInfoWrapper.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mediainfowrapper.MediaInfoWrapper +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..307be8d --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + MediaInfoWrapper + + + + + + + + + diff --git a/src/yukihane/mediainfowrapper/Info.java b/src/yukihane/mediainfowrapper/Info.java new file mode 100644 index 0000000..cde8165 --- /dev/null +++ b/src/yukihane/mediainfowrapper/Info.java @@ -0,0 +1,26 @@ +/* $Id: Info.java 44 2010-02-03 09:51:57Z yuki $ */ +package yukihane.mediainfowrapper; + +public class Info { + + private final int width; + private final int height; + + public Info(int width, int height) { + this.width = width; + this.height = height; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + @Override + public String toString() { + return "Width:" + width + ", Height:" + height; + } +} diff --git a/src/yukihane/mediainfowrapper/MediaInfo.java b/src/yukihane/mediainfowrapper/MediaInfo.java new file mode 100644 index 0000000..843fcda --- /dev/null +++ b/src/yukihane/mediainfowrapper/MediaInfo.java @@ -0,0 +1,69 @@ +/* $Id: MediaInfo.java 57 2010-02-04 04:43:44Z yuki $ */ +package yukihane.mediainfowrapper; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MediaInfo { + + public static Info getInfo(File mediaInfoBin, File videoFile) throws IOException { + String[] command = new String[]{mediaInfoBin.getPath(), videoFile.getPath()}; + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + Pattern widthPattern = Pattern.compile("Width +:(.+)pixels"); + Pattern heightPattern = Pattern.compile("Height +:(.+)pixels"); + int width = -1; + int height = -1; + while ((line = reader.readLine()) != null) { + Matcher widthMatcher = widthPattern.matcher(line); + if (widthMatcher.find()) { + String str = widthMatcher.group(1).replaceAll(" ", ""); + width = Integer.parseInt(str); + continue; + } + + Matcher heightMatcher = heightPattern.matcher(line); + if (heightMatcher.find()) { + String str = heightMatcher.group(1).replaceAll(" ", ""); + height = Integer.parseInt(str); + continue; + } + } + return new Info(width, height); + } + + public static Size adjustSize(Info info, int maxWidth, int maxHeight) { + int nowWidth = info.getWidth(); + int nowHeight = info.getHeight(); + + if (nowWidth <= maxWidth && nowHeight <= maxHeight) { + return new Size(nowWidth, nowHeight); + } + + double widthRatio = calcRatio(nowWidth, maxWidth); + double heightRatio = calcRatio(nowHeight, maxHeight); + + if (widthRatio >= heightRatio) { + int adjustedWidth = adjust(nowWidth, widthRatio); + int adjustedHeight = adjust(nowHeight, widthRatio); + return new Size(adjustedWidth, adjustedHeight); + } else { + int adjustedWidth = adjust(nowWidth, heightRatio); + int adjustedHeight = adjust(nowHeight, heightRatio); + return new Size(adjustedWidth, adjustedHeight); + } + } + + private static double calcRatio(int now, int max) { + return (double) now / (double) max; + } + + private static int adjust(int size, double ratio) { + return (int) (size / ratio); + } +} diff --git a/src/yukihane/mediainfowrapper/Size.java b/src/yukihane/mediainfowrapper/Size.java new file mode 100644 index 0000000..8236204 --- /dev/null +++ b/src/yukihane/mediainfowrapper/Size.java @@ -0,0 +1,26 @@ +/* $Id: Size.java 44 2010-02-03 09:51:57Z yuki $ */ + +package yukihane.mediainfowrapper; + +public class Size { + private final int width; + private final int height; + + public Size(int width, int height) { + this.width = width; + this.height = height; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + @Override + public String toString() { + return "Width:" + width + ", Height:" + height; + } +} -- 2.11.0