我正在尝试使用OpenCV将视频写入媒体文件。视频播放正常,mp4文件写入媒体文件。然而,当我打开书面视频时,我收到了这条消息,
This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt我已经将VideoWriter_fourcc()更改为*"X264“、*"H264”、*"MP4V“、*"mp4v”和*"MPEG“。所有这些都不能解决问题。
import cv2
path = "C:/Users/gri_o/Desktop/opencvProjects/ProjectOne/testVideos/myvideo.mp4"
video_selected = cv2.VideoCapture(path)
vid_cod = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('media/testOne.mp4', vid_cod, 20.0, (640,480))
while(True):
ret,frame = video_selected.read()
if ret == True:
out.write(frame)
cv2.imshow('frame', frame)
# Press Q on keyboard to exit
if cv2.waitKey(10) & 0xFF == ord('q'):
break
else:
break
video_selected.release()
out.release()发布于 2020-03-17 14:54:22
该错误可能是由于中提到的宽度和高度引起的,
out = cv2.VideoWriter('media/testOne.mp4', vid_cod, 20.0, (640,480))获取框架的宽度和高度为
w, h = frame.shape[:2]
out = cv2.VideoWriter('media/testOne.mp4', vid_cod, 20.0, (w,h))https://stackoverflow.com/questions/60609402
复制相似问题