How do I play a video in MATLAB?

122 ビュー (過去 30 日間)
Federico Aliprandi
Federico Aliprandi 2015 年 10 月 28 日
コメント済み: Khaled Abdellatif 2020 年 3 月 25 日
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. :)

採用された回答

Dinesh Iyer
Dinesh Iyer 2015 年 10 月 28 日
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
  2 件のコメント
Federico Aliprandi
Federico Aliprandi 2015 年 11 月 2 日
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!
Khaled Abdellatif
Khaled Abdellatif 2020 年 3 月 25 日
can one use mmplay not for fullscreen? it does not work without fullscreen option

サインインしてコメントする。

その他の回答 (3 件)

Image Analyst
Image Analyst 2015 年 10 月 28 日
Try this:
implay('rhinos.avi');
  3 件のコメント
Image Analyst
Image Analyst 2016 年 4 月 28 日
If you have Windows, you can use the Windows Media Player:
winopen('rhinos.avi');
RAVI GIRI
RAVI GIRI 2019 年 5 月 14 日
Thank you so much!

サインインしてコメントする。


Sk Sahariyaz Zaman
Sk Sahariyaz Zaman 2016 年 4 月 28 日
  2 件のコメント
sebas
sebas 2018 年 5 月 5 日
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
Image Analyst 2018 年 5 月 5 日
I have an example for that, attached.

サインインしてコメントする。


Simon Weber
Simon Weber 2019 年 9 月 16 日
There's an easy way to play videos with sound using the Psychtoolbox.
Check out:
For the quickest way possible just type
SimpleMovieDemo(filename)

Community Treasure Hunt

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

Start Hunting!

Translated by