Main Content

Logging Data to Disk

This example shows how to configure logging properties for disk logging and then initiate an acquisition to log.

Configuring Logging Mode

Data acquired from an image acquisition device may be logged to memory, to disk, or both. By default, data is logged to memory. To change the logging mode, configure the video input object's LoggingMode property.

% Access an image acquisition device, using a grayscale video format with
% 10 bits per pixel.
vidobj = videoinput('gige', 1, 'Mono10');

% View the default logging mode.
currentLoggingMode = vidobj.LoggingMode;
currentLoggingMode =


% List all possible logging modes.
set(vidobj, 'LoggingMode')
[ {memory} | disk | disk&memory ]
% Configure the logging mode to disk.
vidobj.LoggingMode = 'disk';

% Verify the configuration.
currentLoggingMode = vidobj.LoggingMode;
currentLoggingMode =


Configuring Disk Logging Properties

Logging to disk requires a MATLAB® VideoWriter object. VideoWriter is a MATLAB function, not a toolbox function. After you create and configure a VideoWriter object, provide it to the video input object's DiskLogger property.

VideoWriter provides a number of different profiles that log the data in different formats. This example uses the Motion JPEG 2000 profile which can log single-banded (grayscale) data as well as multi-byte data. The complete list of profiles provided by VideoWriter can be found in the documentation.

% Create a VideoWriter object.
logfile = VideoWriter('logfile.mj2', 'Motion JPEG 2000')

  General Properties:
      Filename: 'logfile.mj2'
          Path: 'C:\Temp'
    FileFormat: 'mj2'
      Duration: 0

  Video Properties:
                FrameCount: 0
                 FrameRate: 30
    VideoCompressionMethod: 'Motion JPEG 2000'
          CompressionRatio: 10
       LosslessCompression: 0

% Configure the video input object to use the VideoWriter object.
vidobj.DiskLogger = logfile;

Initiating the Acquisition

Now that the video input object is configured for logging data to a Motion JPEG 2000 file, initiate the acquisition.

% Start the acquisition.

% Wait for the acquisition to finish.
wait(vidobj, 5)

When logging large amounts of data to disk, disk writing sometimes lags behind the acquisition. To determine whether all frames have been written to disk, use the DiskLoggerFrameCount property.

while (vidobj.FramesAcquired ~= vidobj.DiskLoggerFrameCount)

Verify that the FramesAcquired property and the DiskLoggerFrameCount property have the same value.

ans =


ans =


% When the video input object is no longer needed, delete
% it and clear it from the workspace.
clear vidobj