how to extract frames from video using video reader efficiently
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!