MATLAB: I am making a video at 240 FPS for 1 min but whenever I trim that video for 5 seconds that 5 second of video have 30 FPS. wondering why frame rate reduces

digital image processingframe rateimage analysisimage processingvideo processing

Hi,
Is there a way in matlab to trim a clip from a video with the same frame rate. Currently, I am trimming a video and Frame/second reduces to 30 from 240.
Thank you in advance for the reply.

Best Answer

The key to the solution of your problem is the “FrameRate” property of the “VideoWriter” object. If unspecified, the “FrameRate” property defaults to a value of 30 FPS. Hence the video output in your case is at 30 FPS. To change the output frame rate to 240 FPS, you need to explicitly set the “FrameRate” property to 240 FPS. The following code snippet can help you to solve your problem.
% Read the input video file
reader = VideoReader("inputVideo.avi"); % Assuming the name of Input video file is "inputVideo.avi".
% Create a VideoWriter object for the output file
writer = VideoWriter('outputVideo.avi'); % Assuming the name of Input video file is "outputVideo.avi".
% If the value of frame rate is unspecified, the FrameRate property is by default set to 30 FPS
% To Set the desired frame rate, explicitly specify the FrameRate property of the VideoWriter object.
writer.FrameRate = 240; % 240 FPS
% Open the file for writing
open(writer);
while hasFrame(reader) % while frames are remaining
img = readFrame(reader); % read a frame
writeVideo(writer,img); % write a frame to the output file
end
% close the files
close(writer);
close(reader);
Related Question