This example shows how to extract and visualize a video stream, stored in an ADTF DAT file. It also shows how to write the video stream into a video file.
Download the sample video DAT file.
Downloading sample_can_video_dat.zip (9.74 MB)...
Extracting sample_can_video_dat.zip...
Create the ADTF File Reader object.
fileReader =
DataFileName: "C:\Users\latriwal\AppData\Local\Temp\adtf-video\sample_can_video.dat"
DescriptionFileName: ""
PluginDirectory: ""
StreamCount: 2
StreamInfo:
StreamIndex StreamName StreamType StartTime EndTime ItemCount SubstreamInfo
___________ __________ ______________ _________ __________ _________ _____________
1 {'rawcan'} {'UNRESOLVED'} 0 sec 14.805 sec 743 {0×1 struct}
2 {'video' } {'adtf/image'} 0 sec 14.799 sec 149 {0×1 struct}
From the StreamInfo
property, note that the index of the video stream is 2. Use the select
function of the adtfFileReader
object, to select the video stream for reading. The returned adtfStreamReader
object has all the information about the selection.
streamReader =
adtfStreamReader with properties:
DataFileName: "C:\Users\latriwal\AppData\Local\Temp\adtf-video\sample_can_video.dat"
DescriptionFileName: ""
PluginDirectory: ""
StreamIndex: 2
StartIndex: 1
EndIndex: 149
CurrentIndexOffset: 0
StartTime: [0×0 duration]
EndTime: [0×0 duration]
DataCount: 149
Note that the value of CurrentIndexOffset
is 0. This signifies that the next readNext
call will return the first item.
Preview the first image frame from the stream.
Before creating a video, use the reset
function to start reading from the first frame. This resets the value of CurrentIndexOffset
to 0.
Create a VideoWriter
object that you can use to write image frames to a video file. Specify a frame rate of 1 frame per second.
Using the streamReader
object, iterate over the data items in the selection one-by-one. The hasNext
function determines if there is an item left to read as we are incrementally reading the file. readNext
returns the data item which is basically a structure containing the data and the associated timestamp. In every iteration, extract the image frame and write it to the video file.
Alternatively, you can read all the image frames at once, using the read
function, and iterate over it later.
allData = struct with fields:
StreamIndex: 2
Data: [149×1 struct]
Close the connection with the video file.
Visualize the output file example_video.avi
using Video Viewer.