JAVE获取视频文件属性信息(比较全)
程序员文章站
2024-03-25 18:17:22
...
1.直接看效果
2.直接上源码
public static void videoInfo(String videoPath) {
File source = new File(videoPath);
if (!source.exists()) {
System.err.println("提示:文件[" + source + "]不存在!");
return;
}
Encoder encoder = new Encoder();
FileChannel fc = null;
String size = "";
try {
MultimediaInfo mi = encoder.getInfo(source);
String duration = LxTimeUtil.msecToTime(mi.getDuration());
int width = mi.getVideo().getSize().getWidth();
int height = mi.getVideo().getSize().getHeight();
String format = mi.getFormat();
int audioChannels = mi.getAudio().getChannels();
String audioDecoder = mi.getAudio().getDecoder();
int audioSamplingRate = mi.getAudio().getSamplingRate();
String videoDecoder = mi.getVideo().getDecoder();
float videoFrameRate = mi.getVideo().getFrameRate();
System.out.println("★★★★★★★★★【"+source+"】★★★★★★★★★");
System.out.println("格式:" + format);
System.out.println("时长:" + duration);
System.out.println("尺寸:" + width + "×" + height);
System.out.println("音频编码:"+ audioDecoder);
System.out.println("音频轨道:" + audioChannels);
System.out.println("音频采样率:" + audioSamplingRate);
System.out.println("视频编码:" + videoDecoder);
System.out.println("视频帧率:" + videoFrameRate);
@SuppressWarnings("resource")
FileInputStream fis = new FileInputStream(source);
fc = fis.getChannel();
BigDecimal fileSize = new BigDecimal(fc.size());
size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
System.out.println("文件大小:" + size);
System.out.println("★★★★★★★★★By liangxin at 2020-08-16 16:33★★★★★★★★★");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != fc) {
try {
fc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
3.补充说明
获取视频方式有多重途径及插件,但使用JAVE效率较高,速度较快,也比较简便。官网(网址:http://www.sauronsoftware.it/projects/jave/index.php)查阅发现,最后的更新日期为2009年4月15日,非常古老了,当然对一些新格式的支持非常有限。
推荐阅读