以前讀取avi檔案, 如果用內建aviread指令常常會發生無法讀取的窘境,

後來File Exchange有提供mmread指令, 可以避免這個狀況

網路上也有一些獨門秘計可以讓MATLAB可以讀影片, 例如透過ffmpeg轉檔等方法…

不過今天要講的是, 從MATLAB 2012 開始, Mathworks提供videoreader給使用者來讀取每個影格資訊,

image

BitsPerPixel    Bits per pixel of the video data.

Duration        Total length of the file in seconds.

VideoFormat     String indicating the MATLAB representation of the video format, such as 'RGB24'.

FrameRate       Frame rate of the video in frames per second.

Height          Height of the video frame in pixels.

Width           Width of the video frame in pixels.

Name            Name of the file associated with the object.

NumberOfFrames  Total number of frames in the video stream.

 

值得注意的是有些影片的frame rate是變動的, 因此讀取這類的影片時會跳出frame rate警告訊息

 

語法:

video = read(obj);           % 讀取全部影格, 我不建議這麼做, 因為一般影片很大, 這麼做只會得到out of memory的錯誤提示!

video = read(obj, N);      % 讀第N張影格

video = read(obj, [m n]); % 讀第m~n張影格

如果想要在MATLAB播放影片順暢, 建議可以用page方式讀取,

以我的筆電為例, 一個page讀取5~20張左右, 當播放完在讀取下一個page一直讀到結束為止, 播放起來的速度勉強流暢

arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()