How to read a video file and save it to multiple frames in numerical order? Because I keep getting back random frames not in order of the video progression
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Manuella Juwita
le 23 Avr 2020
Commenté : Manuella Juwita
le 23 Avr 2020
My current code is
vid = VideoReader('vid.mp4');
numrames = vid.NumberofFrames;
n = numFrames;
for i = 1:1:n
frames = read(vid,i);
imwrite(frames,['mydirectory\'int2str(i),'.jpg']);
im(i) = image(frames);
end
I know that we can use natsortfiles to read a folder of images in numerical order, but how do you do it with a video file?
Thanks in advance
0 commentaires
Réponse acceptée
Geoff Hayes
le 23 Avr 2020
Manuella - does the because I keep getting back random frames not in order of video propression refer to the files that you have created or the images you see in your figure? If the former, try padding some zeros to the integer file name as
imwrite(frames,sprintf('mydirectory\%05d.jpg', i));
so that the file names are like 00001.jpg, 00002.jpg, etc.
If the latter (images you see are in random order) you may need to pause after displaying the image. The pause should be the inverse of the frame rate
vid = VideoReader('vid.mp4');
numFrames = vid.NumberofFrames;
frameRate = vid.FrameRate;
n = numFrames;
for i = 1:1:n
frames = read(vid,i);
imwrite(frames,sprintf('mydirectory\%05d.jpg', i));
im(i) = image(frames);
pause(1/frameRate);
end
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!