import sys
sys.path.append(".")
import redis
import base64
import os
def video_to_base64(file_path):
base64_encoded = None
try:
with open(file_path, "rb") as video_file:
# 读取视频文件的内容
video_content = video_file.read()
# 使用base64进行编码
base64_encoded = base64.b64encode(video_content)
except Exception as e:
print("error happens when encoding data",e)
return base64_encoded
def base64_to_video(data_str,target_file):
# 1. decode the data
data = base64.b64decode(data_str)
# 2. output into the file
flag = True
if "/" not in target_file:
flag = False
print('not / in the target file path')
return flag
try:
target_path = target_file[:target_file.rindex("/")]
if not os.path.exists(target_path):
os.makedirs(target_path)
with open(target_file,"wb") as f:
f.write(data)
except Exception as e:
print("error happens when output the file",e)
flag = False
return flag
if __name__ == '__main__':
try:
r = redis.Redis(host='10.99.211.163', port=6379, decode_responses=True, password='BgnfYqqrnO')
print(type(r.get('video')))
except Exception as e:
print(e)
基于Python将视频文件读写到Redis
最新推荐文章于 2024-10-27 11:29:42 发布