首页 > 解决方案 > 有没有办法在 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()

我确实尝试过视频,但这并不容易。

有没有人做过同样的过程?

谢谢。

标签: pythondjangoopencvfilefield

解决方案


如果您只想保存 fileField 而无需编辑它,您可以

with  open( file_path , "rb", buffering=0) as vf:
    with ContentFile(vf.read() , file_path ) as vc:

推荐阅读