Jho
Jho

Reputation: 7

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

I'm working on django project and I met a problem with handling videos.

In the project, if user upload an image then server handles it with OpenCV and save it.

This is how I did.

_, 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()

I did try with video, but it wasn't easy.

Is there anyone who did the same process?

Thanks.

Upvotes: 0

Views: 157

Answers (1)

faruk
faruk

Reputation: 151

if you want only to save fileField without edit it you can

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

Upvotes: 1

Related Questions