How do I play a video in MATLAB?
Show older comments
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. :)
Accepted Answer
More Answers (3)
Image Analyst
on 28 Oct 2015
Try this:
implay('rhinos.avi');
3 Comments
K E
on 3 Mar 2016
Requires image processing toolbox
Image Analyst
on 28 Apr 2016
If you have Windows, you can use the Windows Media Player:
winopen('rhinos.avi');
RAVI GIRI
on 14 May 2019
Thank you so much!
Sk Sahariyaz Zaman
on 28 Apr 2016
0 votes
2 Comments
sebas
on 5 May 2018
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?
Image Analyst
on 5 May 2018
I have an example for that, attached.
Simon Weber
on 16 Sep 2019
There's an easy way to play videos with sound using the Psychtoolbox.
Check out:
For the quickest way possible just type
SimpleMovieDemo(filename)
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!