如下所示:
1、计算总帧数
import os
import cv2
video_cap = cv2.VideoCapture('ffmpeg_test.avi')
frame_count = 0
all_frames = []
while(True):
ret, frame = video_cap.read()
if ret is False:
break
all_frames.append(frame)
frame_count = frame_count + 1
# The value below are both the number of frames
print frame_count
print len(all_frames)
2、计算视频中的FPS,即每秒传输帧数(Frames per second)
import cv2
if __name__ == '__main__' :
video = cv2.VideoCapture("video.mp4");
# Find OpenCV version
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
if int(major_ver) < 3 :
fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
print "Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps)
else :
fps = video.get(cv2.CAP_PROP_FPS)
print "Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps)
video.release();
以上这篇使用python-opencv读取视频,计算视频总帧数及FPS的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。
您可能感兴趣的文章:python实现实时视频流播放代码实例python cv2读取rtsp实时码流按时生成连续视频文件方式python 实现视频流下载保存MP4的方法python3将视频流保存为本地视频文件python读取视频流提取视频帧的两种方法使用Python的Flask框架实现视频的流媒体传输Python imageio读取视频并进行编解码详解python处理RSTP视频流过程解析