How to save images on a new folder created automaticaly and named after a video.

1 visualización (últimos 30 días)
So, I`m extracting frames from a video and saving them as JPEG images. However I want to save the frames automaticaly in a folder named after the video they`re from. I`m really struggling with this. This is the code I`m using. The frame extrating works as intended, the new automatic folder is the problem.
%reading video frames
vid=VideoReader('C:\Users\Myname\Documents\Test\Videos\Thevideo.avi');
numFrames = vid.NumberOfFrames;
n=numFrames;
% making a folder to save the frames
Folder = 'C:\Users\Myname\Documents\Test\Videos\Extrac\';
% writing extracted frames into the specified folder
for iFrame = 1:n
frames = read(vid, iFrame);
imwrite(frames, fullfile(Folder, sprintf('%03d.jpg', iFrame)));
end
I tried using mkdir but I`m really confused by its syntax and how to get the new folder`s path.
For example : mkdir vid.Path vid.Name . This should create a new folder named after the video`s name right ?
How do I get the path of this folder ? This syntax does not seem to work

Respuesta aceptada

Stephen23
Stephen23 el 7 de Oct. de 2021
Editada: Stephen23 el 7 de Oct. de 2021
"For example : mkdir vid.Path vid.Name. This should create a new folder named after the video`s name right ? "
No it won't, because you used command syntax it will create a folder literally called "vid.Name", whereas you must use function syntax if you want to include an input variable:
mkdir(vid.Path,vid.Name)
"How do I get the path of this folder ?"
newFolder = fullfile(vid.Path,vid.Name)
Note that you should probably remove the file extension (rather than naming the folder using the complete filename) for which FILEPARTS is the correct tool. And to ensure consistency you should use the name that you create using FULLFILE, so your code should probably be something like this:
[~,noex] = fileparts(vid.Name);
fpth = fullfile(vid.Path,noex);
mkdir(fpth)
.. fullfile(fpth,sprintf(..))

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by