Python 使用cv2.videowrite()创建的视频无法播放?
这是我的代码,只需更改图像的边框,就可以从图像创建视频,而且效果良好 输出视频文件。但该视频文件在我的电脑中无法打开 当我尝试播放视频时,它是一个不正确的压缩代码fourccPython 使用cv2.videowrite()创建的视频无法播放?,python,opencv,cv2,Python,Opencv,Cv2,这是我的代码,只需更改图像的边框,就可以从图像创建视频,而且效果良好 输出视频文件。但该视频文件在我的电脑中无法打开 当我尝试播放视频时,它是一个不正确的压缩代码fourcc 我尝试了不同的fourcc“xvid”、“mpv4”、“mpjg”但没有任何效果您的输出视频帧大小不正确。您的输入帧大小为(1080600)。我们在每一侧添加了40px边框,因此最终的框架尺寸将为(1080+40*2600+40*2),即(1160680) import numpy import cv2 import ra
我尝试了不同的fourcc“xvid”、“mpv4”、“mpjg”但没有任何效果您的输出视频帧大小不正确。您的输入帧大小为(1080600)。我们在每一侧添加了40px边框,因此最终的框架尺寸将为(1080+40*2600+40*2),即(1160680)
import numpy
import cv2
import random
image=cv2.imread(r"C:\Users\Sriram\Desktop/img.png")
print(image.shape)
image=cv2.resize(image,(1080,600))
fourcc=cv2.VideoWriter_fourcc(*"MP4V")
def rand():
n=random.randrange(0,255,15)
x=random.randrange(0,255,15)
y=random.randrange(0,255,15)
return cv2.copyMakeBorder(image,40,40,40,40,cv2.BORDER_CONSTANT,None,(x,n,y))
#cv2.imwrite(r"C:\Users\Sriram\Desktop/new.jpg",image)
l=[rand() for i in range(30)]
print(l)
video=cv2.VideoWriter(r"C:\Users\Sriram\Desktop/video.mp4",fourcc,25,(1080,600))
for i in l:
video.write(i)
cv2.destroyAllWindows()
video.release()
import numpy
import cv2
import random
image=cv2.imread(r"C:\Users\Sriram\Desktop/img.png")
print(image.shape)
image=cv2.resize(image,(1080,600))
fourcc=cv2.VideoWriter_fourcc(*"MP4V")
def rand():
n=random.randrange(0,255,15)
x=random.randrange(0,255,15)
y=random.randrange(0,255,15)
return cv2.copyMakeBorder(image,40,40,40,40,cv2.BORDER_CONSTANT,None,(x,n,y))
#cv2.imwrite(r"C:\Users\Sriram\Desktop/new.jpg",image)
l=[rand() for i in range(30)]
print(l)
video=cv2.VideoWriter(r"C:\Users\Sriram\Desktop/video.mp4",fourcc,25,(1160,680))
for i in l:
video.write(i)
cv2.destroyAllWindows()
video.release()