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 -hif 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.
| Item | Purpose | Connection or setup note |
|---|---|---|
| Raspberry Pi | Runs the camera software and stores captured media | Boot Raspbian and provide stable power |
| Camera module | Captures light and converts it into image or video data | Use a module compatible with the Pi model |
| Ribbon cable | Carries data between the camera and Pi | Insert it squarely and fully; orientation matters |
| CSI connector | Provides the camera interface | On the referenced board layout, it is between the Ethernet and HDMI ports |
| Storage device | Holds JPEG and H.264 output files | Leave sufficient free space before recording |
Connect the camera safely
- 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.
- Find the CSI camera connector. On the referenced Raspberry Pi board layout, it is located between the Ethernet and HDMI ports.
- Lift the small connector latch.
- Insert the ribbon cable fully and squarely into the connector. For this board layout, the exposed silver contacts face the HDMI port.
- Press the latch down to lock the cable in place.
- 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 upgradesudo 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.
- Open the configuration utility:
sudo raspi-config- Open the interface settings.
- Select the camera interface and enable it.
- Finish the configuration and save the setting.
- 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.jpgThe -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.jpgThis 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.h264The 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.h26410000 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 command | Purpose | Key option | Example output |
|---|---|---|---|
raspistill | Capture a still image | -o for output; -t for delay | picture.jpg |
raspivid | Record video | -o for output; -t for duration in milliseconds | video.h264 |
omxplayer | Play the recorded video | Input filename | omxplayer video.h264 |
apt-get update | Refresh package information | Run before an upgrade | Updated package lists |
apt-get upgrade | Install available upgrades | Review and confirm changes | Upgraded 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.h264Playback 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 type | Example filename | Format | Playback or viewing note |
|---|---|---|---|
| Still image | picture.jpg | JPEG | Open with a graphical image viewer or another JPEG-capable application |
| Video clip | video.h264 | Elementary H.264 stream | Try 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.shThe 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
raspistillcommand.
The preview appears, but the output file is missing
- Run
pwdto check the current directory. - Run
lsto 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
- Power off the Pi and connect the camera ribbon cable correctly.
- Boot Raspbian and open a terminal.
- Run
sudo apt-get update, thensudo apt-get upgradewhen appropriate. - Enable the camera interface with
sudo raspi-config. - Reboot if prompted.
- Capture
picture.jpgwithraspistill -o picture.jpg. - Capture a five-second
video.h264file withraspivid -o video.h264, or set an explicit timeout. - Open the image with an image viewer or play the video with a compatible player.