繁体   English   中英

在Matlab中从视频中提取帧

[英]Extracting Frames From A Video In Matlab

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

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

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

该文件似乎是用未知的视频编解码器编码的(可能是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

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

亲切的问候,

恩斯特·扬

我使用以下代码行代替MMREADER

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

有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM