Skip to content

Recording a video stream#

Recording a video stream is a task you may need to perform for further processing of images. The recorded video stream will then be divided into frames. The most suitable still images will be later used for facial recognition and getting the best shot.

In LUNA ID for Android#

Record a video stream#

To record a video stream, open a camera by using recordVideo = true. For example:

LunaID.showCamera(
    ...
    recordVideo = true,
)

When the camera finishes its work, LunaID.allEvents() (or more specialized LunaID.finishStates()) will emit the ResultSuccess event with the best shot found and an optional path to the recorded video. The entire process of getting the best shot is written to this video file.

LUNA ID does not manage the video file. This means, that file management, that is deletion, copying, sending to a server, and so on, is performed on your side.

The recording stops when the best shot is captured or when a user closes the camera before LUNA ID gets the best shot.

Limit a video stream's duration#

To limit a video stream's duration, specify the recordingTimeMillis parameter in LunaID.ShowCameraParams. This will define the video stream's duration in milliseconds. The default value is not set.

LunaID.showCamera(
    activity,
    LunaID.ShowCameraParams(
        recordVideo = true,
        recordingTimeMillis = 10000
    )
)

Note that the recordingTimeMillis parameter is required if the recordVideo parameter is set to true. Otherwise, the following exception will be thrown:

IllegalStateException, when param recordVideo is true -> param recordingTimeMillis must be positive

Set video stream quality#

To set video stream quality, pass the videoQuality parameter to the LunaID.ShowCameraParams() method. The parameter has the following values:

  • VideoQuality.LOW (default)
  • VideoQuality.HIGH

Video stream quality is determined by the following parameters:

Parameter SD (Low quality) SD (High quality) HD 720p HD 1080p
Video resolution 320×240 px 720×480 px 1280×720 px 1920×1080 px
Video frame rate 20 fps 30 fps 30 fps 30 fps
Video bitrate 384 Kbps 2 Mbps 4 Mbps 20 Mbps

In LUNA ID for iOS#

Record a video stream#

To record a video stream:

1․ Define the recordVideo parameter as true in:

let controller = LMCameraBuilder.viewController(delegate: self,
                                                    recordVideo: true)

2․ Find the video file path in the bestShot function in the LMCameraDelegate protocol.

public protocol LMCameraDelegate: AnyObject {

    func bestShot(_ bestShot: LunaCore.LCBestShot, _ videoFile: String?)

    func error(_ error: LMCameraError, _ videoFile: String?)

}

The detected face in the frame is tracked all the time when the camera is on.

Limit a video stream's duration#

To limit a video stream's duration:

  1. Enable face identity tracking by setting the LCLunaConfiguration.trackFaceIdentity property to true.
  2. Specify a video stream length in LCLunaConfiguration::videoRecordLength, in seconds.
  3. Call LMCameraCaptureManager::createVideoRecordWatchDog(LunaCore::LCBestShotDetectorProtocol) in your ViewController.
    This call enables a watchdog object which tracks a primary face search and starts video stream recording. After the time defined in LCLunaConfiguration::videoRecordLength expires, the recording will stop.
    The watchdog object lives inside the capture manager and is not available for public usage.