引入依赖
<dependency>
<groupId>com.github.vip-zpf</groupId>
<artifactId>jave</artifactId>
<version>1.0.9</version>
<exclusions>
<exclusion>
<artifactId>ffmpeg</artifactId>
<groupId>net.bramp.ffmpeg</groupId>
</exclusion>
<exclusion>
<artifactId>fastjson</artifactId>
<groupId>com.alibaba</groupId>
</exclusion>
<exclusion>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
代码:
public class VideoUtil {
public static void main(String[] args) throws EncoderException {
// String filename = "D:\\Marvel\\heiguafu.mp4";
// String filename = "D:\\Download\\material\\111112867e520b.mp4";
String filename = "D:\\Download\\material\\520b.mp4";
File source = new File(filename);
Encoder encoder = new Encoder();
MultimediaInfo m = encoder.getInfo(source);
long millisecond = m.getDuration();//总的毫秒数,可以自己根据毫秒转换成分钟,或者秒数之类的
VideoInfo video = m.getVideo();//视频文件
// AudioInfo audio = m.getAudio();//如果是音频文件可以用这个方法
VideoSize size = video.getSize();
int height = size.getHeight();//高
int width = size.getWidth();//宽
int duration = (int) ((millisecond /1000));//秒
int bitRate = video.getBitRate();//码流(Kb)
float frameRate = video.getFrameRate();//封装格式
String decoder = video.getDecoder();
String format = m.getFormat();
System.out.println("duration----"+duration);
System.out.println("height----"+height);
System.out.println("width----"+width);
System.out.println("bitRate-----"+bitRate);
System.out.println("frameRate-----"+frameRate);
System.out.println("decoder-----"+decoder);
System.out.println("format----"+format);
}
}
结果输出
代码参考自下文:
根据jave获取视频文件/音频文件的详细信息(总时长,宽高等等)_七亿少女的梦的博客-CSDN博客_java 获取视频文件信息