{"id":146759,"date":"2024-05-07T15:27:56","date_gmt":"2024-05-07T15:27:56","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=146759"},"modified":"2024-05-07T17:42:13","modified_gmt":"2024-05-07T17:42:13","slug":"raspberry-pi-picamera2-python","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-picamera2-python\/","title":{"rendered":"Set Up Python Picamera2 on a Raspberry Pi (Take Photos and Capture Video)"},"content":{"rendered":"\n<p>This guide is an introduction to the <span class=\"rnthl rntliteral\">Picamera2<\/span> Python library for the Raspberry Pi board. It covers how to install <span class=\"rnthl rntliteral\">Picamera2<\/span>, take photos, and record video to an .<em>mp4<\/em> file. This guide is compatible with the Raspberry Pi Camera V2 and V3.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Setup Python Picamera2 on a Raspberry Pi Take Photos and Capture Video\" class=\"wp-image-146807\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<p>This guide covers the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#picamera2-python-library\" title=\"\">Picamera2 Python Library<\/a><\/li>\n\n\n\n<li><a href=\"#connect-raspberry-pi-camera\" title=\"\">Preparing the Raspberry Pi Camera<\/a><\/li>\n\n\n\n<li><a href=\"#take-photo-picamera2\" title=\"\">Picamera2 Take Photo Example &#8211; Python Script<\/a><\/li>\n\n\n\n<li><a href=\"#picamera2-record-video\" title=\"\">Picamera2 Record Video Example &#8211; Python Script<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before proceeding, make sure you check the following prerequisites: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need a <a href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-starter-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi board<\/a> and a <a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-camera-v2-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi camera<\/a><\/li>\n\n\n\n<li>You should have a <a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/#install-raspberry-pi-os\">Raspberry Pi running Raspberry Pi OS<\/a> (32-bit or 64-bit).<\/li>\n\n\n\n<li>You should be able to<a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/#connect-RPi-SSH\"> establish an SSH connection with your Raspberry Pi<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"picamera2-python-library\">Picamera2 Python Library<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/raspberrypi\/picamera2\" target=\"_blank\" rel=\"noopener\" title=\"\">Picamera2<\/a> is a Python library for interacting with the Raspberry Pi&#8217;s camera. It is based on the <em>libcamera <\/em>camera stack and it is maintained by the Raspberry Pi foundation. It&#8217;s no longer recommended to use the older <span class=\"rnthl rntliteral\">PiCamera<\/span> library with the latest Raspberry Pi OS versions. <\/p>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">Picamera2<\/span> library is supported on all Raspberry Pi models from the Pi Zero to the RPi 5.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"pip-virtual-environment\">Installing Picamera2 Library<\/h3>\n\n\n\n<p>Having an&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/installing-raspbian-lite-enabling-and-connecting-with-ssh\/#connect-RPi-SSH\">SSH connection established with your Raspberry Pi<\/a>, update and upgrade your Raspberry Pi, if any updates are available. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<p>Run the next command to install the <span class=\"rnthl rntliteral\">Picamera2<\/span> library in your Raspberry Pi.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y python3-picamera2<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntcred\">It is strongly recommended to install and update <span class=\"rnthl rntliteral\">Picamera2<\/span> using the <span class=\"rnthl rntliteral\">apt<\/span> command described earlier which will avoid compatibility problems. I&#8217;ve encountered many compilation issues while trying to install the <span class=\"rnthl rntliteral\">Picamera2<\/span> library with the <span class=\"rnthl rntliteral\">pip<\/span> command on a virtual environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"connect-raspberry-pi-camera\">Preparing the Raspberry Pi Camera<\/h2>\n\n\n\n<p>The Raspberry Pi camera is a small and low-cost camera module compatible with the Raspberry Pi boards. Even though it can be good enough for most projects,<a href=\"https:\/\/randomnerdtutorials.com\/set-up-usb-camera-opencv-raspberry-pi\/\" title=\"\"> some USB cameras will provide better image quality<\/a>. For this guide, we&#8217;ll be using the Raspberry Pi Camera V2 module shown in the following picture:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Camera-Module-v2.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Camera Module V2\" class=\"wp-image-146800\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Camera-Module-v2.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Camera-Module-v2.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>This guide also works with the Raspberry Pi Camera V3 and the camera is compatible with all Raspberry Pi models.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable the Raspberry Pi Camera Module<\/h3>\n\n\n\n<p>If you are running the latest version of Raspberry Pi OS, the official Raspberry Pi cameras will be detected and enabled automatically.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connect the camera<\/h3>\n\n\n\n<p>Connecting the Raspberry Pi Camera Module is very straightforward. With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following figure.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-5-Pi-Camera-Module-v2-connected-cable.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi 5 Pi Camera Module v2 connected cable\" class=\"wp-image-146802\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-5-Pi-Camera-Module-v2-connected-cable.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-5-Pi-Camera-Module-v2-connected-cable.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"take-photo-picamera2\">Picamera2 Take Photo Example &#8211; Python Script<\/h2>\n\n\n\n<p>Taking a photo with the Raspberry Pi camera is simple thanks to the <span class=\"rnthl rntliteral\">Picamera2<\/span> Python library. Create a new file called <em>take_photo.py<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano take_photo.py<\/code><\/pre>\n\n\n\n<p>Copy the following code to your newly created file:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n# Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-picamera2-python\/\r\n \r\nfrom picamera2 import Picamera2, Preview\r\nimport time\r\n\r\npicam2 = Picamera2()\r\n\r\ncamera_config = picam2.create_preview_configuration()\r\npicam2.configure(camera_config)\r\n\r\npicam2.start_preview(Preview.QTGL)\r\npicam2.start()\r\n\r\ntime.sleep(2)\r\n\r\npicam2.capture_file(&quot;test_photo.jpg&quot;)<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi\/take_photo.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Press <strong>Ctrl<\/strong>+<strong>X<\/strong> to save your file, type <strong>Y<\/strong> and <strong>Enter<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Take Photo Script<\/h3>\n\n\n\n<p>Let&#8217;s take a quick look at how the code works.<\/p>\n\n\n\n<p>Start by importing the required libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from picamera2 import Picamera2, Preview\nimport time<\/code><\/pre>\n\n\n\n<p>Create a <span class=\"rnthl rntliteral\">Picamera2()<\/span> object called <span class=\"rnthl rntliteral\">picam2<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>picam2 = Picamera2()<\/code><\/pre>\n\n\n\n<p>Then, generate a camera configuration suitable for preview and configure the camera system with that preview configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>camera_config = picam2.create_preview_configuration()\npicam2.configure(camera_config)<\/code><\/pre>\n\n\n\n<p>Start the preview window.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>picam2.start_preview(Preview.QTGL)<\/code><\/pre>\n\n\n\n<p>Finally, start the camera, wait for two seconds, and take a picture. It will be stored with the filename <em>test_photo.jpg<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>picam2.start()\n\ntime.sleep(2)\n\npicam2.capture_file(\"test_photo.jpg\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running the Script<\/h3>\n\n\n\n<p>Run your script to take a photo by running the following command on your project directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python take_photo.py<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"327\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-command.png?resize=1024%2C327&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Picamera2 Python Take Photo Command\" class=\"wp-image-146794\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-command.png?resize=1024%2C327&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-command.png?resize=300%2C96&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-command.png?resize=768%2C245&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-command.png?w=1422&amp;quality=100&amp;strip=all&amp;ssl=1 1422w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>It takes a photo with the Raspberry Pi Camera and saves it with the <em>test_photo.jpg<\/em> name. The image file will be saved in the same folder as the Python script.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"187\" height=\"106\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-take-photo-folder-files.png?resize=187%2C106&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Picamera2 Python take photo folder files\" class=\"wp-image-146795\"\/><\/figure><\/div>\n\n\n<p>You can <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-desktop-connection-rdp-windows\/\" title=\"\">access your Raspberry Pi Desktop remotely<\/a> and open the image file to take a look at the picture.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"604\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/take-photo-picamera2-python-example-script.png?resize=852%2C604&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Take Photo Picamera2 Python Example Script\" class=\"wp-image-146790\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/take-photo-picamera2-python-example-script.png?w=852&amp;quality=100&amp;strip=all&amp;ssl=1 852w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/take-photo-picamera2-python-example-script.png?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/take-photo-picamera2-python-example-script.png?resize=768%2C544&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"picamera2-record-video\">Picamera2 Record Video Example &#8211; Python Script<\/h2>\n\n\n\n<p>The next Python script also uses the <span class=\"rnthl rntliteral\">PiCamera<\/span> package to capture video to an <em>.mp4<\/em> file. Create a new file called<em> record_video.py<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano capture_video.py<\/code><\/pre>\n\n\n\n<p>Copy the following code to your newly created file:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n# Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-picamera2-python\/\r\n\r\nfrom picamera2 import Picamera2\r\n\r\npicam2 = Picamera2()\r\n\r\npicam2.start_and_record_video(&quot;test_video.mp4&quot;, duration=5)<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi\/capture_video.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Press <strong>Ctrl<\/strong>+<strong>X<\/strong> to save your file, type <strong>Y<\/strong> and <strong>Enter<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Capture Video Script<\/h3>\n\n\n\n<p>Let&#8217;s take a quick look at the script.<\/p>\n\n\n\n<p>Start by importing the required libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>from picamera2 import Picamera2<\/code><\/pre>\n\n\n\n<p>Create a <span class=\"rnthl rntliteral\">Picamera2()<\/span> object.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>picam2 = Picamera2()<\/code><\/pre>\n\n\n\n<p>The next command records video for 5 seconds with the Raspberry Pi Camera and saves it with the <em>test_video.mp4<\/em> name. You can modify the script to change the file name and extend the video recording duration.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>picam2.start_and_record_video(\"test_video.mp4\", duration=5)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running the Script<\/h3>\n\n\n\n<p>Run the script to record a video. You can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 capture_video.py<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"222\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-command.png?resize=1024%2C222&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Picamera2 Python Capture Video Command\" class=\"wp-image-146792\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-command.png?resize=1024%2C222&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-command.png?resize=300%2C65&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-command.png?resize=768%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-command.png?w=1465&amp;quality=100&amp;strip=all&amp;ssl=1 1465w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>It will capture a 5-second video with the Raspberry Pi Camera and will save it with the <em>test_video.mp4 <\/em>name.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"188\" height=\"113\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/picamera2-python-capture-video-folder-files.png?resize=188%2C113&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Picamera2 Python capture video folder files\" class=\"wp-image-146793\"\/><\/figure><\/div>\n\n\n<p>You can access your <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-remote-desktop-connection-rdp-windows\/\" title=\"\">Raspberry Pi Desktop remotely<\/a> and open the video file with the VLC player to watch it.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"938\" height=\"629\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/capture-video-picamera2-python-example-script.png?resize=938%2C629&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Capture Video Picamera2 Python Example Script\" class=\"wp-image-146791\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/capture-video-picamera2-python-example-script.png?w=938&amp;quality=100&amp;strip=all&amp;ssl=1 938w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/capture-video-picamera2-python-example-script.png?resize=300%2C201&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/capture-video-picamera2-python-example-script.png?resize=768%2C515&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>If you are using a Raspberry Pi 3 or an older device, you&#8217;ll need to enable <em>Glamor <\/em>for this example script. To do this, run <span class=\"rnthl rntliteral\">sudo raspi-config<\/span> in a command window, choose <em>Advanced Options<\/em>, and then enable <em>Glamor graphic acceleration<\/em>. Finally, reboot your device.<\/li>\n\n\n\n<li>If you are using a Remote Desktop Connection, sometimes the image preview and video recording will show blurred like the screenshots below. However, if you <a href=\"https:\/\/randomnerdtutorials.com\/transfer-files-raspberry-pi-filezilla-ftp-mac-os\/\" title=\"\">download the files to your regular Windows PC or Mac OS<\/a>, the files are fine.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"418\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-take-photo-preview-error.png?resize=641%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Python Picamera2 Raspberry Pi Python take photo preview error\" class=\"wp-image-146797\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-take-photo-preview-error.png?w=641&amp;quality=100&amp;strip=all&amp;ssl=1 641w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-take-photo-preview-error.png?resize=300%2C196&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\">Related content: <a href=\"https:\/\/randomnerdtutorials.com\/transfer-files-raspberry-pi-filezilla-ftp-windows\/\">Transfer Files to and from Raspberry Pi using FileZilla FTP (Windows PC)<\/a><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"919\" height=\"538\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-capture-video-preview-error.png?resize=919%2C538&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Python Picamera2 Raspberry Pi Python capture video preview error\" class=\"wp-image-146796\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-capture-video-preview-error.png?w=919&amp;quality=100&amp;strip=all&amp;ssl=1 919w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-capture-video-preview-error.png?resize=300%2C176&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/python-picamera2-raspberry-pi-python-capture-video-preview-error.png?resize=768%2C450&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>This post was a quick introduction guide to the Raspberry Pi Camera with the <span class=\"rnthl rntliteral\">Picamera2<\/span> Python library. You learned how to take photos and record video into a file.<\/p>\n\n\n\n<p>We have other Raspberry Pi Projects that you may find useful:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/install-opencv-raspberry-pi\/\">Install OpenCV on a Raspberry Pi (compatible with all RPi boards)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/set-up-usb-camera-opencv-raspberry-pi\/\">Set Up USB Camera for OpenCV Projects with Raspberry Pi<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/install-mediapipe-raspberry-pi\/\">Install MediaPipe on a Raspberry Pi \u2013 Example Gesture Recognition<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-control-outputs-based-on-time\/\">Raspberry Pi: Control Outputs Based on Time of the Day (Python)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-send-email-python-smtp-server\/\">Raspberry Pi: Send an Email using Python (SMTP Server)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pinout-gpios\/\">Raspberry Pi Pinout Guide: How to use the Raspberry Pi GPIOs?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi\/\" title=\"\">All our Raspberry Pi Projects and Guides<\/a><\/li>\n<\/ul>\n\n\n\n<p>We hope you\u2019ve found this post useful.<\/p>\n\n\n\n<p>Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide is an introduction to the Picamera2 Python library for the Raspberry Pi board. It covers how to install Picamera2, take photos, and record video to an .mp4 file. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Set Up Python Picamera2 on a Raspberry Pi (Take Photos and Capture Video)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-picamera2-python\/#more-146759\" aria-label=\"Read more about Set Up Python Picamera2 on a Raspberry Pi (Take Photos and Capture Video)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":146807,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,264,190,268],"tags":[],"class_list":["post-146759","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-project","category-raspberry-pi","category-raspberry-pi-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/Raspberry-Pi-Picamera2-getting-started.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/146759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=146759"}],"version-history":[{"count":13,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/146759\/revisions"}],"predecessor-version":[{"id":155037,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/146759\/revisions\/155037"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/146807"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=146759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=146759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=146759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}