import cv2 as cv
cap=cv.VideoCapture("D:/Desktop/test.mp4")
#获取视频参数
width=cap.get(3)
high=cap.get(4)
fps=cap.get(5)
size=(int(width/2),int(high))
#定义编解码器并创建VideoWriter对象
fourcc=cv.VideoWriter_fourcc(*'XVID')
out=cv.VideoWriter('D:/Desktop/testleft.mp4',fourcc,fps,size)
while(cap.isOpened()):
ret,frame=cap.read()
target=frame[:,:1280,:]
out.write(target)
cv.imshow("frame_src",frame)
cv.imshow("frame",target)
k=cv.waitKey(1)
if(k==ord('q')):
break
cv.destroyAllWindows()
cap.release()
out.release()
opencv剪裁视频
最新推荐文章于 2024-08-07 09:39:41 发布