Splitting a video into pieces

54 Views Asked by At

I am trying to split a video in to different sections and have them saved in a array. I found this code, but when I run it I get: type error: 'none type' object is not subscriptable. I can't see anything wrong in the code.

I got the code working Fixed code:

import cv2

cap = cv2.VideoCapture('Test_5_vid.MP4')
n_rows = 3
n_images_per_row = 3

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    
    if not ret: #this is what needed to be added 
        print('not working')
        break
    
    height = 1080
    width = 1080

    roi_height = int(height / n_rows)
    roi_width = int(width / n_images_per_row)

    images = []

    for x in range(0, n_rows):
        for y in range(0,n_images_per_row):
            tmp_image=frame[x*roi_height:(x+1)*roi_height, y*roi_width:(y+1)*roi_width]
            images.append(tmp_image)
           
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
0

There are 0 best solutions below