Hi Shikha,
It seems that you were trying to read stream data from ADFT DAT file. You can try speedup the reading process by chunking the input data and leveraging the parallel computing toolbox for reducing the time taken to read the data.
You can try testing it out using the following example as well:
openExample('driving/ExtractVideoStreamFromADTFDATFileExample');
Once you create chunks of the file, you can read it parallelly. Here is a simple example for reading a file using parfor:
if isempty(gcp('nocreate'))
chunkSize = ceil(lines / chunks);
dataCellArray = cell(chunks, 1);
parfor (curChunk = 1:chunks, numWorkers)
startLine = (curChunk - 1) * chunkSize + 1;
endLine = min(curChunk * chunkSize, lines);
dataCellArray{curChunk} = readChunk(startLine, endLine, 'dummy_data.txt');
dataArray = vertcat(dataCellArray{:});
da = vertcat(dataArray{:})
function dataChunk = readChunk(startLine, endLine, filename)
fileID = fopen(filename, 'r');
dataChunk = textscan(fileID, '%d', endLine-startLine+1, 'HeaderLines', startLine-1);
You can modify the above code snippet to work for “adftFileReader” as well. Please refer to the following code snippet:
numChunks = itemcount/chunkSize;
dataCellArray = cell(numChunks, 1);
parfor (curChunk = 1:numChunks, numWorkers)
startIndex = (curChunk-1)*chunkSize+1;
endIndex = min(startIndex+chunkSize-1,itemcount);
dataCellArray{curChunk} = readChunk(startIndex, endIndex);
dataArray = vertcat(dataCellArray{:})
function dataChunk = readChunk(startIndex, endIndex)
dataFolder = fullfile(tempdir, 'adtf-video', filesep);
datFileName = fullfile(dataFolder,"sample_can_video.dat");
file_reader = adtfFileReader(datFileName);
stream_reader = select(file_reader, stream_index, IndexRange=[startIndex endIndex]);
dataChunk = read(stream_reader);
I have tested the code snippet on the example mentioned above. I have created chunks containing 10 frames (total 149 frames are present) and here is a glimpse of result stored in “dataArray”:
The first 10 frames of the video are stored as:
I would suggest to profile your code and perform the tasks asynchronously.
I hope this helps!