Raspberry Pi online course

Record Pictures and Videos with a Raspberry Pi Camera

Learn to connect and enable a Raspberry Pi camera, capture JPEG photos with raspistill, record H.264 video with raspivid, play media, and automate timestamped photos.

What you will learn

A Raspberry Pi camera module is a small printed circuit board (PCB) camera accessory designed to connect directly to a Raspberry Pi. This lesson covers the original Raspberry Pi camera command-line utilities: raspistill for photographs and raspivid for video.

The camera hardware described in the historical example could capture 5-megapixel still images and 1080p video. Specifications vary by camera model, however, so check the documentation for your particular module. The commands in this lesson apply to Raspbian systems that include the legacy raspistill and raspivid utilities.

You should already know how to boot a Raspberry Pi, safely power it off, open a terminal, navigate directories, and work with files.

Required hardware and software

  • A Raspberry Pi with a compatible camera interface.
  • A compatible Raspberry Pi camera module.
  • A camera ribbon cable. The ribbon cable is a flat cable that carries the camera connection between the module and the Pi.
  • A suitable power supply.
  • A display and keyboard, or remote terminal access such as SSH.
  • Storage with enough free space for JPEG images and video files. Use a disk-space command such as df -h if you need to check available capacity.
  • Raspbian, with the legacy Raspberry Pi camera utilities installed.

The camera connects through the dedicated CSI connector. CSI means Camera Serial Interface. This is different from connecting a webcam through a USB port.

ItemPurposeConnection or setup note
Raspberry PiRuns the camera software and stores captured mediaBoot Raspbian and provide stable power
Camera moduleCaptures light and converts it into image or video dataUse a module compatible with the Pi model
Ribbon cableCarries data between the camera and PiInsert it squarely and fully; orientation matters
CSI connectorProvides the camera interfaceOn the referenced board layout, it is between the Ethernet and HDMI ports
Storage deviceHolds JPEG and H.264 output filesLeave sufficient free space before recording

Connect the camera safely

  1. Shut down the Raspberry Pi and disconnect its power before attaching or removing the ribbon cable. Do not connect the cable while the Pi is powered.
  2. Find the CSI camera connector. On the referenced Raspberry Pi board layout, it is located between the Ethernet and HDMI ports.
  3. Lift the small connector latch.
  4. Insert the ribbon cable fully and squarely into the connector. For this board layout, the exposed silver contacts face the HDMI port.
  5. Press the latch down to lock the cable in place.
  6. Connect the camera end of the ribbon cable using the same careful, fully inserted connection, then close its latch if it has one.

An incorrectly seated, loose, or reversed cable can prevent the camera from being detected. If the camera is not recognized, power off the Pi before reseating the cable.

Update Raspbian

After booting the Pi, open a terminal. Refresh package information before upgrading installed packages:

sudo apt-get update
sudo apt-get upgrade

sudo runs a command with administrator privileges. apt-get update downloads current package information from the configured repositories; it does not itself upgrade installed software. apt-get upgrade installs available upgrades for packages already installed. Review the proposed changes and confirm when prompted.

The update commands require network access. A reboot may be needed after system updates or after changing camera configuration. For more background, see Update Raspbian and Connect to the Internet.

Enable the camera interface

Raspbian must enable the camera interface before camera capture tools can access the module.

  1. Open the configuration utility:
sudo raspi-config
  1. Open the interface settings.
  2. Select the camera interface and enable it.
  3. Finish the configuration and save the setting.
  4. Reboot when prompted, or reboot after exiting if the utility requests it.

You can also review the dedicated guide to enable the camera in raspi-config. Verify recognition before attempting a larger capture. A short test with raspistill, after the cable and configuration have been checked, is a practical verification. If the command reports that no camera is available, see the troubleshooting section below.

Capture a still picture with raspistill

raspistill is the legacy Raspberry Pi command-line utility for capturing still images. Its basic output syntax is:

raspistill -o picture.jpg

The -o option specifies the output filename. In this example, the .jpg extension indicates a JPEG image, a common compressed image format. Because picture.jpg is a relative filename, it is saved in the terminal's current working directory. Check that directory with pwd, and list its files with ls.

The command normally shows a preview before capture. To give yourself time to position the camera, add a delay with -t. The delay is measured in milliseconds:

raspistill -t 2000 -o picture.jpg

This waits two seconds before taking the picture. A relative output filename does not automatically mean the file is saved beside the script; it is saved relative to the directory from which you ran the command.

Record video with raspivid

raspivid is the related legacy utility for recording video. A basic command is:

raspivid -o video.h264

The output is an H.264 video stream. With the basic command, the historical default recording duration is five seconds. To choose a duration, use -t followed by milliseconds:

raspivid -t 10000 -o video.h264

10000 milliseconds equals 10 seconds. Always convert seconds to milliseconds before entering the value: multiply the number of seconds by 1,000.

An .h264 file is an elementary, or raw, H.264 stream. It is not the same as an MP4 file, which is a container that can hold video together with metadata and other streams. Some desktop players and devices will not open a raw H.264 stream directly.

Tool or commandPurposeKey optionExample output
raspistillCapture a still image-o for output; -t for delaypicture.jpg
raspividRecord video-o for output; -t for duration in millisecondsvideo.h264
omxplayerPlay the recorded videoInput filenameomxplayer video.h264
apt-get updateRefresh package informationRun before an upgradeUpdated package lists
apt-get upgradeInstall available upgradesReview and confirm changesUpgraded installed packages

View captured media

Open a photograph

Use an installed image viewer to open the JPEG. From a graphical Raspbian desktop, you can usually double-click the file in the file manager. You can also open it through the viewer's file-open command or menu, depending on which viewer is installed. The important detail is to open the file from the directory where raspistill saved it.

Play the video

The historical Raspberry Pi playback example uses omxplayer:

omxplayer video.h264

Playback support depends on the installed player and the Raspbian or Raspberry Pi operating system version. If omxplayer is unavailable, use a compatible installed media player. When sharing raw H.264 footage with another device, conversion or remuxing into a more broadly supported container such as MP4 may be necessary.

Capture typeExample filenameFormatPlayback or viewing note
Still imagepicture.jpgJPEGOpen with a graphical image viewer or another JPEG-capable application
Video clipvideo.h264Elementary H.264 streamTry omxplayer where available; conversion or remuxing may be needed for sharing

Automate a photo capture

A shell script is a text file containing commands that can be run repeatedly. This example creates a timestamped filename so each capture is preserved instead of overwriting picture.jpg:

#!/bin/sh
raspistill -o "picture-$(date +%Y%m%d-%H%M%S).jpg"

Save the contents in a file named take-picture.sh. Then make it executable and run it:

chmod +x take-picture.sh
./take-picture.sh

The date command produces a suffix such as 20260818-143025. The result might be named picture-20260818-143025.jpg. This pattern is useful for a small camera-based game or project: a button, sensor, or program can trigger the script, and every successful capture receives a different filename.

A related example is available in Script That Takes a Picture.

Troubleshooting

No camera is detected

  • Power off the Pi before checking the cable.
  • Confirm that the camera interface is enabled in sudo raspi-config.
  • Check that the ribbon cable is fully inserted and locked at both ends.
  • On the referenced connector layout, confirm that the exposed silver contacts face the HDMI port.
  • Reboot after enabling the interface or changing related configuration.
  • Retry a simple raspistill command.

The preview appears, but the output file is missing

  • Run pwd to check the current directory.
  • Run ls to list files there.
  • Check the spelling and path after -o.
  • Use an explicit output path or the timestamped script to avoid confusion and accidental overwriting.

The video duration is wrong

If you omit -t, the historical default is five seconds. Also check that the value is in milliseconds, not seconds. For example, 10 seconds requires -t 10000.

The H.264 file will not play elsewhere

The file may be a raw H.264 stream rather than an MP4 container, or the player may not support it. Try omxplayer on a compatible Raspberry Pi installation, use another compatible player, or convert/remux the file before sharing it.

Package commands fail

  • Check the network connection; package commands need repository access.
  • Check whether the system date is substantially incorrect.
  • Look for repository errors or a package-manager lock caused by another package process.
  • Follow the package manager's error message and retry only after resolving the reported problem.

Command-line capture workflow

  1. Power off the Pi and connect the camera ribbon cable correctly.
  2. Boot Raspbian and open a terminal.
  3. Run sudo apt-get update, then sudo apt-get upgrade when appropriate.
  4. Enable the camera interface with sudo raspi-config.
  5. Reboot if prompted.
  6. Capture picture.jpg with raspistill -o picture.jpg.
  7. Capture a five-second video.h264 file with raspivid -o video.h264, or set an explicit timeout.
  8. Open the image with an image viewer or play the video with a compatible player.