Skip to content

Instantly share code, notes, and snippets.

@NickyAlan
Created November 27, 2023 14:08
Show Gist options
  • Save NickyAlan/4c45aa34a6710f704f765ad376b86bb9 to your computer and use it in GitHub Desktop.
Save NickyAlan/4c45aa34a6710f704f765ad376b86bb9 to your computer and use it in GitHub Desktop.
play video in file explorer
# Might ruin your SSD
import cv2
import time
import numpy as np
VIDEO_PATH = "video.mp4"
FOLDER = "playground" # folder that play video, create this folder for sure!
ROWS, COLS = 7, 4 # number of images
cap = cv2.VideoCapture(VIDEO_PATH)
frames_list = []
# Read and process each frame
i = 0
while True:
ret, frame = cap.read()
if not ret: break
if i%2 == 0 : frames_list.append(np.array(frame))
i+=1
H, W, _ = frames_list[0].shape
NW, NH = int(W/ROWS), int(H/COLS) # size of each image
time.sleep(2) # wait for an exciting video
for frame_idx in range(0, len(frames_list)) :
idx = 1
for col in range(COLS) :
startc_idx, endc_idx = col*NH, (col+1)*NH
for row in range(ROWS) :
startr_idx, endr_idx = row*NW, (row+1)*NW
cv2.imwrite(f'{FOLDER}/{idx}.jpg', frames_list[frame_idx][startc_idx: endc_idx, startr_idx: endr_idx,:])
idx += 1
time.sleep(1.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment