How to Change the Frame Rate of a Video in MATLAB
How to Change the Frame Rate of a Video in MATLAB

In my previous trick I promised you that I would present you a simple way to change the frame rate of a video in MATLAB. But I think if you were intelligent enough you need not to wait for my new code. I have already given you the trick in that discussion. In that code itself, there was a line which defines the new frame rate of a video which is "writerObj.FrameRate = 30;"

So only by redefining the FrameRate property of the object writerObj, we can set the frame rate of the video. So I’m giving the piece of the code again.


% Program Name : MATLAB Video Cutter
% Author : Arindam Bose
% Version : 1.0
% Copyright : ? Arindam Bose, All rights reserved.
% License : Open Source, Freeware
vid = VideoReader('samplevideo.avi');
writerObj = VideoWriter('samplevideo1.avi');
writerObj.FrameRate = 30;// Change the desired frame rate here.
nFrames = vid.NumberOfFrames;
vidHeight = vid.Height;
vidWidth = vid.Width;
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap', []);
for k = 31 : nFramesLeft
mov(k).cdata = read(vid, k);
writeVideo(writerObj, mov(k).cdata);
hf = figure;
set(hf, 'position', [20 150 vidWidth vidHeight]);
movie(hf, mov, 1, vid.FrameRate);

Pretty Easy I think, Try it yourself. More interesting things are coming up.

About the author

Scientific History Blog Writer • Art enthusiast and Illustrator • Amateur Photographer • Biker and Hiker • Beer Enthusiast • Electrical Engineer • Chicago

Leave a Reply

Twitter Feed
%d bloggers like this: