Buckets:
| import cv2 | |
| import imageio | |
| import numpy as np | |
| def read(path, size=None, limit=None): | |
| capture = cv2.VideoCapture(str(path)) | |
| frames = [] | |
| while limit is None or len(frames) < limit: | |
| ok, frame = capture.read() | |
| if not ok: | |
| break | |
| frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| frames.append( | |
| cv2.resize(frame, size, interpolation=cv2.INTER_AREA) if size else frame | |
| ) | |
| capture.release() | |
| return np.stack(frames) | |
| def write(path, frames, fps): | |
| imageio.mimwrite( | |
| str(path), list(frames), fps=fps, codec="libx264", quality=8, macro_block_size=1 | |
| ) | |
| def hstack(*clips): | |
| length = min(len(clip) for clip in clips) | |
| return np.concatenate([clip[:length] for clip in clips], axis=2) | |
| def overlay(background, foreground, mask, alpha=0.8): | |
| length = min(len(background), len(foreground), len(mask)) | |
| weight = alpha * mask[:length, ..., None] | |
| blended = background[:length] * (1 - weight) + foreground[:length] * weight | |
| return blended.astype(np.uint8) | |
Xet Storage Details
- Size:
- 1.05 kB
- Xet hash:
- 024d72afb7095dc6d91ccc1bf40083953841c15a9585db03f08adddc249372e3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.