How can I plot on top of a video, and then save the new video with the plots?
33 views (last 30 days)
Show older comments
MathWorks Support Team
on 23 Dec 2015
Edited: MathWorks Support Team
on 13 Apr 2023
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
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'))
0 Comments
More Answers (0)
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!