OpenCV VideoWriter 错误 "dimensions too large for MPEG-4"
OpenCV VideoWriter Error "dimensions too large for MPEG-4"
我有一些帧(尺寸:8192x2160)是通过并排连接两个 4096x2160 帧生成的。使用 OpenCV VideoWriter 将这些帧写入视频文件时,出现此错误:dimensions too large for MPEG-4
这是我的代码:
video_name = "vid.mp4"
images = sorted([img for img in os.listdir(images_folder) if img.endswith(".png")])
frame = cv2.imread(os.path.join(images_folder, images[0]))
height, width, layers = frame.shape
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(video_name, fourcc, FRAME_RATE, (width, height))
for image in images:
video.write(cv2.imread(os.path.join(images_folder, image)))
cv2.destroyAllWindows()
video.release()
这也不起作用:
video_name = "output.avi"
video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*'DIVX'), 10, (width, height))
有人有什么建议吗?
使用不同的编解码器或使用 cv2.resize
缩小每一帧。
DivX 与 MPEG-4 Part 2 和 H.263 相关。
那些视频格式规格无法处理那个大小的帧。它们在设计上有限制,低于您的要求。没有编解码器(实现)可以解决这个问题。
如果您需要处理那种尺寸的帧,则需要不同的格式。
您需要研究可用的 formats/codecs,看看它们是否合适。
更现代的 formats/codecs 更有可能 专为 大尺寸车架设计。 HEVC、AV1、...可能是合适的。
有些non-modern formats/codecs可能也没有这个限制。 MJPEG (MJPG
) 可以工作(刚刚测试过)。它内置于 OpenCV 中,始终存在。 Ffmpeg 也有一个实现,所以这是一个非常兼容的编解码器选择。
我有一些帧(尺寸:8192x2160)是通过并排连接两个 4096x2160 帧生成的。使用 OpenCV VideoWriter 将这些帧写入视频文件时,出现此错误:dimensions too large for MPEG-4
这是我的代码:
video_name = "vid.mp4"
images = sorted([img for img in os.listdir(images_folder) if img.endswith(".png")])
frame = cv2.imread(os.path.join(images_folder, images[0]))
height, width, layers = frame.shape
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(video_name, fourcc, FRAME_RATE, (width, height))
for image in images:
video.write(cv2.imread(os.path.join(images_folder, image)))
cv2.destroyAllWindows()
video.release()
这也不起作用:
video_name = "output.avi"
video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*'DIVX'), 10, (width, height))
有人有什么建议吗?
使用不同的编解码器或使用 cv2.resize
缩小每一帧。
DivX 与 MPEG-4 Part 2 和 H.263 相关。
那些视频格式规格无法处理那个大小的帧。它们在设计上有限制,低于您的要求。没有编解码器(实现)可以解决这个问题。
如果您需要处理那种尺寸的帧,则需要不同的格式。
您需要研究可用的 formats/codecs,看看它们是否合适。
更现代的 formats/codecs 更有可能 专为 大尺寸车架设计。 HEVC、AV1、...可能是合适的。
有些non-modern formats/codecs可能也没有这个限制。 MJPEG (MJPG
) 可以工作(刚刚测试过)。它内置于 OpenCV 中,始终存在。 Ffmpeg 也有一个实现,所以这是一个非常兼容的编解码器选择。