How can I plot on top of a video, and then save the new video with the plots?

27 views (last 30 days)
I would like to read in a video file (MP4), plot some points and lines on top of every frame, and then save this to a new video file with the plotted points and lines in place. The plotted points would change position based on calculations done in every frame. How can I accomplish this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Apr 2023
Edited: MathWorks Support Team on 13 Apr 2023
In short, this can be done with the following steps:
1) Create a
object for the input video file.
2) Create a VideoWriter object for the output video file, and open it for editing.
2) Loop through the video, using readFrame to get each video frame, and displaying it to an axes.
3) Plot the desired points and lines on top of the image.
4) Capture the current axes appearance with the getframe function.
5) Save each of the new frames to the VideoWriter object with the writeVideo function.
6) When finished, close the output video file.
Please see the attached file for an example of one way that this can be accomplished.
For MATLAB R2017b documentation on the same, please use the following command:
>> web(fullfile(docroot, 'matlab/ref/videowriter.html'))
>> web(fullfile(docroot, 'matlab/ref/videoreader.html'))

More Answers (0)

Products


Release

No release entered yet.

Community Treasure Hunt

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

Start Hunting!