How can I embed a video into a GUI?

4 views (last 30 days)
Joe Bennett
Joe Bennett on 16 Oct 2013
Edited: Sean de Wolski on 16 Oct 2013
Hi, I am writing a video processing app and need to be able to display a pre-recorded video (not stream from webcam) on the GUI. If I use 'implay' it works but displays it in a pop up figure. It needs to be within an axis. I have found this question asked a few times but never answered.

Answers (1)

Sean de Wolski
Sean de Wolski on 16 Oct 2013
Edited: Sean de Wolski on 16 Oct 2013
I don't have time to make an example now, but here's how I would approach this:
You will need an axes with an image on it.
hAx = axes;
hIm = imshow(pi,'parent',hAx);
Now use a timer to control it:
doc timer
T = timer('Period',1,... %period
'ExecutionMode','fixedRate',... %{singleShot,fixedRate,fixedSpacing,fixedDelay}
'BusyMode','drop',... %{drop, error, queue}
'TasksToExecute',inf,...
'StartDelay',0,...
'TimerFcn',@(src,evt)foo,...
'StartFcn',[],...
'StopFcn',[],...
'ErrorFcn',[]);
%start(T);
You can set the timer's period, TasksToExecute etc. from properties of the movie (number of frames) or from other user interface controls in the figure, e.g. frame rate selection.
The TimerFcn will have to update the image's 'CData' to reflect the current frame:
set(hIm,'CData',movie_frame(ii))
Now how do you get ii? The event data will contain properties of the function call to the timerfcn such as TasksExecuted which could be used here as an index.
The rest is adding features etc.
I guess I had a (very) minimal working example here: (See Part 2)
Though I was just throwing away the timer event information rather than using it.
And here's a slightly less minimal working example. Though it's doing different task, the infrastructure should be similar to what you actually need:

Categories

Find more on Startup and Shutdown 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!