Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting Frames From A Video In Matlab

I was trying to extract frames from a small video using the 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);

However, I am getting the following error on running this code :

??? Error using ==> extract at 10
The file requires the following codec(s) to be installed on your system:
    Unknown Codec

Can someone help me to sort out this error ? Thanks.

like image 547
competesingh Avatar asked Dec 19 '25 01:12

competesingh


2 Answers

The file seems to be encoded with an unknown video codec (unknown to MatLab probably). The file extension (.avi, .mpeg, etc.) does not denote a codec but rather a container if I'm not mistaking.

The links at the bottom provide some information about supported file formats by MatLab. You should try to retrieve what container and codec your video file uses and see if MatLab supports it. A way of retrieving the codec is by opening it in VLC mediaplayer (by VideoLan) right click the movie, extra-> codec information, or if you are on windows simply open the movie in VLC and press CTRL+J.

Some usefull links: 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/

Kind regards,

Ernst Jan

like image 142
EJG89 Avatar answered Dec 20 '25 18:12

EJG89


Instead of MMREADER, I used the following lines of code :

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

It worked.

like image 26
competesingh Avatar answered Dec 20 '25 16:12

competesingh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!