How can I get accurate timestamps for frames acquired while writing to disk?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 3 Feb 2021
Answered: MathWorks Support Team
on 19 Feb 2021
I am trying to write multiple minutes worth of frames to disk while also getting accurate timestamps for each frame. Right now I am getting the timestamps from the FramesAcquiredFcn callback for every frame and storing them in a global variable. After all of the frames have been logged to disk, the number of timestamps do not match the number of frames acquired or the number of frames in the video file. How can I get the correct number of timestamps that are still accurate?
Accepted Answer
MathWorks Support Team
on 3 Feb 2021
When using the FramesAcquiredFcn callback to get the timestamps for each frame, they may not be accurate. Using something like "datetime('now')" will record the time when the callback event is executed, not when the frame is acquired. To get both accurate timestamps and frames logged to disk, you can set the LoggingMode to "disk&memory":
v = videoinput(adaptorname);
v.LoggingMode = 'disk&memory';
Then, the memory logging part can be used in conjunction with "getdata" to retrieve the timestamps in the callback. The timestamps can be stored and accessed using the UserData property.
function framesAcquiredCallback(obj, event)
[~, ts] = getdata(obj);
obj.UserData = [obj.UserData ts];
end
And to retrieve the timestamps in the main script/function:
timestamps = v.UserData;
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!