Does Matlab have functionality to make a video of a moving graph and merge it with another video?

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Joseph Cheng
Joseph Cheng il 24 Mar 2016
Modificato: Joseph Cheng il 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
open(vobj);
figure(1)
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
writeVideo(vobj, frame);
end
%close the object so its no longer tied up by matlab
close(vobj);
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
mergedobj.Quality=100;
open(mergedobj);
%start the stitch
hfig = figure;
k = 1; %use for my dummy data
%while loop until there are no more frames
while hasFrame(inputVid)
%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
subplot(1,2,2),plot(k,mean(singleFrame(:)),'.'),hold on;
title('Average pixel data');
%grab what the figure looks like
frame = getframe(hfig);
%write to file.
writeVideo(mergedobj, frame);
%increment k for my dummy data.
k = k+1;
end
%close the object
close(mergedobj)
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)
  2 Commenti
Matthew Hall
Matthew Hall il 25 Mar 2016
Wow. Thanks. That helps a ton. It looks like I'm going to have to pick up a home edition of MATLAB. I think it will be a great edition to my hobby and likely lead to some other cool projects.
Michael Cottingham
Michael Cottingham il 21 Gen 2021
Modificato: Michael Cottingham il 21 Gen 2021
Joseph, I used the general layout of this code for a slightly different application. But, I am having issues syncing the data properly with the video. The main issue is the 2 data matrices are 50x larger than the number of frames in the video. Do you know how to make the plot 50 points of data per frame of the video?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by