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

参考文献

相关推荐
就叫飞六吧4 小时前
Spring Security 集成指南:避免 CORS 跨域问题
java·后端·spring
冼紫菜5 小时前
[特殊字符]CentOS 7.6 安装 JDK 11(适配国内服务器环境)
java·linux·服务器·后端·centos
秋野酱7 小时前
Spring Boot 项目的计算机专业论文参考文献
java·spring boot·后端
香饽饽~、7 小时前
【第二篇】 初步解析Spring Boot
java·spring boot·后端
你是狒狒吗7 小时前
消息队列了解一哈
后端
Chandler248 小时前
Go语言 GORM框架 使用指南
开发语言·后端·golang·orm
蚂蚁在飞-9 小时前
Golang基础知识—cond
开发语言·后端·golang
程序员爱钓鱼15 小时前
匿名函数与闭包(Anonymous Functions and Closures)-《Go语言实战指南》原创
后端·golang
言之。16 小时前
Go 语言中接口类型转换为具体类型
开发语言·后端·golang