hasFrame
确定是否有视频帧可供读取
说明
示例
创建 VideoReader 对象并读取视频
为示例影片文件 xylophone.mp4
创建一个VideoReader
对象。
v = VideoReader('xylophone.mp4');
读取视频中的所有帧,一次一帧。
while hasFrame(v) frame = readFrame(v); end
显示 readFrame
返回的最后一帧的有关信息。
whos frame
Name Size Bytes Class Attributes frame 240x320x3 230400 uint8
读取并播放影片文件
读取并播放示例影片文件 xylophone.mp4
。
创建 VideoReader
对象以从示例文件读取数据。然后,确定视频的宽度和高度。
xyloObj = VideoReader('xylophone.mp4');
vidWidth = xyloObj.Width;
vidHeight = xyloObj.Height;
创建影片结构体数组 mov
。
mov = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),... 'colormap',[]);
一次读取一帧,直到视频结束。
k = 1; while hasFrame(xyloObj) mov(k).cdata = readFrame(xyloObj); k = k+1; end
基于视频的宽度和高度确定图窗大小。然后,按照视频的帧速率播放一次影片。
hf = figure;
set(hf,'position',[150 150 vidWidth vidHeight]);
movie(hf,mov,1,xyloObj.FrameRate);
输入参数
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)