Thread Subject: convert video avi to frames

Subject: convert video avi to frames

From: Teoh

Date: 9 Nov, 2010 08:51:04

Message: 1 of 12

hi,
can anyone out here teach me how to use matlab to convert video avi to frames
like load the video and then break them down to their frames. how is the frames label as and how to call the frames out to use them.

thax

Subject: convert video avi to frames

From: Teoh

Date: 15 Nov, 2010 13:42:05

Message: 2 of 12

i mean i just want to extrect the frame out from the video. Do i need a long code for this? and can i process the video while playing it or it can only be process after breaking the whole video into frame?

Subject: convert video avi to frames

From: Kalim DElia

Date: 3 Dec, 2010 02:13:05

Message: 3 of 12

i have the same question!

http://www.mathworks.com/matlabcentral/newsreader/view_thread/297680

Subject: convert video avi to frames

From: ImageAnalyst

Date: 3 Dec, 2010 03:25:37

Message: 4 of 12

On Dec 2, 9:13 pm, "Kalim DElia" <kalimde...@gmail.com> wrote:
> i have the same question!
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/297680

------------------------------------------------------------------------
See my demo:
BE SURE to join any lines that the newsreader splits into two (there
will be syntax errors there if you don't re-join the lines).


% Demo macro to extract frames and get frame means from an avi movie
% and save individual frames to separate image files.
% Also computes the mean gray value of the color channels.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Open the rhino.avi demo movie that ships with MATLAB.
movieFullFileName = 'C:\Program Files\MATLAB\R2010a\toolbox\images
\imdemos\rhinos.avi';
% Check to see that it exists.
if ~exist(movieFullFileName, 'file')
strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new
one, or cancel', movieFullFileName);
response = questdlg(strErrorMessage, 'File not found', 'OK - choose a
new movie.', 'Cancel', 'OK - choose a new movie.');
if strcmpi(response, 'OK - choose a new movie.')
[baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
if ~isequal(baseFileName, 0)
movieFullFileName = fullfile(folderName, baseFileName);
else
return;
end
else
return;
end
end

try
mov = aviread(movieFullFileName);
% movie(mov);
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;
% Prepare a figure to show the images in the upper half of the
screen.
figure;
screenSize = get(0, 'ScreenSize');
newWindowPosition = [1 screenSize(4)/2 - 70 screenSize(3)
screenSize(4)/2];
set(gcf, 'Position', newWindowPosition); % Maximize figure.
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

    % Ask user if they want to write the individual frames out to
disk.
    promptMessage = sprintf('Do you want to save the individual frames
out to individual disk files?');
    button = questdlg(promptMessage, 'Save individual frames?', 'Yes',
'No', 'Yes');
    if strcmp(button, 'Yes')
        writeToDisk = true;

        % Extract out the various parts of the filename.
        [folder, baseFileName, extentions, version] =
fileparts(movieFullFileName);
        % Make up a special new output subfolder for all the separate
        % movie frames that we're going to extract and save to disk.
        % (Don't worry - windows can handle forward slashes in the
folder name.)
        folder = pwd; % Make it a subfolder of the folder where this
m-file lives.
        outputFolder = sprintf('%s/Movie Frames from %s', folder,
baseFileName);
        % Create the folder if it doesn't exist already.
        if ~exist(outputFolder, 'dir')
            mkdir(outputFolder);
        end
    else
        writeToDisk = false;
    end

    % Loop through the movie, writing all frames out.
% Each frame will be in a separate file with unique name.
meanGrayLevels = zeros(numberOfFrames, 1);
meanRedLevels = zeros(numberOfFrames, 1);
meanGreenLevels = zeros(numberOfFrames, 1);
meanBlueLevels = zeros(numberOfFrames, 1);
    for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = mov(frame).cdata;

        % Display it
        hImage = subplot(1,2,1);
        image(thisFrame);
        axis square;
        caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
        title(caption, 'FontSize', fontSize);
        drawnow; % Force it to refresh the window.

% Write the image array to the output file, if requested.
        if writeToDisk
             % Construct an output image file name.
            outputBaseFileName = sprintf('Frame %4.4d.png', frame);
            outputFullFileName = fullfile(outputFolder,
outputBaseFileName);

            % Stamp the name and frame number onto the image.
            % At this point it's just going into the overlay,
            % not actually getting written into the pixel values.
            text(5, 15, outputBaseFileName, 'FontSize', 20);

            % Extract the image with the text "burned into" it.
            frameWithText = getframe(gca);
            % frameWithText.cdata is the image with the text
            % actually written into the pixel values.
            % Write it out to disk.
            imwrite(frameWithText.cdata, outputFullFileName, 'png');
        end

% Calculate the mean gray level.
grayImage = rgb2gray(thisFrame);
meanGrayLevels(frame) = mean(grayImage(:));

% Calculate the mean R, G, and B levels.
meanRedLevels(frame) = mean(mean(thisFrame(:, :, 1)));
meanGreenLevels(frame) = mean(mean(thisFrame(:, :, 2)));
meanBlueLevels(frame) = mean(mean(thisFrame(:, :, 3)));

% Plot the mean gray levels.
hPlot = subplot(1,2,2);
        hold off;
plot(meanGrayLevels, 'k-', 'LineWidth', 2);
        hold on;
        plot(meanRedLevels, 'r-');
        plot(meanGreenLevels, 'g-');
        plot(meanBlueLevels, 'b-');

        % Put title back because plot() erases the existing title.
title('Mean Gray Levels', 'FontSize', fontSize);
        if frame == 1
xlabel('Frame Number');
yLabel('Gray Level');
            % Get size data later for preallocation if we read
            % the movie back in from disk.
            [rows columns numberOfColorChannels] = size(thisFrame);
        end

        % Update user with the progress. Display in the command
window.
        if writeToDisk
     progressIndication = sprintf('Wrote frame %4d of %d.', frame,
numberOfFrames);
        else
     progressIndication = sprintf('Processed frame %4d of %d.',
frame, numberOfFrames);
        end
disp(progressIndication);
% Increment frame count (should eventually = numberOfFrames
% unless an error happens).
numberOfFramesWritten = numberOfFramesWritten + 1;
    end

    % Alert user that we're done.
    if writeToDisk
        finishedMessage = sprintf('Done! It wrote %d frames to folder
\n"%s"', numberOfFramesWritten, outputFolder);
    else
        finishedMessage = sprintf('Done! It processed %d frames of
\n"%s"', numberOfFramesWritten, movieFullFileName);
    end
    disp(finishedMessage); % Write to command window.
    uiwait(msgbox(finishedMessage)); % Also pop up a message box.

    % Exit if they didn't write any individual frames out to disk.
    if ~writeToDisk
        return;
    end

    % Ask user if they want to read the individual frames from the
disk,
    % that they just wrote out, back into a movie and display it.
    promptMessage = sprintf('Do you want to recall the individual
frames\nback from disk into a movie?\n(This will take several
seconds.)');
    button = questdlg(promptMessage, 'Recall Movie?', 'Yes', 'No',
'Yes');
    if strcmp(button, 'No')
        return;
    end

    % Read the frames back in, and convert them to a movie.
    % I don't know of any way to preallocate recalledMovie.
    for frame = 1 : numberOfFrames
        % Construct an output image file name.
        outputBaseFileName = sprintf('Frame %4.4d.png', frame);
        outputFullFileName = fullfile(outputFolder,
outputBaseFileName);
        % Read the image in from disk.
        thisFrame = imread(outputFullFileName);
        % Convert the image into a "movie frame" structure.
        recalledMovie(frame) = im2frame(thisFrame);
    end
    % Get rid of old image and plot.
    delete(hImage);
    delete(hPlot);
    % Create new axes for our movie.
    subPlot(1, 3, 2);
    axis off; % Turn off axes numbers.
    title('Movie recalled from disk', 'FontSize', fontSize);
    % Play the movie in the axes.
    movie(recalledMovie);
    % Note: if you want to display graphics or text in the overlay
    % as the movie plays back then you need to do it like I did at
first
    % (at the top of this file where you extract and imshow a frame at
a time.)
    msgbox('Done with this demo!');

catch ME
% Some error happened if you get here.
stError = lasterror;
strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n
\nError: %s\n\n)', movieFullFileName, stError.message);
msgboxw(strErrorMessage);
end

Subject: convert video avi to frames

From: Kalim DElia

Date: 3 Dec, 2010 04:55:06

Message: 5 of 12

I have this error

Error in ==> Speckle at 200
msgboxw(strErrorMessage);

Subject: convert video avi to frames

From: Kalim DElia

Date: 3 Dec, 2010 05:06:06

Message: 6 of 12

Ready!!!!

I fix it

I'm going to study this tanks

Subject: convert video avi to frames

From: nsh

Date: 17 Dec, 2010 12:09:04

Message: 7 of 12


hi,

i tried this code but its not supporting all avi files.i was trying to separate frames from cat_video.avi file which is there in matlab folder.. ..but it is giving error as can not extract frames from video..

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <51ecfbc6-66d4-4c2b-8feb-af178de26892@h17g2000pre.googlegroups.com>...
> On Dec 2, 9:13 pm, "Kalim DElia" <kalimde...@gmail.com> wrote:
> > i have the same question!
> >
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/297680
>
> ------------------------------------------------------------------------
> See my demo:
> BE SURE to join any lines that the newsreader splits into two (there
> will be syntax errors there if you don't re-join the lines).
>
>
> % Demo macro to extract frames and get frame means from an avi movie
> % and save individual frames to separate image files.
> % Also computes the mean gray value of the color channels.
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 14;
>
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> % Open the rhino.avi demo movie that ships with MATLAB.
> movieFullFileName = 'C:\Program Files\MATLAB\R2010a\toolbox\images
> \imdemos\rhinos.avi';
> % Check to see that it exists.
> if ~exist(movieFullFileName, 'file')
> strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new
> one, or cancel', movieFullFileName);
> response = questdlg(strErrorMessage, 'File not found', 'OK - choose a
> new movie.', 'Cancel', 'OK - choose a new movie.');
> if strcmpi(response, 'OK - choose a new movie.')
> [baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
> if ~isequal(baseFileName, 0)
> movieFullFileName = fullfile(folderName, baseFileName);
> else
> return;
> end
> else
> return;
> end
> end
>
> try
> mov = aviread(movieFullFileName);
> % movie(mov);
> % Determine how many frames there are.
> numberOfFrames = size(mov, 2);
> numberOfFramesWritten = 0;
> % Prepare a figure to show the images in the upper half of the
> screen.
> figure;
> screenSize = get(0, 'ScreenSize');
> newWindowPosition = [1 screenSize(4)/2 - 70 screenSize(3)
> screenSize(4)/2];
> set(gcf, 'Position', newWindowPosition); % Maximize figure.
> % set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
>
> % Ask user if they want to write the individual frames out to
> disk.
> promptMessage = sprintf('Do you want to save the individual frames
> out to individual disk files?');
> button = questdlg(promptMessage, 'Save individual frames?', 'Yes',
> 'No', 'Yes');
> if strcmp(button, 'Yes')
> writeToDisk = true;
>
> % Extract out the various parts of the filename.
> [folder, baseFileName, extentions, version] =
> fileparts(movieFullFileName);
> % Make up a special new output subfolder for all the separate
> % movie frames that we're going to extract and save to disk.
> % (Don't worry - windows can handle forward slashes in the
> folder name.)
> folder = pwd; % Make it a subfolder of the folder where this
> m-file lives.
> outputFolder = sprintf('%s/Movie Frames from %s', folder,
> baseFileName);
> % Create the folder if it doesn't exist already.
> if ~exist(outputFolder, 'dir')
> mkdir(outputFolder);
> end
> else
> writeToDisk = false;
> end
>
> % Loop through the movie, writing all frames out.
> % Each frame will be in a separate file with unique name.
> meanGrayLevels = zeros(numberOfFrames, 1);
> meanRedLevels = zeros(numberOfFrames, 1);
> meanGreenLevels = zeros(numberOfFrames, 1);
> meanBlueLevels = zeros(numberOfFrames, 1);
> for frame = 1 : numberOfFrames
> % Extract the frame from the movie structure.
> thisFrame = mov(frame).cdata;
>
> % Display it
> hImage = subplot(1,2,1);
> image(thisFrame);
> axis square;
> caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
> title(caption, 'FontSize', fontSize);
> drawnow; % Force it to refresh the window.
>
> % Write the image array to the output file, if requested.
> if writeToDisk
> % Construct an output image file name.
> outputBaseFileName = sprintf('Frame %4.4d.png', frame);
> outputFullFileName = fullfile(outputFolder,
> outputBaseFileName);
>
> % Stamp the name and frame number onto the image.
> % At this point it's just going into the overlay,
> % not actually getting written into the pixel values.
> text(5, 15, outputBaseFileName, 'FontSize', 20);
>
> % Extract the image with the text "burned into" it.
> frameWithText = getframe(gca);
> % frameWithText.cdata is the image with the text
> % actually written into the pixel values.
> % Write it out to disk.
> imwrite(frameWithText.cdata, outputFullFileName, 'png');
> end
>
> % Calculate the mean gray level.
> grayImage = rgb2gray(thisFrame);
> meanGrayLevels(frame) = mean(grayImage(:));
>
> % Calculate the mean R, G, and B levels.
> meanRedLevels(frame) = mean(mean(thisFrame(:, :, 1)));
> meanGreenLevels(frame) = mean(mean(thisFrame(:, :, 2)));
> meanBlueLevels(frame) = mean(mean(thisFrame(:, :, 3)));
>
> % Plot the mean gray levels.
> hPlot = subplot(1,2,2);
> hold off;
> plot(meanGrayLevels, 'k-', 'LineWidth', 2);
> hold on;
> plot(meanRedLevels, 'r-');
> plot(meanGreenLevels, 'g-');
> plot(meanBlueLevels, 'b-');
>
> % Put title back because plot() erases the existing title.
> title('Mean Gray Levels', 'FontSize', fontSize);
> if frame == 1
> xlabel('Frame Number');
> yLabel('Gray Level');
> % Get size data later for preallocation if we read
> % the movie back in from disk.
> [rows columns numberOfColorChannels] = size(thisFrame);
> end
>
> % Update user with the progress. Display in the command
> window.
> if writeToDisk
> progressIndication = sprintf('Wrote frame %4d of %d.', frame,
> numberOfFrames);
> else
> progressIndication = sprintf('Processed frame %4d of %d.',
> frame, numberOfFrames);
> end
> disp(progressIndication);
> % Increment frame count (should eventually = numberOfFrames
> % unless an error happens).
> numberOfFramesWritten = numberOfFramesWritten + 1;
> end
>
> % Alert user that we're done.
> if writeToDisk
> finishedMessage = sprintf('Done! It wrote %d frames to folder
> \n"%s"', numberOfFramesWritten, outputFolder);
> else
> finishedMessage = sprintf('Done! It processed %d frames of
> \n"%s"', numberOfFramesWritten, movieFullFileName);
> end
> disp(finishedMessage); % Write to command window.
> uiwait(msgbox(finishedMessage)); % Also pop up a message box.
>
> % Exit if they didn't write any individual frames out to disk.
> if ~writeToDisk
> return;
> end
>
> % Ask user if they want to read the individual frames from the
> disk,
> % that they just wrote out, back into a movie and display it.
> promptMessage = sprintf('Do you want to recall the individual
> frames\nback from disk into a movie?\n(This will take several
> seconds.)');
> button = questdlg(promptMessage, 'Recall Movie?', 'Yes', 'No',
> 'Yes');
> if strcmp(button, 'No')
> return;
> end
>
> % Read the frames back in, and convert them to a movie.
> % I don't know of any way to preallocate recalledMovie.
> for frame = 1 : numberOfFrames
> % Construct an output image file name.
> outputBaseFileName = sprintf('Frame %4.4d.png', frame);
> outputFullFileName = fullfile(outputFolder,
> outputBaseFileName);
> % Read the image in from disk.
> thisFrame = imread(outputFullFileName);
> % Convert the image into a "movie frame" structure.
> recalledMovie(frame) = im2frame(thisFrame);
> end
> % Get rid of old image and plot.
> delete(hImage);
> delete(hPlot);
> % Create new axes for our movie.
> subPlot(1, 3, 2);
> axis off; % Turn off axes numbers.
> title('Movie recalled from disk', 'FontSize', fontSize);
> % Play the movie in the axes.
> movie(recalledMovie);
> % Note: if you want to display graphics or text in the overlay
> % as the movie plays back then you need to do it like I did at
> first
> % (at the top of this file where you extract and imshow a frame at
> a time.)
> msgbox('Done with this demo!');
>
> catch ME
> % Some error happened if you get here.
> stError = lasterror;
> strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n
> \nError: %s\n\n)', movieFullFileName, stError.message);
> msgboxw(strErrorMessage);
> end

Subject: convert video avi to frames

From: ImageAnalyst

Date: 17 Dec, 2010 13:00:00

Message: 8 of 12

On Dec 17, 7:09 am, "nsh " <nsh_...@yahoo.com> wrote:
> hi,
>
> i tried this code but its not supporting all avi files.i was trying to separate frames from cat_video.avi file which is there in matlab folder.. ..but it is giving error as can not extract  frames from video..
-----------------------------------------------------------------------------------------
cat_video is not in my MATLAB folder. Please tell me exactly the
folder that it is in. Maybe it was shipped with a toolbox or version
that I don't have. I have R2010a and R2010b on this computer. Maybe
it's not a MATLAB-supplied avi file but one you got somewhere else
that used a special encoder.

What is the exact error you're getting?

Have you looked at this week's "File Exchange Pick of the Week"?
http://blogs.mathworks.com/pick/2010/12/10/video-player-for-your-frame-based-processing/

A longshot:
Why do I receive the error "Failed to open file" when I read an AVI
file using AVIREAD command on MATLAB 7.8 (R2009a)?
http://www.mathworks.com/support/solutions/en/data/1-B3DT9O/?solution=1-B3DT9O

Aurélien

Subject: convert video avi to frames

From: Sree

Date: 26 Dec, 2010 19:03:05

Message: 9 of 12

I've made all the changes required to the file. But, I got an error as indicated below :

??? Undefined function or variable "ME".

Error in ==> avi2frames at 193
catch ME


Please provide any solution ASAP. I've tried many ways(including ffmpeg) to extract frames from a video file, but in vain. Thought of this would help me out...


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <51ecfbc6-66d4-4c2b-8feb-af178de26892@h17g2000pre.googlegroups.com>...
> On Dec 2, 9:13 pm, "Kalim DElia" <kalimde...@gmail.com> wrote:
> > i have the same question!
> >
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/297680
>
> ------------------------------------------------------------------------
> See my demo:
> BE SURE to join any lines that the newsreader splits into two (there
> will be syntax errors there if you don't re-join the lines).
>
>
> % Demo macro to extract frames and get frame means from an avi movie
> % and save individual frames to separate image files.
> % Also computes the mean gray value of the color channels.
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 14;
>
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> % Open the rhino.avi demo movie that ships with MATLAB.
> movieFullFileName = 'C:\Program Files\MATLAB\R2010a\toolbox\images
> \imdemos\rhinos.avi';
> % Check to see that it exists.
> if ~exist(movieFullFileName, 'file')
> strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new
> one, or cancel', movieFullFileName);
> response = questdlg(strErrorMessage, 'File not found', 'OK - choose a
> new movie.', 'Cancel', 'OK - choose a new movie.');
> if strcmpi(response, 'OK - choose a new movie.')
> [baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
> if ~isequal(baseFileName, 0)
> movieFullFileName = fullfile(folderName, baseFileName);
> else
> return;
> end
> else
> return;
> end
> end
>
> try
> mov = aviread(movieFullFileName);
> % movie(mov);
> % Determine how many frames there are.
> numberOfFrames = size(mov, 2);
> numberOfFramesWritten = 0;
> % Prepare a figure to show the images in the upper half of the
> screen.
> figure;
> screenSize = get(0, 'ScreenSize');
> newWindowPosition = [1 screenSize(4)/2 - 70 screenSize(3)
> screenSize(4)/2];
> set(gcf, 'Position', newWindowPosition); % Maximize figure.
> % set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
>
> % Ask user if they want to write the individual frames out to
> disk.
> promptMessage = sprintf('Do you want to save the individual frames
> out to individual disk files?');
> button = questdlg(promptMessage, 'Save individual frames?', 'Yes',
> 'No', 'Yes');
> if strcmp(button, 'Yes')
> writeToDisk = true;
>
> % Extract out the various parts of the filename.
> [folder, baseFileName, extentions, version] =
> fileparts(movieFullFileName);
> % Make up a special new output subfolder for all the separate
> % movie frames that we're going to extract and save to disk.
> % (Don't worry - windows can handle forward slashes in the
> folder name.)
> folder = pwd; % Make it a subfolder of the folder where this
> m-file lives.
> outputFolder = sprintf('%s/Movie Frames from %s', folder,
> baseFileName);
> % Create the folder if it doesn't exist already.
> if ~exist(outputFolder, 'dir')
> mkdir(outputFolder);
> end
> else
> writeToDisk = false;
> end
>
> % Loop through the movie, writing all frames out.
> % Each frame will be in a separate file with unique name.
> meanGrayLevels = zeros(numberOfFrames, 1);
> meanRedLevels = zeros(numberOfFrames, 1);
> meanGreenLevels = zeros(numberOfFrames, 1);
> meanBlueLevels = zeros(numberOfFrames, 1);
> for frame = 1 : numberOfFrames
> % Extract the frame from the movie structure.
> thisFrame = mov(frame).cdata;
>
> % Display it
> hImage = subplot(1,2,1);
> image(thisFrame);
> axis square;
> caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
> title(caption, 'FontSize', fontSize);
> drawnow; % Force it to refresh the window.
>
> % Write the image array to the output file, if requested.
> if writeToDisk
> % Construct an output image file name.
> outputBaseFileName = sprintf('Frame %4.4d.png', frame);
> outputFullFileName = fullfile(outputFolder,
> outputBaseFileName);
>
> % Stamp the name and frame number onto the image.
> % At this point it's just going into the overlay,
> % not actually getting written into the pixel values.
> text(5, 15, outputBaseFileName, 'FontSize', 20);
>
> % Extract the image with the text "burned into" it.
> frameWithText = getframe(gca);
> % frameWithText.cdata is the image with the text
> % actually written into the pixel values.
> % Write it out to disk.
> imwrite(frameWithText.cdata, outputFullFileName, 'png');
> end
>
> % Calculate the mean gray level.
> grayImage = rgb2gray(thisFrame);
> meanGrayLevels(frame) = mean(grayImage(:));
>
> % Calculate the mean R, G, and B levels.
> meanRedLevels(frame) = mean(mean(thisFrame(:, :, 1)));
> meanGreenLevels(frame) = mean(mean(thisFrame(:, :, 2)));
> meanBlueLevels(frame) = mean(mean(thisFrame(:, :, 3)));
>
> % Plot the mean gray levels.
> hPlot = subplot(1,2,2);
> hold off;
> plot(meanGrayLevels, 'k-', 'LineWidth', 2);
> hold on;
> plot(meanRedLevels, 'r-');
> plot(meanGreenLevels, 'g-');
> plot(meanBlueLevels, 'b-');
>
> % Put title back because plot() erases the existing title.
> title('Mean Gray Levels', 'FontSize', fontSize);
> if frame == 1
> xlabel('Frame Number');
> yLabel('Gray Level');
> % Get size data later for preallocation if we read
> % the movie back in from disk.
> [rows columns numberOfColorChannels] = size(thisFrame);
> end
>
> % Update user with the progress. Display in the command
> window.
> if writeToDisk
> progressIndication = sprintf('Wrote frame %4d of %d.', frame,
> numberOfFrames);
> else
> progressIndication = sprintf('Processed frame %4d of %d.',
> frame, numberOfFrames);
> end
> disp(progressIndication);
> % Increment frame count (should eventually = numberOfFrames
> % unless an error happens).
> numberOfFramesWritten = numberOfFramesWritten + 1;
> end
>
> % Alert user that we're done.
> if writeToDisk
> finishedMessage = sprintf('Done! It wrote %d frames to folder
> \n"%s"', numberOfFramesWritten, outputFolder);
> else
> finishedMessage = sprintf('Done! It processed %d frames of
> \n"%s"', numberOfFramesWritten, movieFullFileName);
> end
> disp(finishedMessage); % Write to command window.
> uiwait(msgbox(finishedMessage)); % Also pop up a message box.
>
> % Exit if they didn't write any individual frames out to disk.
> if ~writeToDisk
> return;
> end
>
> % Ask user if they want to read the individual frames from the
> disk,
> % that they just wrote out, back into a movie and display it.
> promptMessage = sprintf('Do you want to recall the individual
> frames\nback from disk into a movie?\n(This will take several
> seconds.)');
> button = questdlg(promptMessage, 'Recall Movie?', 'Yes', 'No',
> 'Yes');
> if strcmp(button, 'No')
> return;
> end
>
> % Read the frames back in, and convert them to a movie.
> % I don't know of any way to preallocate recalledMovie.
> for frame = 1 : numberOfFrames
> % Construct an output image file name.
> outputBaseFileName = sprintf('Frame %4.4d.png', frame);
> outputFullFileName = fullfile(outputFolder,
> outputBaseFileName);
> % Read the image in from disk.
> thisFrame = imread(outputFullFileName);
> % Convert the image into a "movie frame" structure.
> recalledMovie(frame) = im2frame(thisFrame);
> end
> % Get rid of old image and plot.
> delete(hImage);
> delete(hPlot);
> % Create new axes for our movie.
> subPlot(1, 3, 2);
> axis off; % Turn off axes numbers.
> title('Movie recalled from disk', 'FontSize', fontSize);
> % Play the movie in the axes.
> movie(recalledMovie);
> % Note: if you want to display graphics or text in the overlay
> % as the movie plays back then you need to do it like I did at
> first
> % (at the top of this file where you extract and imshow a frame at
> a time.)
> msgbox('Done with this demo!');
>
> catch ME
> % Some error happened if you get here.
> stError = lasterror;
> strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n
> \nError: %s\n\n)', movieFullFileName, stError.message);
> msgboxw(strErrorMessage);
> end

Subject: convert video avi to frames

From: ImageAnalyst

Date: 26 Dec, 2010 19:07:21

Message: 10 of 12

Just get rid of the ME. You probably have an old version that doesn't
support catch the way the new versions do.

Subject: convert video avi to frames

From: Sree

Date: 26 Dec, 2010 20:56:04

Message: 11 of 12

Then, any other alternate to get over this. I can't get a genuine newer version of MATLAB right now. Any help!!

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <59f06240-0af9-4e63-90f9-c3a0269ad5f8@d8g2000yqf.googlegroups.com>...
> Just get rid of the ME. You probably have an old version that doesn't
> support catch the way the new versions do.

Subject: convert video avi to frames

From: ImageAnalyst

Date: 26 Dec, 2010 21:21:18

Message: 12 of 12

On Dec 26, 3:56 pm, "Sree " <seenu...@gmail.com> wrote:
> Then, any other alternate to get over this. I can't get a genuine newer version of MATLAB right now. Any help!!
>
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <59f06240-0af9-4e63-90f9-c3a0269ad...@d8g2000yqf.googlegroups.com>...
> > Just get rid of the ME.  You probably have an old version that doesn't
> > support catch the way the new versions do.
---------------------------------------------------------------------------------
Just get rid of the try/catch entirely then. Just pull out any stuff
inside the try block into it's own file. In other words, what is in
the try part of the try/catch block should be the entirety of the code.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com