gpt4 book ai didi

javascript - python3 opencv 不保存可读视频

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:43 24 4
gpt4 key购买 nike

我只是想让视频与网络浏览器兼容。从视频对象中我得到图像路径,图像是 png 类型我只想将这些图像转换为视频并在浏览器中显示。

    path = settings.WEBUI_ROOT + '/events/'
if not os.path.exists(path):
os.makedirs(path)
video = Video.objects.get(id=video_id)
movements = Image.objects.filter(video=video)

frame = cv2.imread(movements[0].file_path, 1)
height, width, channel = frame.shape
video_name = 'eventvideo.mp4'
output_video = cv2.VideoWriter(path + video_name, cv2.VideoWriter_fourcc(*'MP4V'), 15, (height, width))

for _, image in enumerate(movements):
image = Image.objects.get(id=image.id)
frame = cv2.imread(image.file_path)
output_video.write(frame)
output_video.release()

result = {
'success': True,
'path': "events/" + event_video_name
}
return JsonResponse(result, safe=False)

使用的工具有Django和JS

最佳答案

创建 VideoWriter 时,您应该使用 (width, height) 元组作为帧大小,而不是 (height, width)

关于javascript - python3 opencv 不保存可读视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50902687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com