目标
将所有格式的视频转码为H5能播放的mp4格式
依赖
<!-- 依赖很多,不需要的自行排除 -->
<!-- 转码功能只需要以ffmpeg、javacpp、javacv、openblas、opencv开头的jar包依赖 -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.3</version>
</dependency>
VideoFormat.java
package com.videotest;
public class VideoFormat {
private boolean exists;
private boolean isFile;
private String absolutePath;
private String parent = "";
private String name = "";
private String simpleName = "";
private String extName = "";//扩展名
/**
* @See {org.bytedeco.ffmpeg.global.avcodec}
*/
private int videoCodec;//视频编码格式
/**
* @See {org.bytedeco.ffmpeg.global.avcodec}
*/
private int audioCodec;//音频编码格式
private String format = "";//封装格式
public boolean isExists() {
return exists;
}
public void setExists(boolean exists) {
this.exists = exists;
}
public boolean isFile() {
return isFile;
}
public void setFile(boolean isFile) {
this.isFile = isFile;
}
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSimpleName() {
return simpleName;
}
public void setSimpleName(String simpleName) {
this.simpleName = simpleName;
}
public String getExtName() {
return extName;
}
public void setExtName(String extName) {
this.extName = extName;
}
public int getVideoCodec() {
return videoCodec;
}
public void setVideoCodec(int videoCodec) {
this.videoCodec = videoCodec;
}

该博客介绍了如何使用JavaCV库将不同格式的视频转换为H5兼容的MP4格式。通过VideoFormat和Video类,检查视频编码、音频编码和封装格式,然后利用FFmpegFrameGrabber和FFmpegFrameRecorder进行转码操作。
最低0.47元/天 解锁文章
1158

被折叠的 条评论
为什么被折叠?



