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?
21 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Nitin Kapgate
2020-8-13
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);
2 个评论
Andrew Keefe
2021-3-5
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!