1
00:00:00,180 --> 00:00:08,280
In this lecture, we're going to create a script which instructs all the images that's make of this

2
00:00:08,490 --> 00:00:09,420
video file.

3
00:00:09,660 --> 00:00:11,760
So this is in my directory.

4
00:00:12,090 --> 00:00:14,400
And you can play that in Ripple.

5
00:00:15,330 --> 00:00:17,100
It's a three seconds long video.

6
00:00:18,290 --> 00:00:29,210
And it's made of 90 frames, so 90 images, 90 pictures stacked on top of each other and being rendered

7
00:00:29,540 --> 00:00:33,740
every fraction of a second or so, and we see that as a video.

8
00:00:33,950 --> 00:00:34,310
All right.

9
00:00:34,520 --> 00:00:39,710
So we're going to extract all the frames and save them inside a folder.

10
00:00:39,740 --> 00:00:42,710
So let's create an empty folder and name its images.

11
00:00:43,040 --> 00:00:49,250
So inside that images will go, all the jpg frames 90 of them.

12
00:00:49,820 --> 00:00:53,450
So go to main those p y and start coding.

13
00:00:53,750 --> 00:00:57,020
So the first thing we want to do is perhaps.

14
00:00:58,630 --> 00:01:01,870
Load the video inside Python.

15
00:01:02,810 --> 00:01:13,040
With COVID to that video capture, that is a class which expects us arguments, guess what, the video

16
00:01:13,040 --> 00:01:16,580
that's aimed before the path to the video file?

17
00:01:17,180 --> 00:01:20,900
So this one is this that will create.

18
00:01:21,680 --> 00:01:23,630
You will see if you print adults.

19
00:01:23,960 --> 00:01:25,370
Nothing impressive.

20
00:01:29,160 --> 00:01:33,570
So that's the output of this print function.

21
00:01:34,020 --> 00:01:41,890
So that means this is an object instance and a video capture object instance with this particular I.D.

22
00:01:41,910 --> 00:01:42,930
in memory.

23
00:01:43,230 --> 00:01:46,590
So in the computer memory, we don't need that idea just there.

24
00:01:46,920 --> 00:01:51,660
But the idea is that this is a class and that is the object instance.

25
00:01:51,900 --> 00:01:53,500
And as you see, nothing impressive.

26
00:01:53,520 --> 00:02:00,870
But if you apply the right methods, which is a specific method of video capture object instances.

27
00:02:01,320 --> 00:02:06,390
So if you execute this now we see something.

28
00:02:06,750 --> 00:02:09,090
So the output of this is a tuple.

29
00:02:09,870 --> 00:02:12,510
You see, it's a tipper which starts in here.

30
00:02:12,690 --> 00:02:17,020
So the opening parentheses, this is the first item of the tuple.

31
00:02:17,040 --> 00:02:22,470
You see the comma here and then we have the second item, which is a non-point array.

32
00:02:23,100 --> 00:02:32,970
So the second item and here this is the parentheses of the tip of the closing parentheses.

33
00:02:33,120 --> 00:02:34,420
So we have two items.

34
00:02:34,950 --> 00:02:35,730
The Boolean.

35
00:02:36,760 --> 00:02:44,260
And the umpire the non-point array represents the very first frame of the video.

36
00:02:44,440 --> 00:02:52,420
So the video has 90 frames and reads, we'll get you the first frame, but that's not exactly true.

37
00:02:52,680 --> 00:02:57,270
Reads We will actually get you the next frame in line.

38
00:02:57,280 --> 00:02:59,060
So we have 90 frames.

39
00:02:59,080 --> 00:03:05,320
If you execute reads once you get the first frame, if you execute it one more time.

40
00:03:05,680 --> 00:03:09,160
The second reads, methods will extract the second frame.

41
00:03:10,690 --> 00:03:13,120
You see, we have no one.

42
00:03:13,690 --> 00:03:19,810
Well, we also have Elizabeth, that's from the lost execution because this is an interactive shell

43
00:03:20,050 --> 00:03:20,800
of the reptile.

44
00:03:20,800 --> 00:03:27,010
The way reptile works is that it sends the code in an interactive shell, so it keeps the shell the

45
00:03:27,010 --> 00:03:28,000
session open.

46
00:03:28,150 --> 00:03:35,680
And we have to read the methods are returning this new temple so true and the the frame.

47
00:03:36,970 --> 00:03:38,530
Which goes in here and so on.

48
00:03:40,150 --> 00:03:45,570
And then another to fall for the second method.

49
00:03:46,240 --> 00:03:48,220
So the next frame?

50
00:03:48,670 --> 00:03:49,660
So what is true?

51
00:03:49,690 --> 00:03:50,630
What is true here?

52
00:03:50,650 --> 00:03:52,900
What is the other true there?

53
00:03:53,970 --> 00:04:02,250
Well, we get through whenever a frame was found, because if we keep executing this, if we add it's

54
00:04:02,610 --> 00:04:10,110
in total 90 Reid's methods, if we had 90 agreed methods here like we had to keep adding them and so

55
00:04:10,110 --> 00:04:16,140
on after the 90th methods, we wouldn't get any frames anymore.

56
00:04:16,320 --> 00:04:18,930
And the output would be false for this.

57
00:04:19,200 --> 00:04:27,570
So this first item of the table basically tells us that a frame was found and we could also get false

58
00:04:27,570 --> 00:04:29,610
if the video doesn't exist.

59
00:04:29,970 --> 00:04:37,650
So if you see videos for file path that doesn't exist and you execute and you scroll down here, yeah,

60
00:04:37,650 --> 00:04:41,580
we see falls, we see falls four times.

61
00:04:41,730 --> 00:04:50,970
So false, false, false and false for all the four times we executed the reads and none means no frame.

62
00:04:51,570 --> 00:04:59,370
So let's change videos to video and let's look at 86 more related methods.

63
00:04:59,880 --> 00:05:00,180
No.

64
00:05:01,440 --> 00:05:06,870
Or is there a better way to do this without having to execute slides 90 times?

65
00:05:07,440 --> 00:05:08,700
Well, yes, there is.

66
00:05:09,000 --> 00:05:13,740
Using a while loop, and it works like this.

67
00:05:14,250 --> 00:05:17,220
So I'm going to delete this print function.

68
00:05:17,580 --> 00:05:23,700
And what I'll do is I will the right to variables success and frame.

69
00:05:25,260 --> 00:05:34,530
Equals to vets Sue, the Colts stores, imports open CV and creates a video object, and then in success,

70
00:05:34,530 --> 00:05:42,330
we will store the true the Boolean value, so success will be equal to either true or false, and frame

71
00:05:42,330 --> 00:05:48,930
will be equal to the next item of the tipple that we get from this, which is the Nampai array, the

72
00:05:48,930 --> 00:05:49,470
frame.

73
00:05:49,920 --> 00:05:58,290
So in this first call of reads, we will get the first frame, then we see wild success.

74
00:06:00,630 --> 00:06:04,020
What we do is, we say severe to I am right.

75
00:06:04,380 --> 00:06:10,680
And we want to rights this first frame in an image file incites images here.

76
00:06:11,220 --> 00:06:19,870
This folder, therefore what we do, is we specify the path of that image file, which is images slash.

77
00:06:20,190 --> 00:06:22,410
Hmm, what's the name of this?

78
00:06:22,650 --> 00:06:24,960
So we're going to have nine two images.

79
00:06:25,230 --> 00:06:28,320
It makes sense to use some sort of numbering rights.

80
00:06:28,770 --> 00:06:33,720
So we could see a placeholder and say count here.

81
00:06:34,170 --> 00:06:36,240
So count could start from one.

82
00:06:37,620 --> 00:06:39,060
That's jpg.

83
00:06:39,540 --> 00:06:51,060
So the first frame would have the name one dot jpg stored inside images, and then we increase count

84
00:06:51,600 --> 00:06:55,290
by one using this formula.

85
00:06:56,010 --> 00:07:03,570
So in the second iteration count will be the current Collins value, which is one plus one.

86
00:07:03,720 --> 00:07:05,580
Second, we'll get a value of two.

87
00:07:05,820 --> 00:07:08,540
So again, we get the first frame count.

88
00:07:08,550 --> 00:07:13,350
It's one we write the first frame on the Rwanda jpg.

89
00:07:13,800 --> 00:07:20,850
We increase the count by one second is to know the loop is run again was true.

90
00:07:20,940 --> 00:07:26,010
So it's true we get the second image rewritten.

91
00:07:26,370 --> 00:07:28,050
But what do your rights here?

92
00:07:28,260 --> 00:07:29,220
Well, the frame.

93
00:07:29,550 --> 00:07:31,360
But this time we want to stall.

94
00:07:31,740 --> 00:07:34,950
We want to get the next frame, so we see success.

95
00:07:35,580 --> 00:07:38,820
Frame is to go to video, Dots reads.

96
00:07:39,420 --> 00:07:41,310
So that's what gets us the second frame.

97
00:07:41,610 --> 00:07:45,660
And that will be written as to the jpg.

98
00:07:46,320 --> 00:07:47,910
So this frame here?

99
00:07:48,890 --> 00:07:51,510
And that's the idea or run.

100
00:07:54,290 --> 00:07:56,870
And you see the images are being generated.

101
00:07:57,080 --> 00:07:59,100
So one is here.

102
00:07:59,120 --> 00:08:00,110
Two is here.

103
00:08:00,380 --> 00:08:02,180
So it's in an alphabetical order.

104
00:08:03,480 --> 00:08:06,600
And then you have three somewhere here.

105
00:08:06,740 --> 00:08:07,140
Right?

106
00:08:10,740 --> 00:08:15,030
And so one so 90s should be the last image.

107
00:08:15,990 --> 00:08:23,730
However, that was not the case because I think we should change the order of these lines in here because

108
00:08:24,030 --> 00:08:25,440
we get the first frame.

109
00:08:25,620 --> 00:08:30,480
And before we get the second frame, we want to write the first frame.

110
00:08:31,910 --> 00:08:32,450
In here.

111
00:08:32,870 --> 00:08:39,679
So get the first frame right, it's in an image file and then then get to the second frame.

112
00:08:40,070 --> 00:08:41,960
Increase the count by one.

113
00:08:42,409 --> 00:08:47,840
So we have the second frame currently in frame, therefore that will be written in frame.

114
00:08:48,140 --> 00:08:50,390
And then we get the third frame increase.

115
00:08:50,750 --> 00:08:51,770
That's two three.

116
00:08:52,520 --> 00:08:52,970
Right?

117
00:08:53,000 --> 00:08:56,570
The third frame in three jpg and so on.

118
00:08:56,930 --> 00:08:58,100
So that should work.

119
00:08:58,400 --> 00:09:01,370
I'm going to delete all these files from here.

120
00:09:02,180 --> 00:09:08,660
You can delete them either by going to here one by one, or you could go to the shell and see ah, and

121
00:09:08,660 --> 00:09:14,570
for or remove Bashar and you want to remove everything that is inside images.

122
00:09:14,720 --> 00:09:20,450
So images slash asterisk that's deleted all my images on there images.

123
00:09:20,810 --> 00:09:21,860
Now we're going to run again.

124
00:09:23,910 --> 00:09:31,950
The last one should be 90, the JRPG this time, so it's still generating new images.

125
00:09:33,140 --> 00:09:33,860
And there we go.

126
00:09:34,070 --> 00:09:42,830
So 9:02, That's the last frame, 89, slightly different from 1988 87.

127
00:09:43,040 --> 00:09:46,100
So they change a little bit from each other.

128
00:09:47,640 --> 00:09:47,940
Right.

129
00:09:48,570 --> 00:09:51,030
And that's our final code.

130
00:09:51,570 --> 00:09:57,960
So even though this is not very useful to just extract some images from a video, but it could be useful.

131
00:09:58,620 --> 00:10:06,060
And what we will do in the next video where we are going to extract only one frame from a certain timestamp

132
00:10:06,270 --> 00:10:07,290
in the video.

133
00:10:08,040 --> 00:10:13,200
So given a timestamp, we will get the frame of the image for that timestamp of the video.

134
00:10:13,320 --> 00:10:14,580
Let's do that in the next video.

