[英]How to change resolution of video to 1440p in opencv
I am trying to capture a video from webcam in 1440p but the output file cannot be opened. 我正在尝试从1440p网络摄像头捕获视频,但是无法打开输出文件。 There aren't any problem when I captured in 1080p and 2592*1944 (5mp), only 1440p that has a problem. 当我以1080p和2592 * 1944(5mp)拍摄时,没有任何问题,只有1440p才有问题。 Does anybody knows how can I make it work with 1440p? 有人知道我如何使它与1440p兼容吗?
I am not sure is it about the fourCC but I tried changing it to DIVX and the result still the same. 我不确定这与fourCC有关,但是我尝试将其更改为DIVX,结果仍然相同。
import cv2
cap = cv2.VideoCapture(0)
framesize = '1440p'
if framesize=='5mp':
cap.set(3, 2592)
cap.set(4, 1944)
resolution = (2592,1944)
elif framesize=='1440p':
cap.set(3, 2560)
cap.set(4, 1440)
resolution = (2560, 1440)
else :
cap.set(3, 1920)
cap.set(4, 1080)
resolution = (1920, 1080)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('new_output.avi',fourcc, 20.0, resolution)
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
The output file is only 13 KB. 输出文件只有13 KB。 When trying to play it, there's a message "This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt. 0xc10100be" 尝试播放时,出现一条消息“此文件不可播放。这可能是因为文件类型不受支持,文件扩展名不正确或文件已损坏。0xc10100be”
I think you have to resize each frame before passing it to the VideoWriter()
: 我认为您必须在将每个帧传递给VideoWriter()
之前调整其大小:
out = VideoWriter(outvid, fourcc, float(fps), size, is_color)
if size[0] != img.shape[1] and size[1] != img.shape[0]:
img = resize(img, size)
out.write(img)
More examples at https://www.programcreek.com/python/example/72134/cv2.VideoWriter 有关更多示例, 请访问https://www.programcreek.com/python/example/72134/cv2.VideoWriter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.