Opencv提供了类似java中静态变量的参数,可以通过get(参数)获取当前视频的信息,参数类别还是挺多的,按照需求查手册或源码即可。
源码参数举例
获取视频帧的长宽
import cv2
if __name__ == '__main__':
mp4_path ='xhx_utils/images/demo.mp4'
video = cv2.VideoCapture(mp4_path)
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
print("长:{%d},宽:{%d}"%(height,width))
video.release()
获取视频的总帧数
import cv2
if __name__ == '__main__':
mp4_path ='xhx_utils/images/demo.mp4'
video = cv2.VideoCapture(mp4_path)
num_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
print("帧数:"+str(num_frames))
video.release()
获取视频的FPS
import cv2
if __name__ == '__main__':
mp4_path ='xhx_utils/images/demo.mp4'
video = cv2.VideoCapture(mp4_path)
fps = int(video.get(cv2.CAP_PROP_FPS))
print("fps:"+str(fps))
video.release()
文章来源:https://www.toymoban.com/news/detail-813834.html
还有很多其他的参数可以获取,大家可以按照自己的需求查取。文章来源地址https://www.toymoban.com/news/detail-813834.html
到了这里,关于Opencv获取当前视频长宽、总帧数、fps的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!