[matlab]matlab读取视频VideoReader类

xiaoxiao2021-02-28  98

1。VideoReader - 该函数用于读取视频文件对象。 函数调用格式: obj = VideoReader(filename) obj = VideoReader(filename,Name,Value)  其中obj为结构体,包括如下成员: Name - 视频文件名 Path - 视频文件路径 Duration - 视频的总时长(秒) FrameRate -  视频帧速(帧/秒) NumberOfFrames -  视频的总帧数 Height -  视频帧的高度 Width -  视频帧的宽度 BitsPerPixel -  视频帧每个像素的数据长度(比特) VideoFormat - 视频的类型, 如 'RGB24'. Tag -  视频对象的标识符,默认为空字符串 '' Type -  视频对象的类名,默认为'VideoReader'. UserData -  Generic field for data of any class that you want to add to the object.   Default: [] 如,视频的总帧数为 numFrames = obj.NumberOfFrames; 在不同的系统平台下,可以读取的视频文件类型如下: 所有系统平台: AVI (.avi),  Motion JPEG 2000 (.mj2) 所有Windows系统: MPEG-1 (.mpg),  Windows Media Video (.wmv, .asf, .asx), 和任何 Microsoft DirectShow?支持的类型。 Windows 7系统: MPEG-4, 包括 H.264 编码视频 (.mp4, .m4v),  Apple QuickTime Movie (.mov),  和任何Microsoft Media Foundation支持的类型。 Macintosh系统: MPEG-1 (.mpg),  MPEG-4,  包括 H.264 编码视频  (.mp4, .m4v),  Apple QuickTime Movie (.mov), 和任何在http://support.apple.com/kb/HT3775中列出的 QuickTime支持的类型。 Linux系统: Any format supported by your installed plug-ins for GStreamer 0.10 or above, as listed on http://gstreamer.freedesktop.org/documentation/plugins.html, including Ogg Theora (.ogg). 2 该类其他成员函数: get - 获取视频对象的参数 参数的名字为上述obj对象的所有成员。 调用格式: Value = get(obj,Name) Values = get(obj,{Name1,...,NameN}) allValues = get(obj) get(obj) 如: xyloObj = VideoReader('xylophone.mpg'); xyloSize = get(xyloObj, {'Height', 'Width', 'NumberOfFrames'}) set - 设置视频对象的参数,与get对应 调用格式: set(obj,Name,Value) set(obj,cellOfNames,cellOfValues) set(obj,structOfProperties) settableProperties = set(obj)  如: newValues.Tag = 'My Tag'; newValues.UserData = {'My User Data', pi, [1 2 3 4]}; xyloObj = VideoReader('xylophone.mpg'); set(xyloObj, newValues) set(xyloObj, 'Tag', 'This is my tag.'); getFileFormats - 获取在该系统平台下,VideoReader可以支持读取的视频类型。 调用格式: formats = VideoReader.getFileFormats() isPlatformSupported - 检测在当前系统平台下VideoReader是否可用 调用格式: supported = VideoReader.isPlatformSupported() read - 读取视频帧, 注意:matlab提示:VideoReader.read is not recommended. Use VideoReader.readFrame instead. 调用格式: video = read(obj),获取该视频对象的所有帧 video = read(obj,index),获取该视频对象的制定帧 如: video = read(obj, 1);         % first frame only 获取第一帧 video = read(obj, [1 10]);    % first 10 frames 获取前10帧 video = read(obj, Inf);       % last frame only 获取最后一帧

video = read(obj, [50 Inf]);  % frame 50 thru end 获取第50帧之后的帧

v=VideoReader('1.avi');

v.CurrentTime=1.5;

fr=readFrame(v);

即readFrame通过设置CurrentTime来读取指定的时间节点的图像,

也可以通过设置

v.CurrentTime=(1/v.FrameRate)*numframe; 

来读取指定帧数的视频,但由于FrameRate一般是小数,故除不尽,可能存在误差,

因此以后读取帧数还是用read来

说明:在一开始使用VideoReader读取视频时,matlab报错:

错误使用 VideoReader/init (line 619) 无法确定所需的编解码器。 出错 VideoReader (line 172)             obj.init(fileName);

然后下载了完美转码者,将原视频进行转码,报错消失。

转载请注明原文地址: https://www.6miu.com/read-71879.html

最新回复(0)