.. 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 [|link_sf_facebook|] and join today! .. _3.1.2_py: 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. .. image:: ../img/photo1.png :width: 800 It's definitely convenient to buy a whole kit, here's the link: .. list-table:: :widths: 20 20 20 :header-rows: 1 * - Name - ITEMS IN THIS KIT - LINK * - Raphael Kit - 337 - |link_Raphael_kit| You can also buy them separately from the links below. .. list-table:: :widths: 30 20 :header-rows: 1 * - COMPONENT INTRODUCTION - PURCHASE LINK * - :ref:`cpn_camera_module` - |link_camera_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 :ref:`remote_desktop`. **Step 2:** Check if the camera is enabled. For instructions, please refer to: :ref:`enable_camera`. **Step 3:** Open a Terminal and get into the folder of the code. .. code-block:: cd ~/raphael-kit/python/ **Step 4:** Run. .. code-block:: 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 :ref:`filezilla`. **Code** .. code-block:: python 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** .. code-block:: python start_recording(output, format=None, resize=None, splitter_port=1, **options) Start recording video from the camera, storing it in ``output``. .. code-block:: python camera.stop_recording() End the recording.