How to use real time for writeVideo
8 views (last 30 days)
Show older comments
I am using following code to track a point in 3d with respect to time.
h=animatedline('Marker', 'o');
vidObj=VideoWriter('abc.avi');
open(vidObj);
for i=1:length(t) % t is time as an vector defined by user with, let's say, 1/10000 sec as time interval
addpoints(h, x, y, z) % x,y,z are of same length as of t
view(45, 45)
frame=getframe(gcf);
writeVideo(vidObj, frame);
drawnow
end
close(vidObj)
The program is running alright but the video generated in slow as compared to the time t which was defined already. for example the total video time is 0.16 sec whereas the actual time was only 0.05 sec. I want the video time to be 0.05 with real time speed.
Kindly help.
0 Comments
Answers (1)
Rahul
on 24 Jan 2025
I understand that while trying to track 3d points and create a video object while doing so, the speed with which the video gets created would not be as expected in a real time simulation video.
The following MATLAB Answers mention that adjusting the 'FrameRate' property of the 'VideoWriter' object would ensure that each frame in the video corresponds to the same time interval as your data.
Here is an example, how you can adjust the code:
desiredFrameRate = 1 / length(t)
% Set the frame rate for the video
vidObj.FrameRate = desiredFrameRate;
Refer to the following MathWorks documentation to know more:
Thanks.
0 Comments
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!