How do I save captured video to an avi like imaqtool does?

조회 수: 2 (최근 30일)
Chris
Chris 2013년 2월 17일
I'm using the Image Acquisition Toolbox (imaqtool) to capture video from my Pike camera. In imaqtool I'm able to push a button to acquire video and then another button to save the video to an avi file. The imaqtool session log says that this is the code used:
vid = videoinput('gentl', 1, 'RGB8Packed');
src = getselectedsource(vid);
vid.FramesPerTrigger = 100;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\MATLAB\vidx.avi', 'Uncompressed AVI');
open(diskLogger);
data = getdata(vid, vid.FramesAvaialble);
numFrames = size(data, 4);
for ii = 1:numFrames
writeVideo(diskLogger, data(:,:,:,ii));
end
close(diskLogger);
However, when I copy this code to a script and run it I get this error:
Warning: No video frames were written to this file. The file may be invalid.
> In VideoWriter.VideoWriter>VideoWriter.close at 289
In VideoWriter.VideoWriter>VideoWriter.delete at 238
In camera at 14
Error using imaqdevice/subsref (line 31)
Invalid property: 'FramesAvaialble'.
Type 'imaqhelp' for information.
Error in camera (line 16)
data = getdata(vid, vid.FramesAvaialble);
What am I doing wrong? Please help /Chris

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 2월 17일
편집: Youssef Khmou 2013년 2월 17일
Hi
1)you have an error in your code : you wrote "FramesAvaialble", it is "FramesAvailable" . correct that and try again .
2)After you get the data which is NxPx100 according your code, you can try "avifile" :
mov = avifile('example.avi')
for x=1:100
mov = addframe(mov,data(:,:,x));
end
try
doc avifile
  댓글 수: 2
Chris
Chris 2013년 2월 22일
편집: Chris 2013년 2월 22일
Thanks, correcting the spelling error fixed it.
My code was copypasted from the session log of imaqtool, so the spelling error was generated by the toolbox itself... bug report?
Youssef  Khmou
Youssef Khmou 2013년 2월 22일
hi,i am glad it works now, maybe a bug report, if you found it you can email them to rectify .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by