我正在尝试创建 Matlab GUI ,在其一侧播放视频,另一侧播放按钮。单击按钮,只需获取视频的播放时间并将其存储在文件中。有没有办法在指定的轴上播放视频?我正在使用以下代码但没有得到回复。
xyloObj = VideoReader('xylophone.mp4');
vidWidth = xyloObj.Width;
vidHeight = xyloObj.Height;
mov = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
k = 1;
while hasFrame(xyloObj)
mov(k).cdata = readFrame(xyloObj);
k = k+1;
end
hf = figure;
set(hf,'position',[150 150 vidWidth vidHeight]);
movie(hf,mov,1,xyloObj.FrameRate);
答案 0 :(得分:0)
以下代码对您有所帮助。尝试一下,如果您有任何问题或任何与该代码相关的查询,请问我
xyloObj = VideoReader('xylophone.mpg');
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
% Preallocate movie structure.
mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
'colormap', []);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k);
end
h = figure ; hf = axes('Parent' , h);
% Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);