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?

22 views (last 30 days)
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.

Accepted Answer

Nitin Kapgate
Nitin Kapgate on 13 Aug 2020
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
while hasFrame(reader) % while frames are remaining
img = readFrame(reader); % read a frame
writeVideo(writer,img); % write a frame to the output file
% close the files
Andrew Keefe
Andrew Keefe on 5 Mar 2021
Muhammad, did this work for you? When I try to make a 240 fps video after importing from a gopro I get an error that my framesize is too large for the framerate. My frame size is 960 x 1280 which doesn't seem that large to me.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by