获取视频帧率
以下
public static void main(String[] args) {
String url = "/Users/lx/Desktop/1634115611333.mp4";
File file = new File(url);
getVideoInfo(file);
}
/**
* 获取视频信息
*
* @param file
*/
public static void getVideoInfo(File file) {
try {
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(file); // 获取视频文件
frameGrabber.start();
System.out.println(frameGrabber.getFrameRate()); // 视频帧数
System.out.println(frameGrabber.getLengthInTime() / (1000 * 1000)); // 时长
frameGrabber.close();
} catch (Exception e) {
e.printStackTrace();
}
}
需要引用的jar如下
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.4.4</version>
</dependency>
输出
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/lx/Desktop/1634115611333.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2021-10-13T03:15:40.000000Z
Duration: 00:00:20.07, start: 0.000000, bitrate: 3040 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x480 [SAR 1:1 DAR 8:3], 2720 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
Metadata:
creation_time : 2021-10-13T03:15:40.000000Z
handler_name : ?Mainconcept Video Media Handler
encoder : AVC Coding
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
Metadata:
creation_time : 2021-10-13T03:15:40.000000Z
handler_name : #Mainconcept MP4 Sound Media Handler
25.0
20
参考:
https://blog.csdn.net/qq_39390545/article/details/105278362