在日常开发中,经常会遇到产品经理提出一个需求“上传视频”,而且还得显示出视频的播放时长,我们直接上最简单的代码
1.???????提前引入包
<!--视频多媒体工具包 包含 FFmpeg、OpenCV-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.3</version>
</dependency>
2.逻辑实现
public static void main(String[] args) throws IOException, InterruptedException {
String localPath = "C:/Users/Administrator/Desktop/dab2d14cad0244229e228e7bf297dd9a.flv";
FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(localPath);
grabber.start();
log.info("此视频时长(s/秒):{}", grabber.getLengthInTime() / (1000 * 1000));
}