1
00:00:00,180 --> 00:00:09,060
And this video of the riots, a program which gets from the user a timestamp and returns the frame corresponding

2
00:00:09,060 --> 00:00:13,440
to that timestamp in a video, a timestamp could look something like this.

3
00:00:14,070 --> 00:00:22,770
For example, zero zero four hours zero six four minutes seven point eighty seven four seconds.

4
00:00:23,810 --> 00:00:28,010
So we warned the timeframe at that time stamp in a video.

5
00:00:28,860 --> 00:00:29,570
Let's do this.

6
00:00:31,430 --> 00:00:37,220
I import almost CV and I create a video object using that video file.

7
00:00:37,520 --> 00:00:40,370
So it's a short three second video.

8
00:00:43,770 --> 00:00:46,530
One, two and three seconds.

9
00:00:47,580 --> 00:00:50,760
Right, then I'm extracting the number of frames here.

10
00:00:50,970 --> 00:00:56,550
So how many frames does the video have and how many frames are there per second?

11
00:00:57,210 --> 00:00:58,950
We want these two variables.

12
00:00:59,130 --> 00:01:03,510
These two numbers and I'll explain you why I need them.

13
00:01:03,810 --> 00:01:06,090
So let's run this to see what we get.

14
00:01:06,520 --> 00:01:12,390
Yes, a number of frames is 90 and FPSO frames per second is three.

15
00:01:12,690 --> 00:01:16,320
So three times three seconds we get 90 frames in total.

16
00:01:16,680 --> 00:01:24,600
And these are properties of open CV to give us the total number of frames when we use this gets methods

17
00:01:24,900 --> 00:01:26,430
and the frames per second.

18
00:01:27,210 --> 00:01:33,060
Again, when we use the get methods, so ways to get information about the video, what do we do with

19
00:01:33,060 --> 00:01:34,080
these numbers now?

20
00:01:34,440 --> 00:01:41,610
So the idea is that, for example, if we had a timestamp such as zero zero and zero zero minutes and

21
00:01:41,610 --> 00:01:50,370
zero two seconds, then we want to calculate what frame is this particular timestamp?

22
00:01:50,790 --> 00:01:55,410
Is it the 30 first frame, the 30 second frame, the sixth frame?

23
00:01:55,410 --> 00:01:55,890
Perhaps.

24
00:01:56,610 --> 00:02:05,370
So if it was one second, we know that in one seconds we have 30 frames so that zero zero seconds we

25
00:02:05,370 --> 00:02:11,039
have the first frame and the zero seconds we have the 30th frame.

26
00:02:11,280 --> 00:02:13,410
So in one seconds we have three frames.

27
00:02:13,590 --> 00:02:21,780
Therefore, at this particular timestamp, we have the 30 frame, we have the 60fps frame at this particular

28
00:02:21,780 --> 00:02:22,350
timestamp.

29
00:02:22,620 --> 00:02:24,780
So after two seconds, we have 60 frames.

30
00:02:25,260 --> 00:02:32,400
So basically we want to extract the frame, the number of frame for a timestamp.

31
00:02:32,790 --> 00:02:37,980
And we, of course, we can also do this with decimal seconds, such as eighty nine.

32
00:02:38,940 --> 00:02:44,160
We have to divide by the number of frames per second and so on.

33
00:02:44,310 --> 00:02:46,020
So let's do this.

34
00:02:46,650 --> 00:02:49,560
Let me show you what I think the formula should be.

35
00:02:50,790 --> 00:02:56,550
So first, I want to create a string that represents a timestamp.

36
00:02:57,240 --> 00:03:01,950
Later on, we're going to give this as inputs as an input function through the command line from the

37
00:03:01,950 --> 00:03:02,340
user.

38
00:03:02,460 --> 00:03:06,030
But from now, as we develop the program, let's just have it here.

39
00:03:06,900 --> 00:03:15,270
So zero zero four hours, zero zero four minutes, I'm going to say zero two point seventy five four

40
00:03:15,270 --> 00:03:16,200
seconds.

41
00:03:16,210 --> 00:03:20,130
So I'm not using minutes here because it's a very short video.

42
00:03:20,310 --> 00:03:26,640
So zero two point sixty seven should be within the limits of our particular video file.

43
00:03:27,580 --> 00:03:35,920
Once we have this string, we want to find a way to extract any of these members as a separate variable.

44
00:03:36,280 --> 00:03:49,240
So first, what I do is I would convert these into a list timestamp lists equal to timestamp dot splits

45
00:03:49,240 --> 00:03:50,080
with split.

46
00:03:50,620 --> 00:03:52,450
What you get is.

47
00:03:55,180 --> 00:03:57,310
A least out of a string.

48
00:03:57,710 --> 00:03:59,260
Oh, let me print it out.

49
00:04:04,040 --> 00:04:15,470
So now we have the items each separated as an individual object, so I a know we could go further and

50
00:04:15,470 --> 00:04:16,579
convert them.

51
00:04:18,140 --> 00:04:24,140
So let's create another variable floats that is equal to vessel list comprehension.

52
00:04:24,290 --> 00:04:27,110
So we want to convert each of those items.

53
00:04:27,290 --> 00:04:34,820
So floats I for I in time stamp list and see that this time.

54
00:04:37,100 --> 00:04:38,900
This list will have flows.

55
00:04:39,080 --> 00:04:41,510
You see, these are in quotes, but now.

56
00:04:42,510 --> 00:04:47,310
We have them as floats, as numbers, and that allows us to make calculations.

57
00:04:47,910 --> 00:04:53,460
I would go even further and stall each of these items in a variable.

58
00:04:53,760 --> 00:05:05,130
So let's say hours, minutes and seconds equal to timestamp list floats if you do that and you can then

59
00:05:05,130 --> 00:05:07,140
extract each of the items.

60
00:05:07,890 --> 00:05:09,750
So zero zero, you get the hours.

61
00:05:10,320 --> 00:05:19,230
And if you add minutes here minutes, it's also zero zero zero zero four hours, zero zero four minutes.

62
00:05:19,500 --> 00:05:21,570
And again, we also get seconds.

63
00:05:24,700 --> 00:05:27,610
Which is two point seventy five.

64
00:05:28,840 --> 00:05:32,530
So we have the time stamp as numbers.

65
00:05:32,860 --> 00:05:37,570
Now we want to get the frame number at that particular time stamp.

66
00:05:38,410 --> 00:05:39,460
How to do that?

67
00:05:39,520 --> 00:05:44,110
Well, let's say frame number is equal to.

68
00:05:44,750 --> 00:05:45,100
Hmm.

69
00:05:45,130 --> 00:05:54,970
So how if you do, how multiplied by three six zero zero, you get the number of seconds in an hour.

70
00:05:55,240 --> 00:06:03,100
So for example, one hour as 3600 seconds, two hours with half seven thousand two hundred seconds.

71
00:06:03,670 --> 00:06:13,240
And therefore, if we also multiply of IS by F.P. as we get something like, um, let's see if we have

72
00:06:13,300 --> 00:06:21,250
two hours times three six zero zero, we get seven thousand two hundred times thirty.

73
00:06:21,610 --> 00:06:29,330
We get the number of frames in two hours or in seven thousand two hundred seconds.

74
00:06:29,350 --> 00:06:29,950
In other words.

75
00:06:30,430 --> 00:06:38,560
So after two hours, we would encounter the frame number two hundred sixteen thousand right.

76
00:06:38,740 --> 00:06:47,310
Then we say plus minutes times, 60 seconds in a minutes times f p s.

77
00:06:48,280 --> 00:06:49,270
And finally.

78
00:06:50,430 --> 00:06:52,640
Plus seconds.

79
00:06:53,110 --> 00:07:01,110
Times FP s, that's the complete formula, so that's will give us the number of that frame that is in

80
00:07:01,110 --> 00:07:05,380
that particular time stamp using that frame number.

81
00:07:05,700 --> 00:07:07,680
We can use video that sets.

82
00:07:08,010 --> 00:07:11,970
So video is that object, which contains a video file.

83
00:07:12,570 --> 00:07:20,670
This gets as arguments the property i d, which is one with one you are saying that's you want to set

84
00:07:21,030 --> 00:07:23,870
the video at a particular frame.

85
00:07:23,880 --> 00:07:26,670
So this is a code for a property.

86
00:07:27,240 --> 00:07:29,710
And what is that frame?

87
00:07:29,730 --> 00:07:33,360
No, it is frame number this value here.

88
00:07:34,590 --> 00:07:41,730
So basically, what we're doing here is we open the video, but we don't play it.

89
00:07:42,240 --> 00:07:49,950
So we don't read the frames, we read the frames after we have set the starting point.

90
00:07:50,250 --> 00:07:56,790
So the starting point is this frame, which is something like it, depends on the timestamp.

91
00:07:57,180 --> 00:08:03,000
It would be something like the 60 or 70 or 80 frame of the video.

92
00:08:03,150 --> 00:08:11,070
So with two seconds, we have 60 frames and with two point seventy five, we should f around 70 75.

93
00:08:11,550 --> 00:08:12,180
Yep, now.

94
00:08:13,050 --> 00:08:20,880
So we said that the Sony points of that particular frame, and then we can apply that success frame

95
00:08:22,620 --> 00:08:27,240
to variables which will be populated with values from this method.

96
00:08:27,390 --> 00:08:30,870
So success will get a boolean such as true or false.

97
00:08:30,870 --> 00:08:39,330
If there is a frame at that particular point and frame will be the actual frame object, a number or

98
00:08:39,330 --> 00:08:44,790
a representing the image of that video timestamp.

99
00:08:45,000 --> 00:08:48,860
And finally, finally, we see two dots.

100
00:08:48,870 --> 00:08:52,950
I'm right and we give the name to the frame.

101
00:08:53,190 --> 00:08:55,170
File the image file, actually.

102
00:08:55,410 --> 00:09:05,250
So I'm going to do something like an f string frame that we could enter here, the hours and the minutes

103
00:09:05,910 --> 00:09:08,070
and the seconds.

104
00:09:08,730 --> 00:09:16,630
So these three variables and lustily dot jpg.

105
00:09:17,280 --> 00:09:21,690
And the second argument, so that is the first argument, the string representing the file name.

106
00:09:22,030 --> 00:09:27,960
The second argument should be the actual frame object, which is frame.

107
00:09:29,580 --> 00:09:33,510
So this one goes here, executes.

108
00:09:35,070 --> 00:09:37,080
And we have an image.

109
00:09:37,770 --> 00:09:39,930
So that is the frame.

110
00:09:41,860 --> 00:09:47,770
If you want to further improve the name of the file, perhaps you want to use.

111
00:09:49,300 --> 00:09:57,700
Some other variables here, which you can get from this object, so the time list, if you print the

112
00:09:57,710 --> 00:10:04,120
time list, time stamp list, you get these format.

113
00:10:05,670 --> 00:10:07,260
You see, with double zeros.

114
00:10:08,400 --> 00:10:10,200
So we could get to them.

115
00:10:10,980 --> 00:10:12,150
H h.

116
00:10:12,540 --> 00:10:22,650
And as as equal to timestamp list and then use H h here M M and SS Arun.

117
00:10:25,210 --> 00:10:29,860
And that is the next frame we got is the same frame, of course, but with a different name.

118
00:10:30,820 --> 00:10:39,580
And of course, you could then answer and inputs function here instead of having a static string.

119
00:10:40,080 --> 00:10:50,510
We could say inputs, answer time, stamp and age, age and SS formats.

120
00:10:52,180 --> 00:10:54,040
So we let the user answer.

121
00:10:55,900 --> 00:10:56,770
A time stamp.

122
00:10:57,550 --> 00:11:04,480
You see, the command line asks us, so let's say zero zero zero zero four minutes and zero two point

123
00:11:04,480 --> 00:11:06,160
twenty two four seconds.

124
00:11:07,340 --> 00:11:09,290
And we get that new.

125
00:11:10,740 --> 00:11:11,160
Frame.

126
00:11:13,680 --> 00:11:17,610
And that is the complete code for this video.

127
00:11:18,060 --> 00:11:20,820
Thanks a lot for following this, and I'll see you in the next one.

