How to match camera framerate in matlab?
5 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I tooke a 2.5sec video at 250fps with a camera. However, MATLAB gives me 9.6sec video at 50fps.
The expected number of frames is 625 but I am getting 480 with MATLAB.
How do I match or reconcile these two data?
Tahnk you
0 件のコメント
回答 (1 件)
Maneet Kaur Bagga
2024 年 5 月 9 日
Hi,
As per my understanding you want to match the original camera frame rate and duration in MATLAB, one of the possible workaround for this involves manually setting the frame rate and processing the video frame by frame.
Please refer to the example below using MATLAB's "VideoReader" and "VideoWriter" classes:
Create a "VideoReader" object and read the metadata to detect the correct frame rate.
% Create a VideoReader object to read the video file
v = VideoReader('your_video_file.mp4');
% Display original video file frame rate
disp(['Original File Frame Rate: ', num2str(v.FrameRate)]);
Given the original video is expected to have been recorded at 250 fps, process the video frame-by-frame and write it to a new file with the given frame rate using "VideoWriter":
% Create a VideoWriter object to write the video with the correct frame rate
outputVideo = VideoWriter('corrected_video.mp4', 'MPEG-4');
outputVideo.FrameRate = 250; % Set the correct frame rate
open(outputVideo);
while hasFrame(v)
frame = readFrame(v);
writeVideo(outputVideo, frame);
end
close(outputVideo);
% Create a VideoReader object for the corrected video
correctedVideo = VideoReader('corrected_video.mp4');
% Calculate the expected duration and frame count
expectedDuration = 2.5; % seconds
expectedFrameCount = expectedDuration * outputVideo.FrameRate;
% Display the results
disp(['Corrected Video Frame Rate: ', num2str(correctedVideo.FrameRate)]);
disp(['Corrected Video Duration: ', num2str(correctedVideo.Duration)]);
disp(['Expected Frame Count: ', num2str(expectedFrameCount)]);
disp(['Actual Frame Count: ', num2str(correctedVideo.Duration * correctedVideo.FrameRate)]);
Please refer to the MathWorks Documentation for further understanding:
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!