WEBVTT

00:00.080 --> 00:05.150
And now that you can take a photo with Python, let's see also how to take a video.

00:05.180 --> 00:07.370
So it's not going to be much more complicated.

00:07.400 --> 00:09.470
We're going to start from the same code.

00:09.470 --> 00:12.800
I'm just going to first comment what we don't need.

00:12.800 --> 00:15.800
So we're going to initialize the camera here.

00:15.800 --> 00:20.120
But for the video resolution is not going to be the same option.

00:20.120 --> 00:22.070
So I'm going to comment that line.

00:22.070 --> 00:25.550
We're still going to flip the camera and wait for two seconds.

00:26.120 --> 00:27.950
But then we're not going to take a photo.

00:27.980 --> 00:29.330
We're going to take a video.

00:29.330 --> 00:34.910
So for the video resolution instead of still size, we have.

00:34.910 --> 00:38.480
So we can do camera dot video size.

00:38.930 --> 00:40.370
That's another option.

00:40.370 --> 00:44.690
So video size and the same thing we need to provide a tuple.

00:44.690 --> 00:49.640
So I'm going to give 640 and 480 okay.

00:49.670 --> 00:52.430
That's the resolution that we had previously on the terminal.

00:52.430 --> 00:53.990
I'm going to keep the same okay.

00:53.990 --> 00:56.780
But you can also decide to use another one.

00:56.810 --> 00:57.140
All right.

00:57.170 --> 01:02.750
So depending on if you take a photo or a video the option here is going to be different.

01:02.750 --> 01:07.760
And then to take a video well we have the camera dot take photo.

01:07.760 --> 01:16.880
But we have also when I write it here camera dot is going to be Record underscore video.

01:16.910 --> 01:20.750
You need to provide the file to save the video.

01:20.750 --> 01:21.710
So let's do.

01:21.740 --> 01:22.310
Home.

01:22.310 --> 01:26.030
So slash home slash pi slash camera.

01:26.030 --> 01:29.030
And then slash let's call it my video.

01:29.060 --> 01:30.440
Dot mp4.

01:30.440 --> 01:32.690
So once again I use the mp4 format.

01:32.690 --> 01:35.660
I close everything and I'm just going.

01:35.690 --> 01:37.430
To add another log here.

01:37.430 --> 01:41.030
So after we initialize just to say that we start to.

01:41.060 --> 01:42.410
Record the video okay.

01:42.440 --> 01:46.400
Because otherwise we're not going to see anything for a long time.

01:46.610 --> 01:51.800
So print um let's say starting video.

01:51.860 --> 01:57.920
And actually where in this record video, the first argument is going to be the path.

01:57.920 --> 01:59.960
But then we can add a second argument.

01:59.960 --> 02:03.440
And the second argument is going to be the time to record.

02:03.470 --> 02:06.560
And in the terminal that was milliseconds.

02:06.560 --> 02:11.180
So in the terminal for example for seven seconds you had to write 7000.

02:11.180 --> 02:15.080
But here it's going to be seconds directly okay.

02:15.110 --> 02:22.100
So if you write 7000 it's going to record for 7000 seconds, which might be a bit too long.

02:22.100 --> 02:25.400
So seven seconds you just put seven.

02:25.430 --> 02:25.790
All right.

02:25.790 --> 02:31.610
So to recap here we initialize the camera and then we set a video size.

02:31.760 --> 02:36.170
We can flip the camera horizontally and vertically if we want.

02:36.200 --> 02:40.550
Just going to wait for two seconds just to be sure that everything is correctly initialized.

02:40.550 --> 02:44.150
And the focus is right and well, just that kind of stuff.

02:44.180 --> 02:46.820
Then I have a log to say I'm starting the video.

02:46.850 --> 02:52.280
I record the video for seven seconds and I save it inside this file and then it's done.

02:52.280 --> 02:54.110
So let's run that.

02:55.430 --> 02:59.390
So it's initializing and then we should see starting video.

02:59.510 --> 02:59.780
Okay.

02:59.780 --> 03:02.750
So I'm going to move my hand in front of the camera.

03:02.750 --> 03:05.120
And at some point.

03:05.150 --> 03:05.780
Done.

03:05.810 --> 03:06.200
Great.

03:06.200 --> 03:08.660
So let's see what we have in our camera folder.

03:08.660 --> 03:12.740
And we have a new file my video dot mp4.

03:12.770 --> 03:14.390
Let's open that.

03:14.600 --> 03:16.700
And you see it's seven seconds.

03:16.700 --> 03:19.820
And that's well that's the video I just took.

03:21.050 --> 03:21.860
All right.

03:21.860 --> 03:29.780
So as you can see taking a photo or taking a video from Python with this Pi camera module is quite easy.

03:29.810 --> 03:35.210
You just initialize the camera with a few options, and then you have one function to take a photo or

03:35.210 --> 03:35.690
a video.

03:35.690 --> 03:37.250
And that's pretty much it.

03:37.250 --> 03:41.630
So it's going to be quite easy to include that inside our final project.
