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:
problem with avifile in IAT toolbox

Subject: problem with avifile in IAT toolbox

From: Alex

Date: 16 Nov, 2010 12:18:06

Message: 1 of 5

I have a strange problem with writing ( saving) my avi file .
At the first time it works correctly , but always in the second run I have problems:

??? Error using ==> avi
Failed to open file.

Error in ==> avifile.avifile at 173
  aviobj.FileHandle = avi('open',filename);

Error in ==> Untitled at 17
aviobj2 = avifile('imag1.avi');

if I change the file name manually then it works. but why this problem happens ?



vid=videoinput('avtmatlabadaptor_r2010a',1,'F0M5_Mono8_640x480');
triggerconfig(vid, 'manual');
vid.TimerFcn=@trigger;
vid.TimerPeriod = 1;

set(vid, 'FramesPerTrigger', 5)
set(vid, 'TriggerRepeat', 4)


% Configure the processing routine and AVI file.
vid.TriggerFcn = {'util_imaverage', 5};
aviobj2 = avifile('imag1111.avi');
aviobj2.Fps = 20;

% Use the video input object's UserData to store processing information.
userdata2.average = {};
userdata2.avi = aviobj2;
vid.UserData = userdata2;

% Start the acquisition.
start(vid);
wait(vid, 10);

% Verify the averaged frames were saved to the AVI file.
userdata2 = vid.UserData;
aviobj2 = userdata2.avi;
framesWritten2 = aviobj2.TotalFrames

% Display the resulting averages of the acquired frames.
% Notice the change in the lower chamber of the hourglass over time.
imaqmontage(userdata2.average);
title('Averaging Results - Timer Based');

% Once the video input object is no longer needed, delete
% it and clear it from the workspace.
delete(vid)
clear vid

Subject: problem with avifile in IAT toolbox

From: Aurelien Queffurust

Date: 16 Nov, 2010 14:15:05

Message: 2 of 5

"Alex " <ashkandav@yahoo.com> wrote in message <ibtspu$gfi$1@fred.mathworks.com>...
> I have a strange problem with writing ( saving) my avi file .
> At the first time it works correctly , but always in the second run I have problems:
>
> ??? Error using ==> avi
> Failed to open file.
>
> Error in ==> avifile.avifile at 173
> aviobj.FileHandle = avi('open',filename);
>
> Error in ==> Untitled at 17
> aviobj2 = avifile('imag1.avi');
>
> if I change the file name manually then it works. but why this problem happens ?
>
>
>
> vid=videoinput('avtmatlabadaptor_r2010a',1,'F0M5_Mono8_640x480');
> triggerconfig(vid, 'manual');
> vid.TimerFcn=@trigger;
> vid.TimerPeriod = 1;
>
> set(vid, 'FramesPerTrigger', 5)
> set(vid, 'TriggerRepeat', 4)
>
>
> % Configure the processing routine and AVI file.
> vid.TriggerFcn = {'util_imaverage', 5};
> aviobj2 = avifile('imag1111.avi');
> aviobj2.Fps = 20;
>
> % Use the video input object's UserData to store processing information.
> userdata2.average = {};
> userdata2.avi = aviobj2;
> vid.UserData = userdata2;
>
> % Start the acquisition.
> start(vid);
> wait(vid, 10);
>
> % Verify the averaged frames were saved to the AVI file.
> userdata2 = vid.UserData;
> aviobj2 = userdata2.avi;
> framesWritten2 = aviobj2.TotalFrames
>
> % Display the resulting averages of the acquired frames.
> % Notice the change in the lower chamber of the hourglass over time.
> imaqmontage(userdata2.average);
> title('Averaging Results - Timer Based');
>
> % Once the video input object is no longer needed, delete
> % it and clear it from the workspace.
> delete(vid)
> clear vid


You may read that:
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
http://blog.developpez.com/matlab4geek/

Subject: problem with avifile in IAT toolbox

From: Alex

Date: 16 Nov, 2010 14:50:29

Message: 3 of 5

@ Aurelien :

Thanks for the help, I have tested the software it worked properly so I think I do not have a windows API problem.

I 'm not sure but maybe its a software bug. I gonna try VideoWriter instead.

Subject: problem with avifile in IAT toolbox

From: Steven_Lord

Date: 16 Nov, 2010 14:55:28

Message: 4 of 5



"Alex " <ashkandav@yahoo.com> wrote in message
news:ibtspu$gfi$1@fred.mathworks.com...
> I have a strange problem with writing ( saving) my avi file .
> At the first time it works correctly , but always in the second run I have
> problems:
>
> ??? Error using ==> avi
> Failed to open file.
>
> Error in ==> avifile.avifile at 173
> aviobj.FileHandle = avi('open',filename);
>
> Error in ==> Untitled at 17
> aviobj2 = avifile('imag1.avi');
>
> if I change the file name manually then it works. but why this problem
> happens ?
>
>
>
> vid=videoinput('avtmatlabadaptor_r2010a',1,'F0M5_Mono8_640x480');
> triggerconfig(vid, 'manual');
> vid.TimerFcn=@trigger;
> vid.TimerPeriod = 1;
>
> set(vid, 'FramesPerTrigger', 5)
> set(vid, 'TriggerRepeat', 4)
>
>
> % Configure the processing routine and AVI file.
> vid.TriggerFcn = {'util_imaverage', 5};
> aviobj2 = avifile('imag1111.avi');

Here's where you construct (and open) your AVIFILE. I don't see anywhere in
your code a corresponding call to the CLOSE method for this AVIFILE object.

http://www.mathworks.com/help/techdoc/ref/avifile.close.html

You can't reopen an AVI file that's already open, and that I believe is the
cause of the problem. Try using CLOSE on the object once you've finished
writing to it and I think you'll fix this message.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: problem with avifile in IAT toolbox

From: Alex

Date: 16 Nov, 2010 16:05:08

Message: 5 of 5

@ Steve:

Thanks that solved the Problem, Now I get the results even if I run it for several times but in command window I got this message. I tried to play a little with triggering values but that was not successful.

??? Error using ==> imaqdevice.trigger at 51
TRIGGER cannot be called more than TriggerRepeat + 1 times.
 
Warning: The TimerFcn callback is being disabled.
To enable the callback, set the TimerFcn property.
Trigger event occurred at 16:56:24.

Tags for 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