And this video of the riots, a program which gets from the user a timestamp and returns the frame corresponding
to that timestamp in a video, a timestamp could look something like this.
For example, zero zero four hours zero six four minutes seven point eighty seven four seconds.
So we warned the timeframe at that time stamp in a video.
Let's do this.
I import almost CV and I create a video object using that video file.
So it's a short three second video.
One, two and three seconds.
Right, then I'm extracting the number of frames here.
So how many frames does the video have and how many frames are there per second?
We want these two variables.
These two numbers and I'll explain you why I need them.
So let's run this to see what we get.
Yes, a number of frames is 90 and FPSO frames per second is three.
So three times three seconds we get 90 frames in total.
And these are properties of open CV to give us the total number of frames when we use this gets methods
and the frames per second.
Again, when we use the get methods, so ways to get information about the video, what do we do with
these numbers now?
So the idea is that, for example, if we had a timestamp such as zero zero and zero zero minutes and
zero two seconds, then we want to calculate what frame is this particular timestamp?
Is it the 30 first frame, the 30 second frame, the sixth frame?
Perhaps.
So if it was one second, we know that in one seconds we have 30 frames so that zero zero seconds we
have the first frame and the zero seconds we have the 30th frame.
So in one seconds we have three frames.
Therefore, at this particular timestamp, we have the 30 frame, we have the 60fps frame at this particular
timestamp.
So after two seconds, we have 60 frames.
So basically we want to extract the frame, the number of frame for a timestamp.
And we, of course, we can also do this with decimal seconds, such as eighty nine.
We have to divide by the number of frames per second and so on.
So let's do this.
Let me show you what I think the formula should be.
So first, I want to create a string that represents a timestamp.
Later on, we're going to give this as inputs as an input function through the command line from the
user.
But from now, as we develop the program, let's just have it here.
So zero zero four hours, zero zero four minutes, I'm going to say zero two point seventy five four
seconds.
So I'm not using minutes here because it's a very short video.
So zero two point sixty seven should be within the limits of our particular video file.
Once we have this string, we want to find a way to extract any of these members as a separate variable.
So first, what I do is I would convert these into a list timestamp lists equal to timestamp dot splits
with split.
What you get is.
A least out of a string.
Oh, let me print it out.
So now we have the items each separated as an individual object, so I a know we could go further and
convert them.
So let's create another variable floats that is equal to vessel list comprehension.
So we want to convert each of those items.
So floats I for I in time stamp list and see that this time.
This list will have flows.
You see, these are in quotes, but now.
We have them as floats, as numbers, and that allows us to make calculations.
I would go even further and stall each of these items in a variable.
So let's say hours, minutes and seconds equal to timestamp list floats if you do that and you can then
extract each of the items.
So zero zero, you get the hours.
And if you add minutes here minutes, it's also zero zero zero zero four hours, zero zero four minutes.
And again, we also get seconds.
Which is two point seventy five.
So we have the time stamp as numbers.
Now we want to get the frame number at that particular time stamp.
How to do that?
Well, let's say frame number is equal to.
Hmm.
So how if you do, how multiplied by three six zero zero, you get the number of seconds in an hour.
So for example, one hour as 3600 seconds, two hours with half seven thousand two hundred seconds.
And therefore, if we also multiply of IS by F.P. as we get something like, um, let's see if we have
two hours times three six zero zero, we get seven thousand two hundred times thirty.
We get the number of frames in two hours or in seven thousand two hundred seconds.
In other words.
So after two hours, we would encounter the frame number two hundred sixteen thousand right.
Then we say plus minutes times, 60 seconds in a minutes times f p s.
And finally.
Plus seconds.
Times FP s, that's the complete formula, so that's will give us the number of that frame that is in
that particular time stamp using that frame number.
We can use video that sets.
So video is that object, which contains a video file.
This gets as arguments the property i d, which is one with one you are saying that's you want to set
the video at a particular frame.
So this is a code for a property.
And what is that frame?
No, it is frame number this value here.
So basically, what we're doing here is we open the video, but we don't play it.
So we don't read the frames, we read the frames after we have set the starting point.
So the starting point is this frame, which is something like it, depends on the timestamp.
It would be something like the 60 or 70 or 80 frame of the video.
So with two seconds, we have 60 frames and with two point seventy five, we should f around 70 75.
Yep, now.
So we said that the Sony points of that particular frame, and then we can apply that success frame
to variables which will be populated with values from this method.
So success will get a boolean such as true or false.
If there is a frame at that particular point and frame will be the actual frame object, a number or
a representing the image of that video timestamp.
And finally, finally, we see two dots.
I'm right and we give the name to the frame.
File the image file, actually.
So I'm going to do something like an f string frame that we could enter here, the hours and the minutes
and the seconds.
So these three variables and lustily dot jpg.
And the second argument, so that is the first argument, the string representing the file name.
The second argument should be the actual frame object, which is frame.
So this one goes here, executes.
And we have an image.
So that is the frame.
If you want to further improve the name of the file, perhaps you want to use.
Some other variables here, which you can get from this object, so the time list, if you print the
time list, time stamp list, you get these format.
You see, with double zeros.
So we could get to them.
H h.
And as as equal to timestamp list and then use H h here M M and SS Arun.
And that is the next frame we got is the same frame, of course, but with a different name.
And of course, you could then answer and inputs function here instead of having a static string.
We could say inputs, answer time, stamp and age, age and SS formats.
So we let the user answer.
A time stamp.
You see, the command line asks us, so let's say zero zero zero zero four minutes and zero two point
twenty two four seconds.
And we get that new.
Frame.
And that is the complete code for this video.
Thanks a lot for following this, and I'll see you in the next one.