Python Forum
memory issue loading movie to numpy array - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: memory issue loading movie to numpy array (/thread-22303.html)



memory issue loading movie to numpy array - djf123 - Nov-07-2019

I have a movie, .mts file, that I want to be able to read into a numpy array that is (w,h,3,f), where w is the frame's width, h its height, and f the number of frames in the movie. 3 refers to the RGB value. Below is my program for doing it. My problem though is that when I run it that it consumes all of the memory on my computer and everything freezes up. I don't understand why since the movie is only 26 MB and I have 3.7GB of RAM memory . I am using Spyder and when not running it says memory is 36% in the lower right hand corner and then jumps up to 96% memory when the program is running and freezes. Why is this happening and how do I fix this? Is there a better way to write this?

import cv2
    
cap2 = cv2.VideoCapture('//home//jr//Desktop//Movie1.MTS')
movieA=[]
while(cap2.isOpened()):
    status, frame = cap2.read()
    if status==True:
        movieA.append(frame)
    else:
        break
cap2.release()



RE: memory issue loading movie to numpy array - ThomasL - Nov-07-2019

The video file is encoded and shrinked in size, if you want an array of the data
it needs to be decoded and that means the amount is increasing dramatically.
https://www.wowza.com/blog/video-codecs-encoding