And now that you can take a photo with Python, let's see also how to take a video.
So it's not going to be much more complicated.
We're going to start from the same code.
I'm just going to first comment what we don't need.
So we're going to initialize the camera here.
But for the video resolution is not going to be the same option.
So I'm going to comment that line.
We're still going to flip the camera and wait for two seconds.
But then we're not going to take a photo.
We're going to take a video.
So for the video resolution instead of still size, we have.
So we can do camera dot video size.
That's another option.
So video size and the same thing we need to provide a tuple.
So I'm going to give 640 and 480 okay.
That's the resolution that we had previously on the terminal.
I'm going to keep the same okay.
But you can also decide to use another one.
All right.
So depending on if you take a photo or a video the option here is going to be different.
And then to take a video well we have the camera dot take photo.
But we have also when I write it here camera dot is going to be Record underscore video.
You need to provide the file to save the video.
So let's do.
Home.
So slash home slash pi slash camera.
And then slash let's call it my video.
Dot mp4.
So once again I use the mp4 format.
I close everything and I'm just going.
To add another log here.
So after we initialize just to say that we start to.
Record the video okay.
Because otherwise we're not going to see anything for a long time.
So print um let's say starting video.
And actually where in this record video, the first argument is going to be the path.
But then we can add a second argument.
And the second argument is going to be the time to record.
And in the terminal that was milliseconds.
So in the terminal for example for seven seconds you had to write 7000.
But here it's going to be seconds directly okay.
So if you write 7000 it's going to record for 7000 seconds, which might be a bit too long.
So seven seconds you just put seven.
All right.
So to recap here we initialize the camera and then we set a video size.
We can flip the camera horizontally and vertically if we want.
Just going to wait for two seconds just to be sure that everything is correctly initialized.
And the focus is right and well, just that kind of stuff.
Then I have a log to say I'm starting the video.
I record the video for seven seconds and I save it inside this file and then it's done.
So let's run that.
So it's initializing and then we should see starting video.
Okay.
So I'm going to move my hand in front of the camera.
And at some point.
Done.
Great.
So let's see what we have in our camera folder.
And we have a new file my video dot mp4.
Let's open that.
And you see it's seven seconds.
And that's well that's the video I just took.
All right.
So as you can see taking a photo or taking a video from Python with this Pi camera module is quite easy.
You just initialize the camera with a few options, and then you have one function to take a photo or
a video.
And that's pretty much it.
So it's going to be quite easy to include that inside our final project.