如何在我的gui中显示avi文件(myVideo.avi)?
如果它有帮助,我有11张图像,我的avi视频由它们组成,我需要的是在无限循环中显示这11幅图像(直到图形将被关闭)。
这是我试过的:
function [] = GUI_400()
hFig = figure;
hAxes = axes('Parent',hFig,'Units','pixels','Position',[362 242 424 359]);
movie('myVideo.avi','Parent',hAxes);
set(hAxes,'Visible','on');
end
这就是我得到的:
谢谢你!
@Amro,我试过了,我收到了错误:
Undefined function or method 'VideoReader' for input arguments of type 'char'.
所以我试过了:
obj=mmreader('loading.avi');
a=read(obj);
frames=get(obj,'numberOfFrames');
for k = 1 : frames-1
I(k).cdata = a(:,:,:,k);
I(k).colormap = [];
end
vid = avireader(I);
sz = [vid.Height vid.Width];
mov = read(vid, [1 vid.NumberOfFrames]);
%# prepare GUI
p = get(0,'DefaultFigurePosition');
hFig = figure('Menubar','none', 'Resize','off', ...
'Position',[p(1:2) sz(2) sz(1)]);
%# play movie
movv = struct('cdata',squeeze(num2cell(mov,[1 2 3])), 'colormap',[]);
movie(hFig, movv, 999, vid.FrameRate);
但现在我得到了:
??? Initialization failed. (No combination of intermediate filters could be found to make the connection.)
Error in ==> mmreader.mmreader>mmreader.init at 423
obj.MMReaderImpl = audiovideo.mmreader(fullName);
Error in ==> mmreader.mmreader>mmreader.mmreader at 133
obj.init(fileName);
Error in ==> GUI_400 at 14
obj=mmreader('loading.avi');
我知道this link
中有一个解决方案但你知道一个简单的解决方案吗?谢谢!
答案 0 :(得分:2)
考虑以下示例:
%# read video frames
vid = VideoReader('xylophone.mpg');
sz = [vid.Height vid.Width];
mov = read(vid, [1 vid.NumberOfFrames]);
%# prepare GUI
p = get(0,'DefaultFigurePosition');
hFig = figure('Menubar','none', 'Resize','off', ...
'Position',[p(1:2) sz(2) sz(1)]);
%# play movie
movv = struct('cdata',squeeze(num2cell(mov,[1 2 3])), 'colormap',[]);
movie(hFig, movv, 999, vid.FrameRate);