clc;
close all;
% Open an sample avi file
[FileName,PathName] = uigetfile('*.AVI','Select the Video');
file = fullfile(PathName,FileName);
%filename = '.\003.AVI';
mov = MMREADER(file);
% Output folder
outputFolder = fullfile(cd, 'frames');
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
%getting no of frames
numberOfFrames = mov.NumberOfFrames;
numberOfFramesWritten = 0;
for frame = 1 : numberOfFrames
thisFrame = read(mov, frame);
outputBaseFileName = sprintf('%3.3d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite(thisFrame, outputFullFileName, 'png');
progressIndication = sprintf('Wrote frame %4d of %d.', frame,numberOfFrames);
disp(progressIndication);
numberOfFramesWritten = numberOfFramesWritten + 1;
end
progressIndication = sprintf('Wrote %d frames to folder "%s"',numberOfFramesWritten,outputFolder);
disp(progressIndication);
但是,我在运行此代码时遇到以下错误:
??? Error using ==> extract at 10
The file requires the following codec(s) to be installed on your system:
Unknown Codec
有人可以帮我解决这个错误吗?感谢。
答案 0 :(得分:1)
该文件似乎是用未知的视频编解码器编码的(可能是MatLab未知)。文件扩展名(.avi,.mpeg等)不表示编解码器,而是一个容器,如果我没有误会。
底部的链接提供了MatLab支持的文件格式的一些信息。您应该尝试检索视频文件使用的容器和编解码器,并查看MatLab是否支持它。检索编解码器的方法是在VLC媒体播放器中打开它(通过VideoLan)右击电影,extra->编解码器信息,或者如果您在Windows上只需在VLC中打开电影并按CTRL + J.
一些有用的链接: http://www.mathworks.nl/help/matlab/ref/mmreader-class.html http://www.mathworks.nl/help/matlab/import_export/supported-video-file-formats.html
亲切的问候,
Ernst Jan
答案 1 :(得分:1)
我使用以下代码行代替MMREADER
:
movieInfo = aviinfo(movieFullFileName);
mov = aviread(movieFullFileName);
% movie(mov);
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;
有效。