A common question that you might face after reading the previous section, is why don't we work with MP4 (or other compressed formats) videos so that we do not face as many space issues? The answer is pretty simple if you stop and think about it. The advantages of compressed video files cease to exist the moment we load them in MATLAB. Once they are loaded, the frames contain all the information needed to fill all the elements of a matrix comprising all the loaded frames. Therefore, it is the same thing as loading an uncompressed video.
We can verify this by inspecting the variables testStill
and testMotion
created in the previous section. We will do it using MATLAB function whos
, designed for reporting all information about a given variable. The name of the variable must be given as input, in a string
format. Let's call this function for our two variables. The following line of code gives information for testStill
:
>> whos('testStill')
The output of the previous code is as follows:
Name Size Bytes Class Attributes testStill 4-D 25920000 uint8
The following line of code gives information for testMotion:
>> whos('testMotion')
The output of the previous code is as follows:
Name Size Bytes Class Attributes testMotion 4-D 25920000 uint8
As you can see, both the variables have the same size in bytes. This proves our previous speculation and leads to a new, very important question: since we can only store a very limited amount of frames in our Workspace, how can we process large videos?
The answer to this question is to design our video processing tasks so that they work with small chunks of our video (for example, 10 frames at a time) and then combine the results to form the processed video.
We will frequently need to apply some processing tasks to the frames of an already acquired video sequence. As you may have already understood, this is a very tricky problem, since we take into consideration the size of the video when it is imported to MATLAB. Let's see how we can tackle such a task.