Python 2.7 无法播放从python 2.7保存的视频
我试过很多编解码器,除了最后一个,所有的都会产生0字节的视频,最后一个编解码器确实会产生一个视频文件,但是它不能播放。这个问题快把我逼疯了,我正在使用的代码已经被其他正在工作的用户测试过了。 我已将opencv_ffmpeg310_64.dll文件复制到c:\python2.7文件夹中。 我使用的是windows 10和opencv 3.1.0,我尝试了所有类型的编解码器,但都不起作用Python 2.7 无法播放从python 2.7保存的视频,python-2.7,opencv3.1,Python 2.7,Opencv3.1,我试过很多编解码器,除了最后一个,所有的都会产生0字节的视频,最后一个编解码器确实会产生一个视频文件,但是它不能播放。这个问题快把我逼疯了,我正在使用的代码已经被其他正在工作的用户测试过了。 我已将opencv_ffmpeg310_64.dll文件复制到c:\python2.7文件夹中。 我使用的是windows 10和opencv 3.1.0,我尝试了所有类型的编解码器,但都不起作用 import numpy as np import cv2 cap = cv2.VideoCaptu
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
# Define the codec and create VideoWriter object
#fourcc = cv2.VideoWriter_fourcc(*'FFV1')
#fourcc = cv2.VideoWriter_fourcc(*'XVID')
#fourcc = cv2.VideoWriter_fourcc(*'DIVX')
#fourcc = cv2.VideoWriter_fourcc(*'DIV3')
#fourcc = cv2.VideoWriter_fourcc('F','M','P','4')
#fourcc = cv2.VideoWriter_fourcc('D','I','V','X')
#fourcc = cv2.VideoWriter_fourcc('D','I','V','3')
#fourcc = cv2.VideoWriter_fourcc('F','F','V','1')
fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
我找到了答案,我所做的是通过输入“-1”而不是“fourcc”来获取可能的编解码器值,然后在fourcc编解码器网站上查找该编解码器的4位代码。 就我而言,是Cinemax编解码器CDIV
SO first step: find the code and enter by hand manually and see if the video is made and is playable
#use -1 below for entering the codec by hand
#out = cv2.VideoWriter('output.avi',-1, 20.0, (640,480))
second step: from the above step find out which codec worked for you and then look up the four digit code on the fourcc site and plug it in
fourcc = cv2.VideoWriter_fourcc(*'CVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
我找到了答案,我所做的是通过输入“-1”而不是“fourcc”来获取可能的编解码器值,然后在fourcc编解码器网站上查找该编解码器的4位代码。 就我而言,是Cinemax编解码器CDIV
SO first step: find the code and enter by hand manually and see if the video is made and is playable
#use -1 below for entering the codec by hand
#out = cv2.VideoWriter('output.avi',-1, 20.0, (640,480))
second step: from the above step find out which codec worked for you and then look up the four digit code on the fourcc site and plug it in
fourcc = cv2.VideoWriter_fourcc(*'CVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))