Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
JPG files to movie

Subject: JPG files to movie

From: nman2084

Date: 12 May, 2011 21:08:03

Message: 1 of 14

I am trying to make movie out of the JPG files, but I am getting this error:

??? Error using ==> avifile.addframe>ValidateFrame at 332
Frame must be 1366 by 656.

Error in ==> avifile.addframe at 196
      ValidateFrame(aviobj,width, height,dims);

Error in ==> movie2avi at 64
avimov = addframe(avimov,mov);

Error in ==> march2011Mov at 8
movie2avi(nom, 'movie.avi');

here is the code:


for i = 1 : 5
    s = int2str(i);
    fileName = strcat({'fig'},{s},{'.jpg'});
    fileName = cell2mat(fileName);
    diag = imread(fileName);
    nom(i) = im2frame(diag);
end;
movie2avi(nom, 'movie.avi');

Subject: JPG files to movie

From: ImageAnalyst

Date: 12 May, 2011 21:35:05

Message: 2 of 14

Evidently not all your frames are the same size. They need to be.
Put in this line
[rows columns numberOfColorChannels] = size(diag) % No semi colon
just after the imread() and see what it says.

Subject: JPG files to movie

From: nman2084

Date: 12 May, 2011 22:05:20

Message: 3 of 14

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9dede61b-829d-475c-bb4e-05644ec07f7e@h9g2000yqk.googlegroups.com>...
> Evidently not all your frames are the same size. They need to be.
> Put in this line
> [rows columns numberOfColorChannels] = size(diag) % No semi colon
> just after the imread() and see what it says.



rows =
   656
columns =
        1366
numberOfColorChannels =
     3

rows =
   656
columns =
        1350
numberOfColorChannels =
     3


rows =
   656
columns =
        1366
numberOfColorChannels =
     3

rows =
   656
columns =
        1366
numberOfColorChannels =
     3

rows =
   656
columns =
        1366
numberOfColorChannels =
     3


Is there a way to resolve this unequal issue?
             Thanks

Subject: JPG files to movie

From: ImageAnalyst

Date: 12 May, 2011 22:22:19

Message: 4 of 14

You could store the size of the first frame and then call imresize on
all subsequent frames with the size of the first frame. That would
make them all the size size, though it might distort the aspect ratio
of some frames.

Subject: JPG files to movie

From: James Tursa

Date: 13 May, 2011 00:08:04

Message: 5 of 14

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4959c882-d27e-40ad-8709-041612c731db@d28g2000yqf.googlegroups.com>...
> You could store the size of the first frame and then call imresize on
> all subsequent frames with the size of the first frame. That would
> make them all the size size, though it might distort the aspect ratio
> of some frames.

You could also resize with padding. e.g., using John D'Errico's FEX submission:

http://www.mathworks.com/matlabcentral/fileexchange/23974-wreshape

James Tursa

Subject: JPG files to movie

From: nman2084

Date: 13 May, 2011 19:32:04

Message: 6 of 14

aviobj = avifile('test.avi','compression','None','fps','3');


for i = 1 : 5
    s = int2str(i);
    fileName = strcat({'fig'},{s},{'.jpg'});
    fileName = cell2mat(fileName);
    imread(fileName);
    %[rows columns numberOfColorChannels] = size(diag)
    F = getframe;
    aviobj = addframe(aviobj,F);
end;
aviobj=close(aviobj);

This time, i am not getting error but test.avi i created does not contain anything.

Subject: JPG files to movie

From: ImageAnalyst

Date: 13 May, 2011 20:27:17

Message: 7 of 14

What is the range of your data? Is numberOfColorChannels equal to 3?

Why aren't you doing it this way (untested)?

for k = 1 : 5
    baseFileName = sprintf('fig%d.jpg', k);
    fullFileName = fullfile(pwd, baseFileName);
    if exist(fullFileName, 'file')
        imageArray = imread(fileName);
        [rows columns numberOfColorChannels] = size(imageArray )
        aviobj = addframe(aviobj, imageArray );
    else
        message = sprintf('File not found:\n%s', fullFileName);
        uiwait(warndlg(message));
    end % of if exist...
end % of loop over k

Or else do it the way I did it at the end of my demo code:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306289#831247

Subject: JPG files to movie

From: nman2084

Date: 13 May, 2011 20:40:04

Message: 8 of 14

Thanks for the reply:

I am right now getting video out of jpg files but when i play it it goes too fast. Here is the code:

clear M ;

mov=avifile('test.avi','compression','None','fps','3');
for i=1:5
    s = int2str(i);
    fileName = strcat({'fig'},{s},{'.jpg'});
    fileName = cell2mat(fileName);
    [X,map] = imread(fileName) ;
    imagesc(X);
    M(i) = getframe ;
    mov = addframe(mov,M(i)); % adds the frame into mov
    pause(2)
end
mov=close(mov); % closes the mov

Subject: JPG files to movie

From: ImageAnalyst

Date: 13 May, 2011 21:17:28

Message: 9 of 14

Did you look up the options for avifile(), and happen to see this?
'fps' A scalar value specifying the speed of the AVI movie in frames
per second (fps).

Of course you have only 5 frames so it will go fast, especially at 15
fps.

Subject: JPG files to movie

From: nman2084

Date: 13 May, 2011 23:43:05

Message: 10 of 14

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <dd28df1d-fbf5-482b-85e4-2f870275a67d@r20g2000yqd.googlegroups.com>...
> Did you look up the options for avifile(), and happen to see this?
> 'fps' A scalar value specifying the speed of the AVI movie in frames
> per second (fps).
>
> Of course you have only 5 frames so it will go fast, especially at 15
> fps.

Thanks, i saw the default is 15, is there a way for me to change it.

Subject: JPG files to movie

From: TideMan

Date: 13 May, 2011 23:50:29

Message: 11 of 14

On May 14, 11:43 am, "nman2084 " <ng2...@yahoo.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <dd28df1d-fbf5-482b-85e4-2f870275a...@r20g2000yqd.googlegroups.com>...
> > Did you look up the options for avifile(), and happen to see this?
> > 'fps'  A scalar value specifying the speed of the AVI movie in frames
> > per second (fps).
>
> > Of course you have only 5 frames so it will go fast, especially at 15
> > fps.
>
> Thanks, i saw the default is 15, is there a way for me to change it.

That's an odd question when a few posts ago you wrote this:
mov=avifile('test.avi','compression','None','fps','3');

Old-Timers' Disease, maybe.

Subject: JPG files to movie

From: ImageAnalyst

Date: 13 May, 2011 23:54:15

Message: 12 of 14

On May 13, 7:43 pm, "nman2084 " <ng2...@yahoo.com> wrote:
> Thanks, i saw the default is 15, is there a way for me to change it.
----------------------------------------------------
Of course. I repeat my answer:

Did you look up the options for avifile(), and happen to see this?
'fps' A scalar value specifying the speed of the AVI movie in frames
per second (fps).

That means you pass in 'fps' followed by a comma and a number in the
argument list. Looks like some brushing up on function calls might be
in order.

Subject: JPG files to movie

From: nman2084

Date: 13 May, 2011 23:59:04

Message: 13 of 14

TideMan <mulgor@gmail.com> wrote in message <52d0eac3-0b0d-4d5c-a41a-decf5ac62294@h12g2000pro.googlegroups.com>...
> On May 14, 11:43 am, "nman2084 " <ng2...@yahoo.com> wrote:
> > ImageAnalyst <imageanal...@mailinator.com> wrote in message <dd28df1d-fbf5-482b-85e4-2f870275a...@r20g2000yqd.googlegroups.com>...
> > > Did you look up the options for avifile(), and happen to see this?
> > > 'fps'  A scalar value specifying the speed of the AVI movie in frames
> > > per second (fps).
> >
> > > Of course you have only 5 frames so it will go fast, especially at 15
> > > fps.
> >
> > Thanks, i saw the default is 15, is there a way for me to change it.
>
> That's an odd question when a few posts ago you wrote this:
> mov=avifile('test.avi','compression','None','fps','3');
>
> Old-Timers' Disease, maybe.

lol i figured that 3 is supposed to fps, i changed it to 1 and ran the program. But the video is still goes very fast even with slowed fps. Is there a way to pause each frame for some duration.
              

Subject: JPG files to movie

From: ImageAnalyst

Date: 14 May, 2011 00:21:26

Message: 14 of 14

On May 13, 7:59 pm, "nman2084 " <ng2...@yahoo.com> wrote:
> lol i figured that 3 is supposed to fps, i changed it to 1 and ran the program. But the video is still goes very fast even with slowed fps. Is there a way to pause each frame for some duration.
-------------------------------------------------
Only if you extract the frames and show them with imshow() and prompt
the user to continue with code like this:
promptMessage = sprintf('Do you want to Continue processing,\nor
Cancel to abort processing?');
button = questdlg(promptMessage, 'Continue', 'Continue', 'Cancel',
'Continue');
if strcmp(button, 'Cancel')
return;
end

Tags for this Thread

No tags are associated with this thread.

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.

Contact us