I am doing a GUI to display 2 video. First video is recorded video, second is the image sequence and need to display at 25 fps. The problem now is i am unable to play 2 video at the same time, just the 1st video played when the button is press. I need to play the 2 video when a button is press. Below is the error after i close the GUI window. Hope someone can help to check where is the error. Thanks.
Error using hgsetdisp (line 8)
Invalid or deleted object.
Error in guitest>pushbutton1_Callback (line 101)
set(hf2)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in guitest (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)guitest('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating DestroyedObject Callback
Below is My Coding:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Obj = VideoReader('ken-test2_mpeg4.mp4');
vidFrames = read(Obj);
vidFrames=imrotate(vidFrames,-90);
numFrames = get(Obj, 'numberOfFrames');
for k = 1 : numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
end
hf = handles.axes1;
set(hf)
movie(hf, mov, 1, Obj.FrameRate);
Output=evalin('base','imgsequence');
[~,~,~,numFrames2]=size(Output);
for l = 1 : numFrames2
mov2(l).cdata = Output(:,:,:,l);
mov2(l).colormap = [];
end
hf2 = handles.axes2;
set(hf2)
movie(hf2, mov2, 1, 25);

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 5월 25일

2 개 추천

Su - I don't think that you will be able to play two videos concurrently using the movie function. I suspect that it blocks so that once it is called with
movie(hf, mov, 1, Obj.FrameRate);
the subsequent line of code won't fire until this first video completes playback.
As for the error message, it is unclear what may be invalid with handles.axes2. Has this been defined correctly? Does this axes exist within your GUI?
I think what you might want to do is to not use the movie function and display the frames yourself. See http://www.mathworks.com/matlabcentral/answers/216698-how-to-play-my-video-while-my-graph-animates for an example on how you may do this.
If the frame rate for both videos is identical, then you can use one for loop to display each frame for each video (of course, you would have to handle the case where one video is longer (has more frames) than the other).
If the frame rate for each video is different, then your code will have to become smarter. The easiest (?) thing to do maybe to create two timers whose rate is the inverse frame rate for each video. When each timer fires (at different rates) it will display the subsequent frame of the video. So you will need to keep track of the last frame displayed for each video.

댓글 수: 1

Su Wing Lee
Su Wing Lee 2016년 5월 27일
Hi Geoff, thanks for the solution provides, now i am know that playing 2 video concurrently is not possible. I am able to display the image sequence using imshow and the video is playing at the same time. Thanks for that. Have a nice day.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

질문:

2016년 5월 23일

댓글:

2016년 5월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by