how to extract frames from video using video reader efficiently
Afficher commentaires plus anciens
Hello. I extract frames from a video with file extension .mp4 using the code below following this discussion:
vid = VideoReader(video); %'test.mp4'
numFrames = vid.NumberOfFrames;
frame_rate = vid.FrameRate;
sprintf('frames: %d frames. frame rate: %d ', numFrames, frame_rate)
n=numFrames;
for i = 1:n
frames = read(vid,i);
imwrite(frames,['Image' int2str(i), '.jpg']); % write this frame to file
end
Then when i reconstruct the video from the written files using this piece of code:
VidObj = VideoWriter('reTest', 'MPEG-4');
open(VidObj);
for f = 1:totalFrames
i = ['Image' num2str(f) '.jpg'];
gI = imread(i);
writeVideo(VidObj, gI);
end
close(VidObj);
resulting video is much bigger than the original video. Why is this? and how can it be corrected/avoided/mitigated? thanks
Réponses (0)
Catégories
En savoir plus sur Video Formats and Interfaces dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!