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);

参考文献

相关推荐
@淡 定几秒前
Spring Boot 的配置加载顺序
java·spring boot·后端
Asthenia041216 分钟前
Java线程池线程工厂深入剖析:从生产需求到面试拷问
后端
等什么君!1 小时前
springmvc-拦截器
后端·spring
brzhang2 小时前
代码即图表:dbdiagram.io让数据库建模变得简单高效
前端·后端·架构
Jamesvalley2 小时前
【Django】新增字段后兼容旧接口 This field is required
后端·python·django
秋野酱2 小时前
基于 Spring Boot 的银行柜台管理系统设计与实现(源码+文档+部署讲解)
java·spring boot·后端
獨枭2 小时前
Spring Boot 连接 Microsoft SQL Server 实现登录验证
spring boot·后端·microsoft
shanzhizi3 小时前
springboot入门-controller层
java·spring boot·后端
电商api接口开发4 小时前
ASP.NET MVC 入门指南三
后端·asp.net·mvc
声声codeGrandMaster4 小时前
django之账号管理功能
数据库·后端·python·django