在Matlab中从视频中提取帧

3

我试图使用以下代码行从一个小视频中提取帧:

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

有人能帮我解决这个错误吗?谢谢。


mmreader 已经过时了,你是否尝试使用 VideoReader - Amro
2个回答

1

我没有使用MMREADER,而是使用以下代码:

movieInfo = aviinfo(movieFullFileName);
mov = aviread(movieFullFileName);
% movie(mov);
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;

它起作用了。


1
文件似乎是使用未知的视频编解码器进行编码的(MatLab可能不支持)。文件扩展名(.avi、.mpeg等)不表示编解码器,而是容器(如果我没有弄错的话)。
底部的链接提供了一些有关MatLab支持的文件格式的信息。您应该尝试获取您的视频文件使用的容器和编解码器,并查看MatLab是否支持它。检索编解码器的一种方法是在VLC媒体播放器中打开它(通过VideoLan),右键单击电影,选择“额外->编解码器信息”,或者如果您在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

http://www.videolan.org/vlc/

亲切的问候,
Ernst Jan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接