You can record a video from multiple cameras. You can start all cameras
configured on your system to start recording at the same time. The Camera library provides the capability for you to start recording from multiple cameras and ensures that the timestamps on the encoded video match.
Here are some situations when synchronized recording is important to ensure that there isn't any latency between the video from multiple cameras.
- You need to synchronize and replicate multiple streams together. For example, you need to synchronize and replicate the streams from multiple cameras to stitch together a video to give a 360-degree view.
- Time-sensitive algorithms that use multiple camera streams. For example, you are applying algorithms to identify objects, typically, the tolerance of delay for playback must be minimal for those algorithms to work properly. As such, the recording from multiple cameras must be synchronized to deliver video streams from the imaging datapath in realtime.
When you want to record video from multiple cameras, each camera creates its own file.
You can play those individual files separately, or you can run
third-party algorithms on the video to combine or stitch together the video.
Often these third-party algorithms require that the video is synchronized to combine multiple
videos together. To ensure that the video you take is synchronized, you must add the cameras
into a video group.
A video group is simply a set of cameras that are associated
with each other. When a camera is associated with a video group, calls to camera_start_video()
or camera_start_encode() no longer start recording video or encoding video right away, but
wait until a call to camera_start_video_group() is made. This allows you to call
camera_start_video() and camera_start_encode() on several cameras and then
call camera_start_video_group() to start recording/encoding for all the cameras in the group, simultaneously.
Here are the basic steps to start recording on multiple cameras at one time:
- Open each camera you want to use. You will get a separate handle for each camera. For more information, see Open the camera.
- Set the viewfinder for each camera. For more information, see Set the viewfinder mode for camera.
- Set up Screen. See Use Screen with the Camera API for more information.
- Start the viewfinder and configure the camera settings as necessary as described in Start viewfinder and configure camera settings in this guide.
- Create a Screen context, window, and
buffers. For more information, see Using streams
in the Resource
Sharing
chapter of the Screen Developer's Guide.
- If you change the format, width, height of the viewfinder from its default setings,
you must set the video properties for these to those new values
since the default properties for video should match the default viewfinder properties
that were overwritten. The exception is framerate, where you can set the
viewfinder to record at an integer multiple of the viewfinder
framerate as long as the framerate isn 't higher. For example, if your viewfinder
framerate is set to 30 fps, you can record 15 fps (multiple of two) or 10 fps (multiple of three).
You can get the viewfinder properties from the camera using
camera_get_vf_property().
Here are the typical properties that you should check match:
- CAMERA_IMGPROP_FORMAT
- CAMERA_IMGPROP_WIDTH
- CAMERA_IMGPROP_HEIGHT
- CAMERA_IMGPROP_ROTATION
- CAMERA_IMGPROP_FRAMERATE
- CAMERA_IMGPROP_VIDEOCODEC
- CAMERA_IMGPROP_AUDIOCODEC
Then, you can set the properties using
camera_set_video_property(). For some properties,
you can use the
camera_set_*() function, such as
:
- CAMERA_IMGPROP_FORMAT
- CAMERA_IMGPROP_WIDTH
- CAMERA_IMGPROP_HEIGHT
- CAMERA_IMGPROP_ROTATION
- CAMERA_IMGPROP_FRAMERATE
- CAMERA_IMGPROP_VIDEOCODEC
- CAMERA_IMGPROP_AUDIOCODEC
- Create a video group using the
camera_create_video_group().
You will get a group ID passed by reference back to you from the call.
- Call camera_add_video_group_entry()
to associate (or add) each camera to the video group.
Ensure that you specify the group ID that you got from the
previous step and the handle for each camera
when you call camera_add_video_group_entry().
You can add or remove cameras before you call
camera_start_video_group() or
camera_start_video() on the camera.
- If you want to encode or record video, you call
camera_start_encode() or camera_start_video(),
respectively.
Note: This step doesn't actually start the encoding or recording
until the next step.
- Call camera_start_video_group() to start encoding or recording at the same time.
To stop recording, you can call camera_stop_video_group(),
but then you must call camera_stop_encode() or
camera_stop_video() to finalize encoding or recording the video files for each camera.
You can remove cameras from the video group after to you stop recording.
- After you are done using the video group, call camera_destroy_video_group().
Any cameras still associated with the video group are automatically disassociated
from the group before the function completes. It's a good idea to set the
group ID variable to CAMERA_VIDEO_GROUP_INVALID
after camera_destroy_video_group() completes.
`