# READ VIDEO
# 从本地摄像头获取视频并保存至当前文件夹
# 网络地址:https://bkrc.oss-cn-beijing.aliyuncs.com/videos/7d380bb1e47623338922e61dfc93d69e.mp4
# 1.引入OpenCV 2.视频读取 3.循环显示+保存 4.键值等待
import cv2
cap = cv2.VideoCapture("https://bkrc.oss-cn-beijing.aliyuncs.com/videos/7d380bb1e47623338922e61dfc93d69e.mp4")
if(cap.isOpened() == False):
print("Error")
# 默认分辨率取决于系统
# 将分辨率从float转换为整数
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
# 定义编解码器并创建VideoWriter对象。输出存储在“outpy.avi”文件中。
out = cv2.VideoWriter("Resources/r8c_SaveVideo.avi", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 30, (frame_width, frame_height))
while True:
state, frame = cap.read()
if state == True:
# Write the frame into the file 'r8c_SaveVideo.avi'
out.write(frame)
# Display the resulting frame
cv2.imshow(" frame ", frame)
OpenCV——视频属性与读取
最新推荐文章于 2023-01-24 10:58:11 发布