gpt4 book ai didi

python - 从字节中将视频保存在python中

转载 作者:行者123 更新时间:2023-12-02 17:28:03 24 4
gpt4 key购买 nike

我有2个微服务一个用Java编写,并以字节[] 的形式发送视频到 B ,它是用python编写的。

B 正在使用openCV对视频进行一些处理,尤其是此命令

 stream = cv2.VideoCapture(video)

该命令在由流媒体或准备就绪的本地视频提供时效果很好,但是当我给它发送我的 request.data 时,由Java发送的消息说

TypeError: an integer is required (got type bytes)



所以我的问题是:

有什么方法可以将视频从我从Java接收的字节保存到磁盘,还是可以将字节提供给 cv2.capture

谢谢。

最佳答案

只是您自己的解决方案的一个小改进:使用with context-manager会为您关闭文件,即使发生意外情况:

FILE_OUTPUT = 'output.avi'

# Checks and deletes the output file
# You cant have a existing file or it will through an error
if os.path.isfile(FILE_OUTPUT):
os.remove(FILE_OUTPUT)

# opens the file 'output.avi' which is accessable as 'out_file'
with open(FILE_OUTPUT, "wb") as out_file: # open for [w]riting as [b]inary
out_file.write(request.data)

关于python - 从字节中将视频保存在python中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57865656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com