Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

3.1.2 Video Module¶

Introduction¶

In addition to taking photos, the Camera Module can also be used to record videos.

Required Components¶

In this project, we need the following components.

../_images/photo1.png

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Raphael Kit

337

Raphael Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Camera Module

BUY

Experimental Procedures¶

Step 1: Go into the Raspberry Pi Desktop. You may need a screen for a better experience, refer to: Connect your Raspberry Pi. Or access the Raspberry Pi desktop remotely, for a detailed tutorial please refer to Remote Desktop Access for Raspberry Pi.

Step 2: Check if the camera is enabled. For instructions, please refer to: Enable the Camera Interface.

Step 3: Open a Terminal and get into the folder of the code.

cd ~/raphael-kit/python/

Step 4: Run.

sudo python3 3.1.2_VideoModule.py

Run the code to start recording. Press Ctrl+C to end the recording. Name the video my_video.h264 and store it in the ~ directory.

Note

You can also open 3.1.2_PhotographModule.py in the ~/raphael-kit/python/ path with a Python IDE, click Run button to run, and stop the code with Stop button.

If you want to send photos to your PC, please refer to Filezilla Software.

Code

from picamera import PiCamera
import os
user = os.getlogin()
user_home = os.path.expanduser(f'~{user}')


camera = PiCamera()

def setup():
    camera.start_preview(alpha=200)

def main():
    camera.start_recording(f'{user_home}/my_video.h264')
    while True:
        pass

def destroy():
    camera.stop_recording()
    camera.stop_preview()

if __name__ == '__main__':
    setup()
    try:
        main()
    except KeyboardInterrupt:
        destroy()

Code Explanation

start_recording(output, format=None, resize=None, splitter_port=1, **options)

Start recording video from the camera, storing it in output.

camera.stop_recording()

End the recording.