xuggle操作视频


文章目录


xuggle操作视频

有个需求是要读取视频的宽高,找到了Xuggle和FFmpeg两种方式,FFmpeg很强大,但是我并不需要那些功能,所以使用了轻量一点的Xuggle

引入依赖

xml 复制代码
<dependency>
    <groupId>xuggle</groupId>
    <artifactId>xuggle-xuggler</artifactId>
    <version>5.4</version>
</dependency>

可能maven仓库中没有该依赖,可以下载后放到本地仓库或私服

xuggle-xuggler-5.4.jar

或者可以使用

xml 复制代码
<dependency>
  <groupId>org.boofcv</groupId>
  <artifactId>xuggler</artifactId>
  <version>0.23</version>
</dependency>

该依赖中包含有xuggle-xuggler且maven仓库中存在

操作示例

java 复制代码
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);

参考文献

相关推荐
Reboot2 分钟前
使用cloc统计代码行数
后端
neoooo3 分钟前
当域名遇上家里的电脑:一条隧道通向世界
后端
zjjuejin3 分钟前
Maven依赖管理艺术
后端·maven
RoyLin3 分钟前
TypeScript设计模式:复合模式
前端·后端·typescript
我的小月月7 分钟前
SQLFE:网页版数据库(VUE3+Node.js)
前端·后端
Alan5215910 分钟前
Java 后端实现基于 JWT 的用户认证和权限校验(含代码讲解)
前端·后端
RoyLin20 分钟前
TypeScript设计模式:策略模式
前端·后端·typescript
brzhang30 分钟前
为什么说低代码谎言的破灭,是AI原生开发的起点?
前端·后端·架构
得物技术1 小时前
破解gh-ost变更导致MySQL表膨胀之谜|得物技术
数据库·后端·mysql
小码编匠1 小时前
WPF 中的高级交互通过右键拖动实现图像灵活缩放
后端·c#·.net