首先确认下视频的播放时间
使用cv库来获取帧率和帧数,测试代码如下
import cv2
cap = cv2.VideoCapture("xxx.mp4")
if not cap.isOpened():
print("Cannot open camera")
exit()
# get default video FPS
fps = cap.get(cv2.CAP_PROP_FPS)
# get total number of video frames
num_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("fps is %d , sum of frames is %d " % (fps, num_frames))
cap.release()
cv2.destroyAllWindows()
python3运行结果,30fps,总帧数807
计算验证,fps含义,多少帧frame每秒,视频的时间就等于总帧数/fps,807/30=26.9s,符合我们最开始看到的视频时间