python - OpenCV - 在 Python 中保存后视频不播放
问题描述
我尝试在 Python 上将分辨率更改为 300x300 后保存视频,但我的视频在保存后无法播放
0xc10100be error: "This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt."
这是我的程序:
import numpy as np
import cv2
cap = cv2.VideoCapture("F:\\mi\\Camera\\2b7d9eccaddffffe3c9ba70b7fe6c12e(0).mp4")
cv2.namedWindow("vid1", 0)
cv2.resizeWindow("vid1", 300,300)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (300,300))
while(cap.isOpened()):
ret, frame = cap.read()
cv2.imshow('vid1',frame)
out.write(frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
怎么了?
解决方案
在向我的老师询问这个问题后,他修复了我的程序:
import numpy as np
import cv2
cap = cv2.VideoCapture("F:\\mi\\Camera\\2b7d9eccaddffffe3c9ba70b7fe6c12e(0).mp4")
cv2.namedWindow('frame',0)
cv2.resizeWindow('frame',300,300)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (300,300))
while(cap.isOpened()):
ret, frame = cap.read()
if ret:
vidout=cv2.resize(frame,(300,300)) #create vidout funct. with res=300x300
out.write(vidout) #write frames of vidout function
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
感谢您对我的问题的关注!
推荐阅读
- google-cloud-platform - 在本地机器上运行 ML 训练作业并将日志写入 Google Cloud
- python-3.x - 月过滤熊猫数据框Python
- python - Discord.py Bot 在点击它的反应后编辑消息
- node.js - Web3 节点 js:错误:事务已被 EVM 还原
- javascript - 旋转文字动画
- c++ - 将 jmp 指令视为函数指针的 DLL 调用
- python - Conv2DCustomBackpropInput:out_backprop 的大小与计算的不匹配:
- xml - XML (XACML) 语法错误 - 应为字符串文字
- python - PySpark:编写镶木地板文件时如何指定文件大小?
- c - 如何检查所有数组项是否连续并以值 9 结束