fileDatastore read: Index exceeds the number of array elements (0).

1 view (last 30 days)
I am attempting to set up a fileDatastore (vds, for video datastore) that will send 1 video file at a time to a modified version of the MotionBasedMultiObjectTrackingExamples.m. I have the following code:
loc = "C:\Users\Christine Deer\Downloads\02242021-SV\02242021-SV";
vds = fileDatastore(loc, 'ReadFcn', @videoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')
function v = videoReader(file)
v = videoReader(file);
Which generates the following output:
vds =
FileDatastore with properties:
Files: {
' ...\Camera 1 - (FLIR A400) - 14-20210216-210329.mp4';
' ...\Camera 1 - (FLIR A400) - 14-20210218-012228.mp4';
' ...\Camera 1 - (FLIR A400) - 14-20210218-232125(1).mp4'
... and 1 more
Folders: {
'C:\Users\Christine Deer\Downloads\02242021-SV\02242021-SV'
UniformRead: 0
ReadMode: 'file'
BlockSize: Inf
PreviewFcn: @videoReader
SupportedOutputFormats: [1×16 string]
ReadFcn: @videoReader
AlternateFileSystemRoots: {}
Error using (line 29)
Index exceeds the number of array elements (0).
Error in DatastoreLoad (line 5)
This looks like vds is populated with the correct data. What I am confused by is that the data is in vds, but I cant seem to call the read properly to not get an error. Any help understanding this error and its resolution is greatly appreciated and thoroughly welcome,
Christine D

Accepted Answer

Kojiro Saito
Kojiro Saito on 2 Jul 2021
videoReader function should be VideoReader.
Also, for avoiding function name conflict, it's better to use another name to custom function than videoReader.
vds = fileDatastore(loc, 'ReadFcn', @myVideoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')
function v = myVideoReader(file)
v = VideoReader(file);
Or, simply, you don't need to use custom function in this case.
vds = fileDatastore(loc, 'ReadFcn', @VideoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!