MATLAB Answers

0

How do I play a video in MATLAB?

Asked by Federico Aliprandi on 28 Oct 2015
Latest activity Commented on by RAVI GIRI on 14 May 2019
Hello,
I need a way to start playing a video in fullscreen, without the user having to deal with the video player UI. I'm trying to do this:
video = 'path\to\my\video.avi';
videoReader = VideoReader(video);
fps = get(videoReader, 'FrameRate');
disp(fps); % the fps is correct: it's the same declared in the video file properties
currAxes = axes;
while hasFrame(videoReader)
vidFrame = readFrame(videoReader);
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
pause(1/videoReader.FrameRate);
end
The problem is that the video does not play at the correct speed: it seems slower and not smooth. Also, I need audio as well. What's the correct way to play a video in MATLAB without exposing the player UI to the user?
Thank you in advance for your help. :)

  0 Comments

Sign in to comment.

3 Answers

Answer by Dinesh Iyer on 28 Oct 2015
 Accepted Answer

MATLAB has no mechanism to play both and video from a video. There have been suggestions about using:
  • MMPLAY which is a user submission
  • Use VLC Player's ActiveX plugin within a MATLAB GUI.
Dinesh

  1 Comment

Thank you for your answer: mmplay works! Do you know if it's possible not to stop the MATLAB program execution while mmplay is playing the video? Thanks again!

Sign in to comment.


Answer by Image Analyst
on 28 Oct 2015

Try this:
implay('rhinos.avi');

  3 Comments

Requires image processing toolbox
If you have Windows, you can use the Windows Media Player:
winopen('rhinos.avi');
Thank you so much!

Sign in to comment.


Answer by Sk Sahariyaz Zaman on 28 Apr 2016

  2 Comments

Thank's for your example code, was very helpfull for me. One question... if you need to aply some image processing tecnique in each frame, which would be the best part of the code to do that?
I have an example for that, attached.

Sign in to comment.