Events Recording to Files

After you have successfully ref:opened a camera <chapter_guides_camera_opening> and started to stream data, you might want to save this event data to a file for further analysis or processing. Let’s explore how to achieve this using the SDK API.

Using HAL C++ API

While a device is actively streaming data, you can record the raw stream to a file using the HAL API. This process is demonstrated in the metavision_hal_showcase sample.

Here is the related excerpt from the sample:

Metavision::I_EventsStream *i_eventsstream = device->get_facility<Metavision::I_EventsStream>();
if (i_eventsstream) {
    i_eventsstream->log_raw_data(raw_file_path);
    }
}

Every RAW file contains a header with information about the actual device and plugin that generated it. See details about the file format in our RAW file page.

Using SDK Stream C++ API

SDK Stream C++ API provides start_recording and stop_recording in the Camera class:

camera = Metavision::Camera::from_first_available();
camera.start();
camera.start_recording(raw_file_path);
(...)
camera.stop_recording(raw_file_path);
camera.stop();

Check out the metavision_viewer sample to see those functions in action.

Using SDK Python API

To record a RAW file using the SDK Core Python API, you can leverage the Python binding of the HAL EventsStream facility (get_i_events_stream()). This provides access to the log_raw_data() and stop_log_raw_data() functions for recording data from your device.

Here is an example with a device opened with DeviceDiscovery that could be leveraged for example in the metavision_hal_get_started sample:

device = DeviceDiscovery.open("")
device.get_i_events_stream().log_raw_data(file_path)
(...)
device.get_i_events_stream().stop_log_raw_data()

Here is another example visible in metavision_simple_recorder sample in which EventsIterator is used to stream the events:

device = initiate_device("")
if device.get_i_events_stream():
    device.get_i_events_stream().log_raw_data(file_path)
mv_iterator = EventsIterator.from_device(device=device)
for evs in mv_iterator:
    // events will be recorded automatically but we can also process/display them
device.get_i_events_stream().stop_log_raw_data()