Logging Data To Disk

Contents

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.
vidobj = videoinput('dcam', 1, 'Y8_640x480');

% View the default logging mode.
currentLoggingMode = get(vidobj, 'LoggingMode')
currentLoggingMode =

memory

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

% Verify the configuration.
currentLoggingMode = get(vidobj, 'LoggingMode')
currentLoggingMode =

disk

Configuring Disk Logging Properties

In order to log to disk, a MATLAB® AVI file object is required. avifile is a MATLAB function, not a toolbox function. Once an AVI file object is created and configured, it is provided to the video input object's DiskLogger property.

Note: Any configurations to the AVI file object must be done before configuring the DiskLogger property. Configurations made to the AVI file object afterwards will require the DiskLogger property to be re-configured.

% Create an AVI file object.
logfile = avifile('logfile.avi')
Adjustable parameters:
               Fps: 15.0000
       Compression: 'Indeo5'
           Quality: 75
    KeyFramePerSec: 2.1429
         VideoName: 'logfile.avi'

Automatically updated parameters:
        Filename: 'logfile.avi'
     TotalFrames: 0
           Width: 0
          Height: 0
          Length: 0
       ImageType: 'Unknown'
    CurrentState: 'Open'

% Select a codec for the AVI file.
logfile.Compression = 'MSVC';

% Since grayscale images will be acquired, a colormap is required.
logfile.Colormap = gray(256);

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

Initiating the Acquisition

Now that the video input object is configured for logging data to an AVI file, initiate the acquisition.

% Start the acquisition.
start(vidobj)

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

Note, when logging large amounts of data to disk, disk writing may lag behind the acquisition. To ensure that no additional writes are still in progress after the acquisition has completed, use the DiskLoggerFrameCount property to determine if all frames have been writtern to disk.

% Determine the number of frames acquired.
vidobj.FramesAcquired
ans =

    10

% Ensure that all aquired frames were written to disk.
vidobj.DiskLoggerFrameCount
ans =

    10

% Once all frames have been written, close the file.
aviobj = vidobj.Disklogger;
file = close(aviobj)
Adjustable parameters:
               Fps: 15.0000
       Compression: 'MSVC'
           Quality: 75
    KeyFramePerSec: 2.1429
         VideoName: 'logfile.avi'

Automatically updated parameters:
        Filename: 'logfile.avi'
     TotalFrames: 10
           Width: 640
          Height: 480
          Length: 0
       ImageType: 'Indexed'
    CurrentState: 'Closed'

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