0

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!

Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
  • What is the problem or error? – bdecaf Jun 04 '12 at 12:28
  • so no error? In my version of Matlab movie doesn't accept string as first parameter. Can you confirm with yours? – bdecaf Jun 04 '12 at 12:39
  • @bdecaf, I don't think there is a problem with the first parameter of the movie, matlab doesn't tell me something about that, but i'm not sure. 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). – Alon Shmiel Jun 04 '12 at 12:49
  • As it looks to me you are on a very old version of Matlab. Can you confirm which version you have? – bdecaf Jun 05 '12 at 10:22
  • I have 2010a, but I gave up this topic. Instead of that, I am trying to show a figure and update the uicontrol of the text (and by this way I will able to update the pictures composing the video. I opened a new topic for that. – Alon Shmiel Jun 05 '12 at 15:15

1 Answers1

2

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

Amro
  • 123,847
  • 25
  • 243
  • 454
  • I will try it, but now I know that you are the best! thank you!! – Alon Shmiel Jun 04 '12 at 18:56
  • @AlonShmiel: I should have mentioned that `VideoReader` was introduced in R2010b. So if you are on an older version, use the similar `mmreader` function or `aviread` for AVI files only (but you seem to have figured that out yourself). As for the error you're getting, its apparently a codec issue. IMO the only way to solve is to install required codecs... I'm on a WinXP 32-bit system so I can't speak for 64-bit issues, but I always like to use [K-Lite Codec Pack](http://www.codecguide.com/) on any Windows machine I work with – Amro Jun 05 '12 at 00:09
  • thank you but I want something that will work in all the windows versions so I gave up this topic. Instead of that, I am trying to show a figure and update the uicontrol of the text (and by this way I will able to update the pictures composing the video. I opened a new topic for that. thank you very much for your help!! – Alon Shmiel Jun 05 '12 at 15:16