classdoc: VideoDetector [c++], [c#]

A common use of the SDK is to process previously captured video files. The VideoDetector [c++], [c#] helps streamline this effort by decoding and processing frames from a video file. Like the FrameDetector, the constructor accepts a parameter for processing frames per second. This parameter regulates how many frames from the video stream get processed. During processing, the VideoDetector decodes and processes frames as fast as possible and actual processing times will depend on CPU speed. Please see this list of accepted file types and recommended video codecs that are compatible with the detector.

Creating the detector

The VideoDetector [c++], [c#] constructor expects two parameters { processFrameRate, maxNumFaces and faceConfig }

                The maximum number of frames processed per second
                If not specified, DEFAULT_PROCESSING_FRAMERATE=30
              float processFrameRate,
                The maximum number of faces to track
                If not specified, DEFAULT_MAX_NUM_FACES=1
              unsigned int maxNumFaces,

                Face detector configuration
                If not specified, defaults to FaceDetectorMode.SMALL_FACES

                FaceDetectorMode.LARGE_FACES=Faces occupying large portions of the photo
                FaceDetectorMode.SMALL_FACES=Faces occupying small portions of the photo
              FaceDetectorMode faceConfig


VideoDetector detector = new VideoDetector(15);

Configuring the detector

In order to initialize the detector, a valid location of the data folder must be specified:

Data folder

The Affdex classifier data files are used in frame analysis processing. These files are supplied as part of the SDK. The location of the data files on the physical storage needs to be passed to a detector in order to initialize it by calling the following with the fully qualified path to the folder containing them:

String classifierPath="C:\\Program Files(x86)\\Affectiva\\Affdex SDK\\data"

Configuring the callback functions

The Detectors use callback functions defined in interface classes to communicate events and results. The event listeners need to be initialized before the detector is started: The FaceListener is a client callback interface which sends notification when the detector has started or stopped tracking a face. Call setFaceListener to set the FaceListener:

classdoc: FaceListener [c++], [c#]

class MyApp : Affdex.FaceListener {
  MyApp() {

The ImageListener is a client callback interface which delivers information about an image which has been handled by the Detector. Call setImageListener to set the ImageListener:

classdoc: ImageListener [c++], [c#]

class MyApp : Affdex.ImageListener {
  MyApp() {

The ProcessStatusListener is a callback interface which provides information regarding the processing state of the detector. Call setProcessStatusListener to set the ProcessStatusListener:

classdoc: ProcessStatusListener [c++], [c#]

class MyApp : Affdex.ProcessStatusListener {
  MyApp() {

Choosing the classifiers

The next step is to turn on the detection of the metrics needed. For example, to turn on or off the detection of the smile and joy classifiers:


To turn on or off the detection of all expressions, emotions or emojis:


To check the status of a classifier at any time, for example smile:


Initializing the detector

After a detector is configured using the methods above, the detector initialization can be triggered by calling the start method:


The start() spawns a thread that decodes video frames then processes them and use the callback functions to notify of the decoded frames, results and exceptions (if exist).

Processing a video

Once the detector is started, the processing begins by calling the process function, the path to video file you are processing is passed in as a parameter:

void process(String path);

On completion of the video processing, the onProcessingFinished function is called from the ProcessStatusListener [c++], [c#]. process() is a non-blocking call.

Stopping the detector

At the end of the interaction with the detection. Stopping the detector can be done as follows:


The processing state can be reset. This method resets the context of the video frames. Additionally Face IDs and Timestamps are set to zero (0):