Does Matlab have functionality to make a video of a moving graph and merge it with another video?
11 views (last 30 days)
I have been doing some Google searches looking for a video tool that will allow me to add moving graphs to video. I came across some questions in this forum that alluded that Matlab might possibly do what I’m looking for. I fly remote control helicopters as a hobby and one of the tools that I used to improve and learn from is flight telemetry. During a flight I can record a lot of different data points like amperage draw, speed, altitude, GPS location, inputs from the controls, and may other data points in .1 second intervals. The problem is I can’t watch this data coming in while I’m flying the helicopter. What I would like to do is record a video of the flight then impose synchronized moving graphs from the telemetry data. Is this something that Matlab could do? If not could it at least make videos of the moving graphs? I could then find some other video editing software to put the two together.
Joseph Cheng on 24 Mar 2016
Edited: Joseph Cheng on 24 Mar 2016
sure. here is a very quick example. my stitch is ugly but gets you where you want to go:
%%lets start by gen dummy video
vobj = VideoWriter('dummyvid','Motion JPEG AVI');
vobj.FrameRate = 24; %just to be cinematic
vobj.Quality=100; %no compression
for ind = 1:100
imagesc(mod(repmat(1:512,512,1),mod(ind,512))),colormap gray, axis off, axis equal;
frame = getframe(1); %get image of whats displayed in the figure
%close the object so its no longer tied up by matlab
close(gcf) %close figure since we don't need it anymore
%%open the drone vid
inputVid = VideoReader('dummyvid.avi');
%calculate total number of frames, mostly to show you what data is
%available in the object.
TotnumFrames = round(inputVid.FrameRate*inputVid.Duration);
%%now add stats to it.
%initiate new composite video file
mergedobj = VideoWriter('compositevid','Motion JPEG AVI');
mergedobj.FrameRate = inputVid.FrameRate; %match same framerate
%start the stitch
hfig = figure;
k = 1; %use for my dummy data
%while loop until there are no more frames
%read in frame
singleFrame = readFrame(inputVid);
% display frame
subplot(1,2,1),imagesc(singleFrame), axis off, axis equal;
%my gen of dummy data or whatever you want to do
title('Average pixel data');
%grab what the figure looks like
frame = getframe(hfig);
%write to file.
%increment k for my dummy data.
k = k+1;
%close the object
now you can play around with axes and figure handle properties, uicontrols etc. to add in text, more plots, etc on how you want it to look. first off i'd suggest modifying the position (ie size and location of the input vid) to be larger, and equal (making sure you have square pixels)