1 回答
TA贡献1871条经验 获得超8个赞
在函数frame_to_base64(frames)中,frames已经是单个图像,因为VideoCapture.read返回单个图像。它也是一个 opencv 图像(numpy 数组),它不是你可以使用“with”的东西。
def frame_to_base64(frame):
return base64.b64encode(frame)
如果你想读取视频的所有帧,你应该这样做:
import cv2
import base64
def footage_to_frame(video):
vidcap = cv2.VideoCapture(video)
frames = []
# read until no more frames exist in the video
while True:
success, frame = vidcap.read()
if (success):
frames.append(frame)
else:
# unable to read a frame
break
return frames
def frames_to_base64(frames):
frames_b64 = []
# iterate frames and convert each of them to base64
for frame in frames:
frames_b64.append(base64.b64encode(frame))
return frames_b64
尽管根据视频长度,您可能会遇到内存问题。
添加回答
举报