Use Python Code to Record Video

Use the camera to record video. Write Python code to start and stop the recording.

Change your code to replace capture() with start_recording() and stop_recording(). Your code will now look like this:

from picamera import PiCamera from time import sleep camera = PiCamera() camera.start_preview() camera.start_recording('/home/pi/video.h264') sleep(10) camera.stop_recording() camera.stop_preview()

Step 2

Run the code by pressing 'F5'. It will record 10 seconds of video and then close the preview.

Step 3

To play the video, open a Terminal window.

Open the Terminal app.

Step 4

Type this command and then press 'Enter':

omxplayer video.h264

The video will play. It might play at a faster speed than what has been recorded due to omxplayer's fast frame rate.