使用了一下JNative,调用MediaInfo.dll的动态链接库。
MediaInfo提供的源码中很多的Example
其中有各类就是Mediainfo提供给用户用JNative调用的类,把它拷到项目下就行了叫做MediaInfoDLL.JNative.java
还有一个是交给我们怎么使用上面那个类的,做的真是周到,叫HowToUseDLL.jNative.java
可以通过这个来学习。
MediaInfo mi = new MediaInfo(); mi.Open(sourceFilePath); mi.Option("Complete", "0"); format = mi.Get(MediaInfo.Stream_General, 0, "Format", MediaInfo.Info_Text, MediaInfo.Info_Name); filesize = mi.Get(MediaInfo.Stream_General, 0, "FileSize", MediaInfo.Info_Text, MediaInfo.Info_Name); duration1 = mi.Get(MediaInfo.Stream_General, 0, "Duration", MediaInfo.Info_Text, MediaInfo.Info_Name); videoFormat = mi.Get(MediaInfo.Stream_Video, 0, "Format", MediaInfo.Info_Text, MediaInfo.Info_Name); videoWidth = mi.Get(MediaInfo.Stream_Video, 0, "Width", MediaInfo.Info_Text, MediaInfo.Info_Name); videoHeight = mi.Get(MediaInfo.Stream_Video, 0, "Height", MediaInfo.Info_Text, MediaInfo.Info_Name); videoFrameRate = mi.Get(MediaInfo.Stream_Video, 0, "FrameRate", MediaInfo.Info_Text, MediaInfo.Info_Name); audioFormat = mi.Get(MediaInfo.Stream_Audio, 0, "Format", MediaInfo.Info_Text, MediaInfo.Info_Name); audioBitRate = mi.Get(MediaInfo.Stream_Audio, 0, "BitRate", MediaInfo.Info_Text, MediaInfo.Info_Name);
上面的代码可以得到视频的General,Video,Audio的信息,比如大小,时长,帧率,码率,高宽等等。
对于其中的参数"Format"等,可以用一下代码获得,其实是在HowToUseDLL.jNative.java这个文件中的,叫做Info_Parameters。
String File_Name = "C:\\v\\content\\uploads\\admin\\shenqi.wmv"; if (args.length > 0) File_Name = args[0]; String To_Display = ""; //Info about the library // To_Display += MediaInfo.Option_Static("Info_Version"); To_Display += "\r\n\r\nInfo_Parameters\r\n"; To_Display += MediaInfo.Option_Static("Info_Parameters"); //To_Display += "\r\n\r\nInfo_Capacities\r\n"; //To_Display += MediaInfo.Option_Static("Info_Capacities"); // To_Display += "\r\n\r\nInfo_Codecs\r\n"; //To_Display += MediaInfo.Option_Static("Info_Codecs"); //An example of how to use the library MediaInfo MI = new MediaInfo(); To_Display += "\r\n\r\nOpen\r\n"; if (MI.Open(File_Name)>0) To_Display+="is OK\r\n"; else To_Display+="has a problem\r\n"; To_Display += "\r\n\r\nInform with Complete=false\r\n"; MI.Option("Complete", "1"); To_Display += MI.Inform(); System.out.println(To_Display);
我这个是在windows上的,MediaInfo.dll和JNativeCpp.dll文件放在了system32下面,不知道怎么能用在linux下,持续更新中....