Main Content


Record video from Camera Board



record(mycamera,filename,duration) records video from the Camera Board to a file on Raspberry Pi®.


collapse all

You can connect to the camera board on the Raspberry Pi hardware, from the MATLAB® software, take a photograph, and record video.

Create a connection from the MATLAB software to the Raspberry Pi hardware.

mypi = raspi


If you encounter errors after running the above command, try using additional arguments (as listed in raspi) or refer to Troubleshoot Connecting Issues to Raspberry Pi Hardware.

Create a connection, mycam, from the MATLAB software to the camera board on the Raspberry Pi hardware, and set the image resolution. The connection displays the camera board properties.

mycam = cameraboard(mypi,'Resolution','1280x720')
mycam = 

Cameraboard with Properties:

                    Name: Camera Board   
              Resolution: '1280x720'       (View available resolutions)
                 Quality: 10              (1 to 100)
                Rotation: 0               (0, 90, 180 or 270)
          HorizontalFlip: 0              
            VerticalFlip: 0              
               FrameRate: 30              (2 to 30)
               Recording: 0              

   Picture Settings
              Brightness: 50              (0 to 100)
                Contrast: 0               (-100 to 100)
              Saturation: 0               (-100 to 100)
               Sharpness: 0               (-100 to 100)

   Exposure and AWB
            ExposureMode: 'auto'          (View available exposure modes)
    ExposureCompensation: 0               (-10 to 10)
                 AWBMode: 'auto'          (View available AWB modes)
            MeteringMode: 'average'       (View available metering modes)

             ImageEffect: 'none'          (View available image effects)
      VideoStabilization: 'off'          
                     ROI: [0.00 0.00 1.00 1.00] (0.0 to 1.0 [top, left, width, height])

Capture and display a sequence of 10 snapshots on your computer.

for ii = 1:10
img = snapshot(mycam)

Each of the 10 snapshots is the latest image captured by the camera.

If the image is upside down, change its orientation.

mycam.Rotation = 180

You can use the same approach to change the values of other cameraboard properties.

Record a 60 second video.


Stop the recording immediately.


Copy the video from the board to your computer.

getFile(mypi,'myvideo.h264','C:\MATLAB ')

Delete the video file from the hardware to free up space.


Input Arguments

collapse all

Connection to a Camera Board, specified as a cameraboard object.

Use the cameraboard function to create this connection.

Example: mycam

Video file name, specified as a string. The only file extension supported is .h264.

Example: 'myvideo.h264'

Data Types: char

Duration of recording, specified in seconds.


Data Types: double

Extended Capabilities