How do I read a video file of arbitrary format and store its frames in a variable?
1 view (last 30 days)
Matthew Simoneau on 27 Jan 2011
See Reading Video Files with Video Reader.
Here is an example from that page:
xyloObj = VideoReader('xylophone.mpg');
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
% Preallocate movie structure.
mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k);
% Play back the movie once at the video's frame rate.
movie(mov, 1, xyloObj.FrameRate);
Walter Roberson on 28 Jan 2011
I have included a complete 36 minute video on the line below:
That is the entire file contents, the single character '$'.
I have included a completely different 36 minute video on the line below:
That is the entire file contents, the single character '$'. But it's a different video than the other one. The first one was a small video that was a constant red for the entire 36 minutes, but this other one is a larger video that fades from yellow to black over the entire 36 minutes.
You look dubious, but it is true. Here, I'll show you:
Character with value decimal 36, 36 minute movie, deterministic behaviour, fixed size for each program -- is it not clear that such video files could indeed be created and read by some display program?
But we have a conflict. Does $ mean constant red or does it mean fading yellow? Clearly we can write a program for either meaning.
What can we conclude? This: that it is not possible to write a program that can convert "any video irrespective of its format". Every data file represents an infinite number of different videos when interpreted by appropriate programs.
The meaning of any particular data file depends on the program that is to read it. There is no universal catalog of video formats and there never can be.