Play multiple videos in one subplot
Show older comments
Hi,
I'm trying to play multiple avi videos in one subplot, and borrowed online code but always showing me the following error:
Error using VideoReader/read (line 134)
Cannot call READ method after using READFRAME or HASFRAME methods or setting the CURRENTTIME property. Recreate the object to read a frame at a
specific frame index.
Error in videoplay (line 18)
v1frame = v1.read(i1);
And here is the code:
clc;clear all;
v1= VideoReader('\\cab-fs07.mae.virginia.edu\NewData\NHTSA\2016-AutomatedVehicle\1Simulation\Project\RESULTV3.5\M50-OS_Standard_Reclined_0_Int_0_RMDB\1_cut.avi');
v1.CurrentTime = 1.5;
v1_numFrames = ceil(v1.FrameRate*v1.Duration);
v2= VideoReader('\\cab-fs07.mae.virginia.edu\NewData\NHTSA\2016-AutomatedVehicle\1Simulation\Project\RESULTV3.5\M50-OS_Standard_Reclined_0_Int_0_RMDB\2_top.avi');
v2.CurrentTime = 1.5;
v2_numFrames = ceil(v2.FrameRate*v2.Duration);
i1 = 0;
i2 = 0;
fig = gcf;
ax1 = subplot(2,2,1, 'Parent', fig);
ax2 = subplot(2,2,2, 'Parent', fig);
currAxes = axes;
while i1 < v1_numFrames && i2 < v2_numFrames
if i1 < v1_numFrames
i1 = i1+1;
v1frame = v1.read(i1);
if isempty(v1frame) %unexpected!
warning(sprintf('skipped v1 empty frame #%d', i1));
elseif ishandle(ax1)
image(v1frame, 'Parent', ax1);
else
break; %axes is gone, figure is probably gone too
end
end
if i2 < v2_numFrames
i2 = i2+1;
v2frame = v2.read(i2);
if isempty(v2frame) %unexpected!
warning(sprintf('skipped v2 empty frame #%d', i2));
elseif ishandle(ax2)
image(v2frame, 'Parent', ax2);
end
end
drawnow
end
Thanks
Accepted Answer
More Answers (1)
Hongnan Lin
on 10 Jan 2018
Edited: Walter Roberson
on 10 Jan 2018
1 Comment
Walter Roberson
on 10 Jan 2018
Edited: Walter Roberson
on 10 Jan 2018
axis(ax1, 'off');
and
axis(ax2, 'off');
and
axis(ax3, 'off')
Note: it is more efficient to update the CData property of an existing image than to image() and axis()
Categories
Find more on Convert Image Type 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!