1. 程式人生 > >[轉載]matlab視頻讀取函數VideoReader

[轉載]matlab視頻讀取函數VideoReader

win bits efault 使用 結構體 () lan its http

看到以前matlab中讀取視頻多

使用mmreader等(參考《matlab讀取/播放視頻的函數》),而現在matlab有一個專門的視頻讀取類VideoReader完成視頻讀取的功能。 相關博文:《matlab寫入/合成視頻VideoWriter類 》
0。 一個讀取視頻,顯示幀,並保存每一幀 的代碼 fileName = ‘MVI_1264_clip.avi‘; obj = VideoReader(fileName); numFrames = obj.NumberOfFrames;% 幀的總數 for k = 1 : numFrames% 讀取數據 frame = read(obj,k); imshow(frame);%顯示幀 imwrite(frame,strcat(num2str(k),‘.jpg‘),‘jpg‘);% 保存幀 end 下面具體介紹VideoReader類的函數。

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 - 讀取視頻幀 調用格式: 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幀之後的幀

[轉載]matlab視頻讀取函數VideoReader