地址:https://bytedeco.org/download/
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
<version>4.0.2-1.4.3</version>
</dependency>
2.代码
String videoPath= "D:\\mp4\\test.m4a";
public static long getDuration(String videoPath) {
long duration = 0;
try (FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoPath)) {
grabber.start();
int numFrames = grabber.getLengthInFrames();
double frameRate = grabber.getFrameRate();
duration = (long) (numFrames / frameRate);
} catch (Exception e) {
e.printStackTrace();
}
return duration;
}