how to extract frames from video using video reader efficiently
Show older comments
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
Answers (0)
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!