Hi everyone, I have managed to modify the code to include a for loop:
%%08 July 2019, Louise Wilson
%Code to split .avi file into many .jpg files.
%Same code but attempting for loop to analyse multiple files in a folder...
clc;
clear;
%Set current directory to folder containing this m file
paths=cd('C:\Users\lwil634\Documents\Cameras\Test');
for i=1:length(paths)
d=dir(fullfile(paths, '*.avi'));
for j=1:length(d)
vidfile=d(j).name
videoObject=VideoReader(vidfile)
[folder, baseFileName, extentions] = fileparts(vidfile);
folder=pwd;
outputFolder = sprintf('%s/Frames', folder);
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
for x=1 : numberOfFrames
frame = read(videoObject,x)
outputBaseFileName = sprintf('-%4.4d.png', x); %output filename, each frame numbered from 0001
outputFullFileName = fullfile(outputFolder, strcat(baseFileName, outputBaseFileName)); %output filename
imwrite(frame, outputFullFileName, 'png'); %write output file
end
end
end
This code works-I get all of the frames for each AVI file in the folder I specify. However, I think it is erroneous? When I run the code, it runs forever, and doesn't stop until I ctrl+c. I only did this once I checked the output folder and saw that all of the files I expected were there. What can do to stop the code running on and on even though I believe it to be finished...?
Ultimately I am trying to write something so that I can put multiple paths in the paths section, so I could use the script to run through many folders of avi files at one execution of code.
Thanks!!