Advertisement
samicrusader

Untitled

Jul 28th, 2023
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. ...
  2.  
  3. def _get_video_thumb(path: str, tiny: bool = False):
  4.     ## <-- New requests stop being processed here -->
  5.     vid = cv2.VideoCapture(path)
  6.     vid.set(cv2.CAP_PROP_POS_FRAMES, (int(vid.get(cv2.CAP_PROP_FRAME_COUNT)) // 3) - 1)
  7.     ret, frame = vid.read()
  8.     ## <-- Requests resume here -->
  9.     if not ret:
  10.         raise RuntimeError('failed to read video frame')
  11.     img = Image.frombytes('RGB', (frame.shape[1], frame.shape[0]), cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
  12.     with BytesIO() as bio:
  13.         img.save(bio, format='JPEG')
  14.         bio.seek(0)
  15.         return bio.read()
  16.  
  17. ...
  18.  
  19. @app.route('/_/thumbnailer')
  20. async def thumbnailer():
  21.     full_path, check = await verify_path(request.args.get('path', None))
  22.     if not check:
  23.         await abort(500)
  24.     i = await run_sync(func)(path=str(full_path), tiny=request.args.get('scale', False, type=lambda v: v.lower() == 'true'))
  25.     return await make_response(i, 200, {'Content-Type': 'image/jpeg'})
  26.  
  27. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement