hasFrame
确定是否有视频帧可供读取
说明
示例
创建 VideoReader
对象并读取视频
为示例视频文件 xylophone_video.mp4
创建一个 VideoReader
对象。
v = VideoReader("xylophone_video.mp4");
读取视频中的所有帧,一次一帧。
while hasFrame(v) frame = readFrame(v); end
显示 readFrame
返回的最后一帧的有关信息。
whos frame
Name Size Bytes Class Attributes frame 240x320x3 230400 uint8
清除 VideoReader
对象。
clear v
读取并播放影片文件
为示例视频文件 xylophone_video.mp4
创建一个 VideoReader
对象。然后,确定视频的宽度和高度。
xyloObj = VideoReader("xylophone_video.mp4");
vidWidth = xyloObj.Width;
vidHeight = xyloObj.Height;
创建一个视频结构体数组。
mov = struct("cdata",zeros(vidHeight,vidWidth,3,"uint8"),colormap=[]);
一次读取一帧,直到视频结束。
k = 1; while hasFrame(xyloObj) mov(k).cdata = readFrame(xyloObj); k = k+1; end
基于视频的宽度和高度调整图窗大小,然后播放一次视频。
vf = figure(Position=[0 0 xyloObj.Width xyloObj.Height]);
imshow(mov(1).cdata,Border="tight")
movie(vf,mov,1,xyloObj.FrameRate)
清除 VideoReader
对象。
clear xyloObj
输入参数
v
— 输入 VideoReader
对象
VideoReader
对象
输入 VideoReader
对象。使用 VideoReader
函数根据您的视频文件创建一个 VideoReader
对象。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
版本历史记录
在 R2014b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)