LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i save video file from USB camera in labview?

Solved!
Go to solution

Hello,I have acquired the video using IMAQdx and now i'm asking how can i save this video on file,and how can i start and stop saving? thank you for answering me its urgent.

0 Kudos
Message 1 of 16
(7,669 Views)

Well, I must confess I was going to say "Look at the Examples that come with LabVIEW", but they're (basically) terrible.  So here's a walkthrough:

 

First, you need video Images, which (as you've noted) you can get with IMAQdx.  You've already been introduced to the (poorly-explained, in my opinion) concept of the IMAQ Buffer, a data structure that holds the actual Image and is needed to move the image around.  What you are going to do is open an AVI File, assign it to a particular Codec, and then write the Images one at a time to the AVI file until you're done, when you close the file.  Most of the Functions I'll describe are in the Vision Utilities/Files sub-Palette.

  • IMAQ AVI2 Create -- this is the AVI "File Open" routine, which takes a Path to the to-be-created AVI File (use extension .avi, of course).  The Frames per Second input describes the rate at which the Frames will be played when the AVI is viewed.  There are a number of encodings (Codecs) you can use to encode your video -- I recommend, as a default, "Motion JPEG (NI Vision)".  Unfortunately, this is a String input (instead of an Enum) -- I'm not sure what happens if you don't spell/capitalize it exactly that way ...  The output from this function is a File Reference, not unlike what you get when you use a "ordinary" File Open/Create.
  • Now, in a loop, you get (from your Camera or somewhere else) a Frame in an IMAQ Image buffer and wire it (and the File Reference from the previous step) to IMAQ AVI2 Write Frame.  Continue until you are all done.
  • Finally, close the AVI file with IMAQ AVI2 Close.
  • You should now be able to double-click on the File you just made and view it at the Frame Rate you chose in the first step (assuming you have software capable of playing AVIs).

Good luck.  If you have any troubles carrying this out, attach your VI and someone will help you.

 

Bob Schor

Message 2 of 16
(7,634 Views)

Hi there, 

 

Thanks for the great explanation, Bob. I just wanted to add, that if you plan to acquire AVI files that are over 2GB in size, you should use the IMAQ AVI functions instead of the IMAQ AVI2 functions. There is a 2GB limitation with the AVI2 functions that our team is aware of, but is not commonly known outside of NI. Just wanted to give a heads up in case you need files over 2GB!

Thanks,

Rita Prather
Software Product Manager
rita.prather@ni.com
National Instruments
0 Kudos
Message 3 of 16
(7,596 Views)

Thank you for your answer it had really help me, this is what i did in the VI attached,i still have a problem that the video saved passed very quickly and not in its normal speed. 

0 Kudos
Message 4 of 16
(7,586 Views)

In AVI2 Create, you need to specify a Codec.  I don't know what Codec is used if you leave it blank, but I tried your code and it did run fast.  I used Motion JPEG (NI Vision), and it worked just fine, seemed to even have the correct timing.  And was a factor of 10 smaller than the earlier file that ran "too fast".  Try adding the Codec and see if it fixes your code.

 

Bob Schor

0 Kudos
Message 5 of 16
(7,581 Views)

I didn't know how to create Motion JPEG in the codec,please if you can help me and modify this VI from me,thank you so much.

0 Kudos
Message 6 of 16
(7,558 Views)

I didn't know how to create Motion JPEG in the codec,please if you can help me and modify this VI from me,thank you so much.

0 Kudos
Message 7 of 16
(7,557 Views)

@Bob_Schor wrote:

In AVI2 Create, you need to specify a Codec.  I don't know what Codec is used if you leave it blank, but I tried your code and it did run fast.  I used Motion JPEG (NI Vision), and it worked just fine, seemed to even have the correct timing.  And was a factor of 10 smaller than the earlier file that ran "too fast".  Try adding the Codec and see if it fixes your code.

 

Bob Schor


Here is a picture that is your VI with the change I suggested in the above response:

Save AVI.png

Bob Schor

Message 8 of 16
(7,548 Views)
Solution
Accepted by topic author touitou

@touitou wrote:

I didn't know how to create Motion JPEG in the codec,please if you can help me and modify this VI from me,thank you so much.


Sorry, I'm "on the road" and didn't carefully read your question.  There's a function on the AVI Palette called IMAQ AVI2 Get Codec Names that returns an Array of Strings.  I simply chose (and exactly copied) the Motion JPEG string.  On my system, this is the function and its result:

Get Codec Names.pngCodec Names.pngBob Schor   

 

0 Kudos
Message 9 of 16
(7,530 Views)

@Bob_Schor wrote:

In AVI2 Create, you need to specify a Codec.  I don't know what Codec is used if you leave it blank, but I tried your code and it did run fast.  I used Motion JPEG (NI Vision), and it worked just fine, seemed to even have the correct timing.  And was a factor of 10 smaller than the earlier file that ran "too fast".  Try adding the Codec and see if it fixes your code.

 

Bob Schor


Hi, I have the same problem, I have tried using Motion JPEG (NI Vision) as it codec but the results are my video still too fast, do you have any advice?

0 Kudos
Message 10 of 16
(5,714 Views)