我有一个二进制的mp4视频文件字符串,并希望将它转换回mp4文件,以便使用openCV库从其中获取单个帧。
import cv2
import tempfile
temp_path = tempfile.gettempdir()
video_binary_string = 'AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAQC0ttZGF0AQIUGRQmM...'
with open(temp_path+'/video.mp4', 'wb') as wfile:
wfile.write(video_binary_string)
cap = cv2.VideoCapture(temp_path+'/video.mp4')
success, frame = cap.read()
print success
>>> False如果帧读取正确,则为True
我知道这不是写视频文件的正确方式。我试着用FFMPEG做这件事,但我不明白这是文档。
请给出一个简单的解释如何将二进制字符串转换回视频的例子,用这种或其他方式。
发布于 2016-04-25 12:49:14
解决我的问题的方法是,我必须首先解码编码的字符串。
import cv2
import tempfile
import base64
temp_path = tempfile.gettempdir()
video_binary_string = 'AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAQC0ttZGF0AQIUGRQmM...'
decoded_string = base64.b64decode(video_binary_string)
with open(temp_path+'/video.mp4', 'wb') as wfile:
wfile.write(decoded_string)
cap = cv2.VideoCapture(temp_path+'/video.mp4')
success, frame = cap.read()
print success
>>> Truehttps://stackoverflow.com/questions/36795267
复制相似问题