Combine a video with animations of three subplots

27 vues (au cours des 30 derniers jours)
Youngmin
Youngmin le 15 Oct 2021
Modifié(e) : Youngmin le 17 Oct 2021
Hello, I am trying to make a video file by combining a video with animations of three subplots. The subplots are position, velocity, and acceleration graphs of the video. However, I am struggling with two things: the size of the video in figure and saving the video with animations. I tried to create 3X2 subplots by putting the video on the left hand side and three graphs on the right hand side. But, I am not sure how to change the size of the video to the same height of sum of all three graphs.
Also, when I try to save the video, I kept having this warning and the video was not saved:
% Warning: No video frames were written to this file. The file may be invalid.
Video and data have the same frame numbers and frame rates. I have attached the script and the csv file of the data that I want to create the plots next to the video.
data = readtable('pva.csv');
inputVid=VideoReader('VJ.mov');
mergedobj = VideoWriter('compositevid','Motion JPEG AVI');
mergedobj.FrameRate = inputVid.FrameRate;
mergedobj.Quality=100;
open(mergedobj);
hfig = figure;
t = 0:(1/60):(162/60);
i = 1;
while hasFrame(inputVid)
singleFrame = readFrame(inputVid);
subplot(3,2,1),imagesc(singleFrame), axis off, axis equal;
subplot(3,2,2);
plot(t(i),data.Position(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Position(1:i),'-k');
axis([0 t(end) 0 max(data.Position)+0.2])
subplot(3,2,4);
plot(t(i),data.Velocity(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Velocity(1:i),'-k');
axis([0 t(end) -3 3])
subplot(3,2,6);
plot(t(i),data.Accleration(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Accleration(1:i),'-k');
axis([0 t(end) -18 18])
pause(0.1)
if i ~= length(t)
clf
i= i+1;
else
close(mergedobj)
end
end

Réponses (1)

kunal gokhe
kunal gokhe le 15 Oct 2021
Try this code below
data = readtable('pva.csv');
inputVid=VideoReader('VJ.mov');
mergedobj = VideoWriter('compositevid','Motion JPEG AVI');
mergedobj.FrameRate = inputVid.FrameRate; %match same framerate
mergedobj.Quality=100;
open(mergedobj);
%start the stitch
hfig = figure;
t = 0:(1/60):(162/60);
%while loop until there are no more frames
i = 1;
while hasFrame(inputVid)
%read in frame
singleFrame = readFrame(inputVid);
% display frame
subplot(3,2,[1 3 5]),imagesc(singleFrame), axis off, axis equal;
%my gen of dummy data or whatever you want to do
subplot(3,2,2);
plot(t(i),data.Position(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Position(1:i),'-k');
axis([0 t(end) 0 max(data.Position)+0.2])
subplot(3,2,4);
plot(t(i),data.Velocity(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Velocity(1:i),'-k');
axis([0 t(end) -3 3])
subplot(3,2,6);
plot(t(i),data.Accleration(i),'o','MarkerFaceColor','red');
hold on;
plot(t(1:i),data.Accleration(1:i),'-k');
axis([0 t(end) -18 18])
pause(0.1)
if i ~= length(t)
clf
i= i+1;
else
close(mergedobj)
end
end
  1 commentaire
Youngmin
Youngmin le 17 Oct 2021
Thank you for your answer. The video was expanded on the left-hand side with the same height of three graphs. However, I still have the same warning and the video cannot be saved.
% Warning: No video frames were written to this file. The file may be invalid.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by