我正在尝试将视频转换为帧,并将这些帧转换为 Base64 字符串。我无法这样做并得到一些例外。下面是我的代码:
import cv2
import base64
def footage_to_frame(video):
vidcap = cv2.VideoCapture(video)
success, frames = vidcap.read()
if success:
return frames
def frame_to_base64(frames):
with frames as frame:
frame_b64 = base64.b64encode(frame.read())
return frame_b64
该方法的函数调用是:
frames = converter.footage_to_frame("/Users/myname/Desktop/video.mp4")
converter.frame_to_base64(frames)
以下是我在控制台中收到的错误:
File "/Users/myname/Desktop/Test/src/service/converter.py", line 13, in frame_to_base64
with frames as frame:
AttributeError: __enter__
ITMISS
相关分类