In this lecture, we're going to create a script which instructs all the images that's make of this
video file.
So this is in my directory.
And you can play that in Ripple.
It's a three seconds long video.
And it's made of 90 frames, so 90 images, 90 pictures stacked on top of each other and being rendered
every fraction of a second or so, and we see that as a video.
All right.
So we're going to extract all the frames and save them inside a folder.
So let's create an empty folder and name its images.
So inside that images will go, all the jpg frames 90 of them.
So go to main those p y and start coding.
So the first thing we want to do is perhaps.
Load the video inside Python.
With COVID to that video capture, that is a class which expects us arguments, guess what, the video
that's aimed before the path to the video file?
So this one is this that will create.
You will see if you print adults.
Nothing impressive.
So that's the output of this print function.
So that means this is an object instance and a video capture object instance with this particular I.D.
in memory.
So in the computer memory, we don't need that idea just there.
But the idea is that this is a class and that is the object instance.
And as you see, nothing impressive.
But if you apply the right methods, which is a specific method of video capture object instances.
So if you execute this now we see something.
So the output of this is a tuple.
You see, it's a tipper which starts in here.
So the opening parentheses, this is the first item of the tuple.
You see the comma here and then we have the second item, which is a non-point array.
So the second item and here this is the parentheses of the tip of the closing parentheses.
So we have two items.
The Boolean.
And the umpire the non-point array represents the very first frame of the video.
So the video has 90 frames and reads, we'll get you the first frame, but that's not exactly true.
Reads We will actually get you the next frame in line.
So we have 90 frames.
If you execute reads once you get the first frame, if you execute it one more time.
The second reads, methods will extract the second frame.
You see, we have no one.
Well, we also have Elizabeth, that's from the lost execution because this is an interactive shell
of the reptile.
The way reptile works is that it sends the code in an interactive shell, so it keeps the shell the
session open.
And we have to read the methods are returning this new temple so true and the the frame.
Which goes in here and so on.
And then another to fall for the second method.
So the next frame?
So what is true?
What is true here?
What is the other true there?
Well, we get through whenever a frame was found, because if we keep executing this, if we add it's
in total 90 Reid's methods, if we had 90 agreed methods here like we had to keep adding them and so
on after the 90th methods, we wouldn't get any frames anymore.
And the output would be false for this.
So this first item of the table basically tells us that a frame was found and we could also get false
if the video doesn't exist.
So if you see videos for file path that doesn't exist and you execute and you scroll down here, yeah,
we see falls, we see falls four times.
So false, false, false and false for all the four times we executed the reads and none means no frame.
So let's change videos to video and let's look at 86 more related methods.
No.
Or is there a better way to do this without having to execute slides 90 times?
Well, yes, there is.
Using a while loop, and it works like this.
So I'm going to delete this print function.
And what I'll do is I will the right to variables success and frame.
Equals to vets Sue, the Colts stores, imports open CV and creates a video object, and then in success,
we will store the true the Boolean value, so success will be equal to either true or false, and frame
will be equal to the next item of the tipple that we get from this, which is the Nampai array, the
frame.
So in this first call of reads, we will get the first frame, then we see wild success.
What we do is, we say severe to I am right.
And we want to rights this first frame in an image file incites images here.
This folder, therefore what we do, is we specify the path of that image file, which is images slash.
Hmm, what's the name of this?
So we're going to have nine two images.
It makes sense to use some sort of numbering rights.
So we could see a placeholder and say count here.
So count could start from one.
That's jpg.
So the first frame would have the name one dot jpg stored inside images, and then we increase count
by one using this formula.
So in the second iteration count will be the current Collins value, which is one plus one.
Second, we'll get a value of two.
So again, we get the first frame count.
It's one we write the first frame on the Rwanda jpg.
We increase the count by one second is to know the loop is run again was true.
So it's true we get the second image rewritten.
But what do your rights here?
Well, the frame.
But this time we want to stall.
We want to get the next frame, so we see success.
Frame is to go to video, Dots reads.
So that's what gets us the second frame.
And that will be written as to the jpg.
So this frame here?
And that's the idea or run.
And you see the images are being generated.
So one is here.
Two is here.
So it's in an alphabetical order.
And then you have three somewhere here.
Right?
And so one so 90s should be the last image.
However, that was not the case because I think we should change the order of these lines in here because
we get the first frame.
And before we get the second frame, we want to write the first frame.
In here.
So get the first frame right, it's in an image file and then then get to the second frame.
Increase the count by one.
So we have the second frame currently in frame, therefore that will be written in frame.
And then we get the third frame increase.
That's two three.
Right?
The third frame in three jpg and so on.
So that should work.
I'm going to delete all these files from here.
You can delete them either by going to here one by one, or you could go to the shell and see ah, and
for or remove Bashar and you want to remove everything that is inside images.
So images slash asterisk that's deleted all my images on there images.
Now we're going to run again.
The last one should be 90, the JRPG this time, so it's still generating new images.
And there we go.
So 9:02, That's the last frame, 89, slightly different from 1988 87.
So they change a little bit from each other.
Right.
And that's our final code.
So even though this is not very useful to just extract some images from a video, but it could be useful.
And what we will do in the next video where we are going to extract only one frame from a certain timestamp
in the video.
So given a timestamp, we will get the frame of the image for that timestamp of the video.
Let's do that in the next video.