我只想让视频与网络浏览器兼容。从我获取图像路径的视频对象中,图像是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的工具
答案 0 :(得分:1)
创建VideoWriter时,您应该使用(width, height)
元组作为帧大小,而不是(height, width)
。