参考地址:
https://geek-docs.com/python/python-ask-answer/683_python_get_video_dimension_in_pythonopencv.html
https://blog.csdn.net/m0_61787307/article/details/129654826
1. 安装(试了三台服务器,有一台服务器安装过程会很慢,卡在一个地方一直不动,目前不清楚是什么原因,但是多等会确实安装成功了)
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
2. 使用
import cv2 # 打开视频文件 video = cv2.VideoCapture('视频地址') # 检查视频是否成功打开 if not video.isOpened(): print('无法打开视频文件') # 获取视频尺寸 width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 输出视频尺寸 print(f'视频尺寸:{width}x{height}') # 释放视频 video.release()
3. 遇到问题
3.1 [ERROR:[email protected]] global cap.cpp:166 open VIDEOIO(CV_IMAGES): raised OpenCV exception: OpenCV(4.9.0) /tmp/pip-install-9bc0cux4/opencv-python_fa0a3297e6c14b959cf0737136675a99/opencv/modules/videoio/src/cap_images.cpp:274: error: (-215:Assertion failed) number < max_number in function 'icvExtractPattern'
原因:python版本和opencv-python安装包版本不符
解决:点这里 查看你使用python的对应包版本,重新pip下载即可
标签:视频,opencv,Python,cv2,python,video,尺寸 From: https://www.cnblogs.com/chaoqi/p/18124554