how to extract frames from video using video reader efficiently
3 ビュー (過去 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!