Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- def _get_video_thumb(path: str, tiny: bool = False):
- ## <-- New requests stop being processed here -->
- vid = cv2.VideoCapture(path)
- vid.set(cv2.CAP_PROP_POS_FRAMES, (int(vid.get(cv2.CAP_PROP_FRAME_COUNT)) // 3) - 1)
- ret, frame = vid.read()
- ## <-- Requests resume here -->
- if not ret:
- raise RuntimeError('failed to read video frame')
- img = Image.frombytes('RGB', (frame.shape[1], frame.shape[0]), cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
- with BytesIO() as bio:
- img.save(bio, format='JPEG')
- bio.seek(0)
- return bio.read()
- ...
- @app.route('/_/thumbnailer')
- async def thumbnailer():
- full_path, check = await verify_path(request.args.get('path', None))
- if not check:
- await abort(500)
- i = await run_sync(func)(path=str(full_path), tiny=request.args.get('scale', False, type=lambda v: v.lower() == 'true'))
- return await make_response(i, 200, {'Content-Type': 'image/jpeg'})
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement