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 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Geoff Hayes
2020 年 4 月 23 日
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
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!