python 获取视频
时间: 2023-10-19 15:11:31 浏览: 104
你可以使用 OpenCV 库来获取视频。下面是一个简单的示例代码:
```python
import cv2
# 打开视频文件
cap = cv2.VideoCapture('video.mp4')
while True:
# 读取视频帧
ret, frame = cap.read()
if ret:
# 显示视频帧
cv2.imshow('Video', frame)
# 按下 q 键退出循环
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
# 释放资源
cap.release()
cv2.destroyAllWindows()
```
在上面的示例中,我们使用了 `cv2.VideoCapture()` 函数打开一个视频文件,然后在一个循环中读取视频帧并显示它们。如果用户按下键盘上的 q 键,循环将被终止并释放资源。
阅读全文
相关推荐

















