Understanding the camera roll

Updated: May 06, 2022

The camera roll is a directory on the target where the camera application saves files. When you use the camera roll, it manages the filenames of video files to ensure that they are unique.

You can call camera_roll_open_video() to get a unique filename that you can pass as an argument when you call camera_start_video(). Each filename uses a date and time stamp to ensure uniqueness and gets written to the directory you specified using -r when starting the Sensor service. When you use the camera roll, the Camera library manages write access to the video files for you, to ensure that only one process writes to a file.

It isn't mandatory to use the camera roll. Optionally, you can choose your own name for the file to write to when you call camera_start_video(), using the filename argument. If you have a requirement to do this, you are responsible for managing write access to the file, ensuring that its name is unique, and managing any file descriptors associated with it.

The following code snippet that shows how to use the first camera configured on a system to use the camera roll and to start recording a video.
Note: It's presumed that you have connected to the camera, set the viewfinder mode, and started the viewfinder. It's also presumed that you have the Screen code in place.
int main(int argc, char *argv[])
    camera_handle_t cameraHandle;
    // Open the first camera
    camera_open(CAMERA_UNIT_1, CAMERA_MODE_RW | CAMERA_MODE_ROLL, &cameraHandle);
    camera_set_vf_mode(cameraHandle, CAMERA_VFMODE_VIDEO);
    camera_start_viewfinder(cameraHandle, NULL, NULL, NULL);
    // Screen code to handle showing the video on the display goes here
    char* rollFilename = (char*) malloc(sizeof(char) * CAMERA_ROLL_NAMELEN);
                           &fd, rollFilename,
                           CAMERA_ROLL_NAMELEN, CAMERA_ROLL_VIDEO_FMT_MP4);
    camera_start_video(cameraHandle, rollFilename, NULL, NULL, NULL);