MATLAB: How to take every nth frame from video and make separate video of those taken frame

digital image processingimage processing

I want to take every 20th frame from a 30fps video file of size 1GB and make another video of 2fps video from those taken frames in an efficient way. I am working on laptop having 4GB RAM and 64-bit windows 8.1

Best Answer

vidObjIn = VideoReader(INFILENAME);
vidObjOut = VideoWriter(OUTFILENAME, 'FrameRate', 2);
while hasFrame(vidObjIn)
got_end = false;
for K = 1 : 20
if ~hasFrame(vidObjIn)
got_end = true;
break;
end
vidFrame = readFrame(vidObjIn);
end
if got_end
break;
end
writeFrame(vidObjOut, vidFrame);
end
close(vidObjIn)
close(vidObjOut)
Related Question