MP4不起作用用于制作框架的视频,但AVI起作用
我正在使用以下代码从我拥有的图片中创建电影,并使用以下代码段:
import cv2
import os
image_folder = 'shots'
video_name = 'video.avi'
fps = 25
images = [img for img in os.listdir(image_folder) if img.endswith(".png")]
images = sorted(images)[:][:steps]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, 0, fps, (width, height))
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
cv2.destroyAllWindows()
video.release()
问题是,当我将扩展名更改为mp4
时,它不起作用。如何更改代码以使其能够工作? mp4
的原因是该过程的速度非常慢,我认为这是因为avi
比mp4
具有更高的质量。
I am using the following code to create a movies out of pictures that I have and use the following code snippet:
import cv2
import os
image_folder = 'shots'
video_name = 'video.avi'
fps = 25
images = [img for img in os.listdir(image_folder) if img.endswith(".png")]
images = sorted(images)[:][:steps]
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, 0, fps, (width, height))
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
cv2.destroyAllWindows()
video.release()
The problem is that when I change the extension to mp4
it does not work. How can I alter my code so that I can get it to work? The reason for mp4
is the speed of the process which is very slow and I think it is because avi
has more quality than mp4
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
cv2.VideWriter
语法中具有(文件名,fourcc,fps,frameSize)
这些参数您缺少一个称为fourcce> fourcc
的参数(fourcc:4--编解码器的字符代码用于压缩帧)In
cv2.VideoWriter
syntax have(filename, fourcc, fps, frameSize)
these parametrs you are missing one parameter calledfourcc
(fourcc: 4-character code of codec used to compress the frames)