BTS army(Korean boys)from PIL import Imageimport cv2, numpy as np, ossrc = "/mnt/data/#longvideo
Kddhaka 007
0:00 / 0:00
BTS army(Korean boys)from PIL import Imageimport cv2, numpy as np, ossrc = "/mnt/data/#longvideo
76 просмотров · 2 дня назад
Kddhaka 007
8,14 тыс. подписчиков
76 просмотров · 2 дня назад
a_clean_sharp_high_resolution_collage_style_imag.png"out = "/mnt/data/korean_boys_one_by_one_slideshow.mp4"img = Image.open(src).convert("RGB")w, h = img.size# The generated collage is a 5x2 grid.# Crop each portrait separately, preserving the individual frame.left, top, right, bottom = 0, 0, w, hgap_x = 5gap_y = 5cell_w = (w - 4 * gap_x) / 5cell_h = (h - gap_y) / 2crops = []for row in range(2): for col in range(5): x1 = int(col * (cell_w + gap_x)) y1 = int(row * (cell_h + gap_y)) x2 = int((col + 1) * cell_w + col * gap_x) y2 = int((row + 1) * cell_h + row * gap_y) crop = img.crop((x1, y1, min(x2, w), min(y2, h))) crops.append(crop)# Make a vertical 1080x1920 slideshow, one portrait at a time.W, H = 1080, 1920fps = 30seconds_each = 1.5frames_each = int(fps * seconds_each)fourcc = cv2.VideoWriter_fourcc(*"mp4v")writer = cv2.VideoWriter(out, fourcc, fps, (W, H))for crop in crops: c = np.array(crop) ch, cw = c.shape[:2] scale = min(W / cw, H / ch) nw, nh = int(cw * scale), int(ch * scale) resized = cv2.resize(c, (nw, nh), interpolation=cv2.INTER_LANCZOS4) canvas = np.zeros((H, W, 3), dtype=np.uint8) x = (W - nw) // 2 y = (H - nh) // 2 canvas[y:y+nh, x:x+nw] = cv2.cvtColor(resized, cv2.COLOR_RGB2BGR) for _ in range(frames_each): writer.write(canvas)writer.release()print(f"वीडियो तैयार है: {out}"))