Reading an image from a movie file


Another really important source of visual information are movie files. The tool box that you have been using ships with a large number of images and also smaller number of movies.

So let’s scroll through the provided images, and some of them are familiar ones that you have either seen already or will see later during this course, and right down the bottom here there is a movie file, we know it is a movie file because it has got an extension of .MPG, short for MPEG. And we will talk a little bit about that shortly.

Let me double click on this movie file and it comes up in a movie player. It is not a brilliantly exciting movie; it is a view from a window looking down on an urban intersection, with cars and trucks. It is in black and white, and it runs for only a very short amount of time.

So what we are going to do now is to read some frames from that movie sequence into the MATLAB workspace. I am going to do that by creating a movie camera object. This is related to the camera object we looked at before, but this particular movie object is of the class movie.

We are going to give it the name of the file that contains the movie, traffic_sequence.mpg. Open that up and it creates a new movie object in our workspace. Now we can grab frames from this movie, by using the grab method, just as we have done for the other camera objects we have seen before. What that does is grab the first frame from the movie and display it in a window. I can get the next frame. And the next frame, the next frame, and so on.

If we display the movie object just by typing in the name and return, it gives us some information about the movie. It tells us the size of the individual frames, that they are 720 columns wide, 576 rows high. The movie is recorded at 30 frames per second and there’s a total of 351 frames in this movie, for a run time of 11.7 seconds.

Movie file formats have got a lot in common with the image file formats that we looked at a little while ago. They comprise a container which holds a number of objects, the first object is the header which says something about the size of each frame within the movie and the format in which the audio and video is encoded.

Often times we refer to what is called a video codec and that is short hand for the compression algorithm that is applied to the image frames within the movie. And there is also an audio codec, which is the algorithm which compresses the audio information.

There is also some metadata associated with the movie. It might have the type of camera, the camera settings and again the location at which the movie was taken. The bulk of the file though is occupied with the frames of the movie, which are compressed using a video codec, and the audio data which is compressed using the audio codec. So we need to specify the format of the container as well as the format of the movie data and the audio data.

So when we refer to something like an mpeg4 movie, to be more precise, what we are talking about is an mpeg4, part fourteen container. That means it is defined by a standard, part of the mpeg4 standard, part fourteen of that standard. And the video is compressed using the H.264 standard, and the audio is compressed using the AAC standard. So mpeg4 is a short hand for a lot more detail about the container, the video and the audio.

And just as with image file formats, there’s a bunch of movie formats that are commonly used today and some of them are container formats, some of them are codec formats and some of them specify the container and the codec.

We store movies in files, typically in an MPEG format. Let’s look at what’s inside one of those movie files, and how we can grab a frame from a movie as an image and put it into the MATLAB workspace.

Professor Peter Corke

Professor of Robotic Vision at QUT and Director of the Australian Centre for Robotic Vision (ACRV). Peter is also a Fellow of the IEEE, a senior Fellow of the Higher Education Academy, and on the editorial board of several robotics research journals.

Skill level

This content assumes an understanding of high school-level mathematics, e.g. trigonometry, algebra, calculus, physics (optics) and some knowledge/experience of programming (any language).

More information...

Rate this lesson


Check your understanding

Leave a comment