Skip to content

Analysis

The Video Analyzer SDK enables analysis of video frames as they are displayed to users. This guide covers how to set up frame analysis, process video data, and handle the results. You can get frames from a camera, a video file, or any other source that provides video frames, as long as you can convert them to OpenCV Mat objects.

Note

Processing speed depends on device performance and frame resolution. Lower resolutions and frame rates will yield faster analysis times.

Getting Started

Once your application is registered, you can start analyzing video frames in real-time.

Tip

Please check the CameraActivity.java in our demo app for a complete example of integrating the Video Analyzer SDK with camera input. Or check the BenchmarkActivity.java for an example of analyzing images using OpenCV directly.

Step 1: Initialize the VideoAnalyzerManager

Create a VideoAnalyzerManager instance to handle frame analysis:

import com.aveq.videoanalyzer.VideoAnalyzerManager;

// Basic initialization with defaults
VideoAnalyzerManager manager = new VideoAnalyzerManager(context);

// Or with custom display parameters
VideoAnalyzerManager manager = new VideoAnalyzerManager(
    context,
    1920,    // Display width in pixels
    1080,    // Display height in pixels
    30.0     // Frames per second for PTS calculations
);

Step 2: Set Up Frame Metrics Callback

Register a callback to receive metrics as each frame is processed:

manager.registerFrameMetricsCallback(new FrameMetricsCallback() {
    @Override
    public void onFrameMetrics(SingleFrameMetrics metrics) {
        // This callback is called for each analyzed frame
        // Update your UI or process metrics on the main thread
        runOnUiThread(() -> {
            // do whatever you want with the metrics
        });
    }
});

Step 3: Process Video Frames

The SDK works with OpenCV Mat objects. You need to provide the native Mat pointer and frame index:

import org.opencv.core.Mat;

// Example: Create or obtain a Mat object from your video source
Mat videoFrame = getVideoFrame(); // Your method to get current frame

// Get the native pointer from the Mat
long matPtr = videoFrame.getNativeObjAddr();

// Analyze the frame
int frameIndex = getCurrentFrameIndex(); // Your frame counter
manager.analyzeFrame(matPtr, frameIndex);

Next, learn about the specific metrics that the SDK provides.