views:

1514

answers:

4

I would like to know how I can record a video in MATLAB with my webcam.

+2  A: 

If you already know how to capture a single image from a webcam, then it should just be a matter of stitching the images together into a movie. You can convert an image file to a movie frame using IM2FRAME, then you can use AVIFILE to create a video file from the frames. Here's how the code might look:

aviObject = avifile('myVideo.avi');   % Create a new AVI file
for iFrame = 1:100                    % Capture 100 frames
  % ...
  % You would capture a single image I from your webcam here
  % ...
  F = im2frame(I);                    % Convert I to a movie frame
  aviObject = addframe(aviObject,F);  % Add the frame to the AVI file
end
aviObject = close(aviObject);         % Close the AVI file

I just used a for loop as a simple example, but you may want to use a MATLAB Timer Object if you instead want to capture images and add them to the AVI file at regular time intervals.

gnovice
A: 

It is not clear to me from the question if you are trying to use a web cam to record your MATLAB session (probably not, but I see people doing it). All of my videos are screen captures made and edited with Camtasia.

MatlabDoug
A: 

Here you can see great videos how to capture and process the images from webcam, so recording shouldn't be hard:

http://blogs.mathworks.com/videos/2008/01/18/cool-feature-video-processing-demos/

Gacek