xuggle操作视频
系列文章目录
文章目录
原文链接 https://zhhll.icu/2023/第三方工具/视频操作/1.xuggle/
xuggle操作视频
有个需求是要读取视频的宽高,找到了Xuggle和FFmpeg两种方式,FFmpeg很强大,但是我并不需要那些功能,所以使用了轻量一点的Xuggle
引入依赖
<dependency>
<groupId>xuggle</groupId>
<artifactId>xuggle-xuggler</artifactId>
<version>5.4</version>
</dependency>
操作示例
String fileName = "/Users/zhanghe/Desktop/1.mp4";
IContainer container = IContainer.make();
IContainerFormat format = IContainerFormat.make();
int result = container.open(fileName, IContainer.Type.READ, null);
if(result < 0){
throw new RuntimeException("不能打开该文件");
}
int num = container.getNumStreams();
for(int i = 0;i<num;i++){
IStream stream = container.getStream(i);
IStreamCoder coder = stream.getStreamCoder();
if(coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO){
System.out.println(coder.getWidth());
System.out.println(coder.getHeight());
}
}
// 还可以获取
// 时长 单位是μs
long duration = container.getDuration();
System.out.println("duration:"+duration);
// 文件大小
long fileSize = container.getFileSize();
System.out.println("fileSize:"+fileSize);
// 码率
int bitRate = container.getBitRate();
System.out.println("bitRate:"+bitRate);
本文来自博客园,作者:拾光师,转载请注明原文链接:https://www.cnblogs.com/life-time/p/17864312.html 个人博客-> https://zhhll.icu

浙公网安备 33010602011771号