how to extract frames from video using video reader efficiently
    4 views (last 30 days)
  
       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
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!