【问题标题】:Extracting Frames From A Video In Matlab在 Matlab 中从视频中提取帧
【发布时间】:2014-09-07 19:40:16
【问题描述】:

我试图使用following lines of code 从一个小视频中提取帧:

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

标签: image matlab video video-processing codec


【解决方案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

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

亲切的问候,

恩斯特·扬

【讨论】:

    【解决方案2】:

    我使用了以下代码行,而不是 MMREADER

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

    成功了。

    【讨论】:

      猜你喜欢
      • 2014-02-27
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2017-11-01
      • 2012-02-22
      • 1970-01-01
      相关资源
      最近更新 更多