How can I use VideoReader to read a variable file name

5 views (last 30 days)
I am writing a function that will call many videos and take certain frames from them. I am trying to use a loop in order to allow for the function to read the video names in a folder and place them in VideoReader so I can look through many videos without having to import each video individually.
The general area of issue in the code is here:
videos = dir(videoFolder);
for k=3:length(videos)
vidName = videos(k).name;
v = VideoReader(vidName);
%motion detection code follows
end
where vidName returns the desired name but I believe VideoReader is searching for the file named "vidName" as opposed to the video file name it represents. I receive this error:
Error using VideoReader/init (line 601)
The filename specified was not found in the MATLAB path.
Error in VideoReader (line 171)
obj.init(fileName);
Error in motion_detection (line 12)
v = VideoReader('vidName');

Accepted Answer

Stephen23
Stephen23 on 25 May 2018
Edited: Stephen23 on 25 May 2018
The bug is clear in the error message: you supply a char vector like this:
v = VideoReader('vidName');
when you should be supplying the variable itself, like this:
v = VideoReader(vidName);
  1 Comment
Tristan Sayre
Tristan Sayre on 25 May 2018
Great thanks! It turns out I had forgotten to add the folder to the file path as well which is why the code wasn't working when I used VideoReader without the single quotes.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!