有没有办法在 django 文件字段中使用 opencv 转换视频?

Is there a way to convert video with open-cv in django file-field?

我正在做 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: