0

I have a flask app. When i run it on my pc it can take videofile, create non-black thumbnail, using flowing code:

uploaded_files = request.files.getlist("file[]")
for i in uploaded_files:
     ......
     vcap = cv2.VideoCapture(file_path)
     b = io.BytesIO()
     res, im_ar = vcap.read()
     while im_ar.mean() < 2 and res:
         res, im_ar = vcap.read()
     r=cv2.resize(im_ar, size, interpolation = cv2.INTER_CUBIC)
     b=cv2.imencode('.jpeg', r)[1]
     s3.Bucket('MY_BUCKET').put_object(Key=MY_KEY, Body=b.tobytes(), ACL= 'public- 
     read',ContentType='image/jpeg', ContentDisposition= 'inline')

For some reason cv2.VideoCapture() doesn't accept any form of "i" as argument: "i.read()/i.file/etc". btw, maybe u can help with that? So I have to use "file_path" which can be a link or a path to local file, both works when it's running on my pc.

type(vcap) = class 'cv2.VideoCapture' type(im_ar) = class 'numpy.ndarray'

But when i run exactly the same code on remote ubuntu server, use the same files, i get this: File "/home/ubuntu/scanner/app/routes.py", line 478, in b while im_ar.mean() < 2 and res: AttributeError: 'NoneType' object has no attribute 'mean'

OpenCV 3.4.3 FFMPEG: YES

How can i fix it?

  • i noticed, that when i save original videofiles with i.save(), they become damaged and have 0-size (is this issue connected with ubuntu permissions?) but when i upload them on amazon, everything is ok, i can watch them, using amazon-link (but may be the link isn't accessible immediately after creation and i shoud try to sleep a bit after uploading?) – Gintoki Sakata Oct 17 '18 at 15:17
  • KINDASOLVED in ubuntu cv2.VideoCapture() is able to accept local "file_path" and u should i.stream.seek(0) before i.save() for proper upload xDDDdd incredible X-----D – Gintoki Sakata Oct 17 '18 at 20:18
  • Having the same problem, could you please elaborate on the solution? – Ludovico Verniani Jun 09 '20 at 19:47

0 Answers0