python - 有没有办法在 django 文件字段中使用 open-cv 转换视频?
问题描述
我正在开发 django 项目,但在处理视频时遇到了问题。
在项目中,如果用户上传图像,则服务器使用 OpenCV 处理并保存它。
我就是这样做的。
_, out_img = cv2.imencode('.jpg', np.asarray(result_image)).tobytes()
out_file = ContentFile(out_img)
out_path = '/path/to/save'
filemodel.file_field.save(out_path, out_file)
filemodel.save()
我确实尝试过视频,但这并不容易。
有没有人做过同样的过程?
谢谢。
解决方案
如果您只想保存 fileField 而无需编辑它,您可以
with open( file_path , "rb", buffering=0) as vf:
with ContentFile(vf.read() , file_path ) as vc:
推荐阅读
- ios - Swift:基于日期对核心数据子实体进行排序
- json - 从 GoLang 的响应中检索到漂亮的 JSON
- bash - 将每行开头的数字复制到行尾
- spring-boot - 将主题列表从应用程序 yml 传递给 KafkaListener
- docker - 在 docker-compose.yml 文件中设置环境变量与在 .env 文件中设置该变量相同吗?
- angular - “商店”类型上不存在属性“replaceReducer”
' 升级后@ngrx/store - linux - KSH Shell 脚本不压缩文件
- node.js - 节点 - 嵌套 For 循环异步行为
- c# - POST 成功但数据没有出现在控制器中
- excel - Excel Shortout 键格式化轴绑定?