Skip to main content
Chemistry LibreTexts

9.22: Libcamera

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    Command Line Acces to Camera

    With the advent of the Bookworm Pi OS the libcamera application was renamed to rpicam.  Right now libcamera commands will still work, but the will be deprecated and so it is best to code forward with rpicam commands.  We will predominantly work with two image encoders, jpeg for still images and h.264 for video.

    The following material relates to the Bullseye operating system and uses libcamera.  If you are using Buster or wish to use the Raspicam legacy interface, go to section 1.3.7 of the 2020 class.  The following video and this article from Core Electronics , How to use of Raspberry Pi Cameras with Bulleseye OS Update are a good place to start.


    For a complete overview of the librecamera go to Raspberry Pi Camera Software Documentation



    libcamera-hello - gives a 5 second view of what the camera sees


    To flip vertically or horizontally use the following switches


    to find options use the help switch

    libcamera-jpeg -h

    To run the camera for a time in milliseconds, use -t followed by the time in milliseconds

    libcamera-hello -t 8000
    libcamera-hello --vflip -t 8000

    To run the camera indefinitely, until you terminate the command (<ctrl>c) or close the window, set the time to zero.

    libcamera-hello -t 0

    Still Picture

    When you take a picture you need to define a path for where the picture will be stored. If you do not do that, it will be stored in whatever directory the command line is operating in. You should think about your project and where you want to keep images, and keep them in a folder that is within your user directory (/home/username/....).

    The following code will give a 5 second preview and then save a file. NOTE: you need to set the path to a folder on your pi.  the -o stands for output (file)

    libcamera-jpeg -o /home/user/path/test1.jpeg
    libcamera-jpeg --vflip -o /home/user/path/test2.jpeg --vflip

    To change the delay time use -t with time in milliseconds

    libcamera-jpeg --vflip -o /home/user/path/test3.jpeg -t 100
    libcamera-jpeg --vflip -o /home/user/path/test4.jpeg -t 100 --width 640 --height 480

    Libcamera-still allows you to save in different formats through the equivalency switch (-e)

    libcamera-still -e png -o /home/user/path//FirstPNGphoto.png


    Here you are making a 5 second video and storing it in the Videos directory.  the .h264 makes an mp4 video.  

     libcamera-vid -t 10000 -o /home/  /path/video.h264 --vflip

    to find help options try the -h switch

    libcamera-vid -h 

    time lapse 

     libcamera-still --vflip -t 60000 -o test%d.jpg --timelapse 10000


    ffmpeg -framerate 1 -i test%d.jpg -c:v libx264 -r 30 output.mp4

    Note, you can not view the video over VNC viewer as it is too slow 



    Using Python 3





    This page titled 9.22: Libcamera is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?