Alon Shmiel
Alon Shmiel

Reputation: 7121

matlab display avi in GUI

how can I display an avi file (myVideo.avi) in my gui?

if it helps, I have 11 images that my avi video is composed of them, and what I need is to show these 11 images in an infinity loop (till the figure will be closed).

this is what I tried:

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

this is what I got:

enter image description here

thank you!

@Amro, I tried it and I got error:

Undefined function or method 'VideoReader' for input arguments of type 'char'.

so I tried:

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);

but now I got:

??? 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');

I know there is a solution in this link

but may you know an easy solution? thank you!

Upvotes: 0

Views: 7076

Answers (1)

Amro
Amro

Reputation: 124563

Consider the following example:

%# 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);

screenshot

Upvotes: 2

Related Questions