使用Open CV和SimpleUploadedFile从视频中获取图像

时间:2017-09-20 03:24:17

标签: python opencv firebase

我有以下代码来创建InMemoryUploadedFile。我之所以这样做是因为我使用了firebase并将图像和视频保存在那里。它可以被认为类似于S3存储......在我的测试中我有以下内容:

file = BASE_DIR + '/static/samy-assets/img/landing/small.mp4'
video = SimpleUploadedFile(file, open(file, 'rb').read(), content_type="video/mp4")
response = self.client.post('/media/upload/', {'file': video}, follow=True)

这可以将视频上传到firebase,但是现在我需要从视频中获取一个框架以显示为"预览"。我有这段代码:

cap = cv2.VideoCapture(media)
cap.set(cv2.CAP_PROP_POS_MSEC, 1000)  # Go to the 1 sec. position
success, frame = cap.read()  # Retrieves the frame at the specified second
print(success)
cv2.imwrite("image.jpg", frame)  # Saves the frame as an image
cv2.waitKey()

但是我收到的错误是:

an integer is required (got type InMemoryUploadedFile)

任何帮助将不胜感激......

0 个答案:

没有答案