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

Been away, just saw your post.  I'll look at your code (all the relevant .VI files) if you Post it (if you have lots of VIs, you can compress the folder containing them and post the resulting .zip file).  If you fail to post it, then I won't be able to help.

 

Bob Schor

0 Kudos
Message 11 of 16
(2,297 Views)

Hi! I know this is an old thread, but I too have issues with the saved video playing very fast, and it happens on any codec. I'm currently trying to save video from my laptop web camera and want to potentially use it for high-resolution machine vision cameras. I have attached the code I use below.

Also, I cannot seems to find the AVI  blocks only the AVI2 blocks, as I will be needing to save files of more than 2GB. 

Any help would be appreciated, I have been spinning my head around this for weeks now.

0 Kudos
Message 12 of 16
(1,977 Views)

I'll take a look, and will try to get a video from my Laptop camera ...

 

Reply here (to bug me) if you don't hear from me in a few days.

 

Bob Schor

0 Kudos
Message 13 of 16
(1,962 Views)

Okay. Will do

0 Kudos
Message 14 of 16
(1,956 Views)
Solution
Accepted by Bob_Schor

As it turns out, I posted a "How to do this" in the Forums in August of 2019, and (fortunately) saved the code, and a Snippet, on my PC.  Before doing this, I searched the Examples that ship with LabVIEW, and found NI's "solution", which is so confusing, so completely undocumented, as to be (in my humble opinion) virtually useless to anyone without much more experience with LabVIEW (and not necessarily with LabVIEW Vision) than I.  So here's my "simplified" example, with explanation.

DEMO Selfie AVI.png

This is the routine that I called "DEMO Selfie AVI", as it uses my Laptop's WebCam to take the video, which is obviously of the person working on the computer.  I'll explain how this works, and also note a few "corrections and improvements".

 

This is structured as a Parallel Loop Producer/Consumer Design Pattern.  The upper (Producer) Loop runs the Camera, while the lower (Consumer) Loop gets single "Frame" Images from the Producer and writes them to an AVI File,

 

The Producer Loop (like many LabVIEW DAQ routines) consists of a few IMAQdx calls to define the Camera "Task", Configure the "Grab" (Video Capture), take Frames in a Loop (clocked by the Camera, here operating at 30 fps), and Closing the Camera Task on exit.  There are two changes I would suggest -- the Session In of IMAQdx Open Camera should be set by clicking the little downward Triangle and choosing a Camera that MAX finds on your PC (mine now says "cam0" -- I don't know where "WebCam" came from, unless I was using another PC when I wrote this Demo).  The other change would be to set the Number of Buffers input of IMAQdx Configure Grab to 30 (the current default is 5, which might be adequate).

 

The Consumer Loop is also a "Configure, Do in a Loop, Close" sequence for processing the Images from the Producer into an AVI file.  I created the AVI file as "My Video.avi" and placed it in the same Folder as the Demo VI (that's what the Strip Path/Build Path sequence is doing).  As the AVI file is been written, it is also being displayed on a Vision Image Display sitting on Demo VI's Front Panel.

 

To get the Images from the Producer to the Consumer, I am using a Stream "Channel Wire".  Asynchronous Channel Wires were introduced in LabVIEW 2016, and are one of my favorite LabVIEW "features", serving as a more mnemonic way of moving Data from one part of the Block Diagram to another, asynchronously (meaning "right now, without obeying the Rules of Data Flow").  Look at the output of the IMAQdx Grab2 VI.  I right-clicked on the Image Out terminal, chose "Create", then "Channel Writer", then chose the first Template, "Stream".  LabVIEW "thinks" briefly, then produces the item I call a Connector that you see in the Block Diagram that has an input for the Image Out wire and produces its "Channel Wire", which looks like a "pipe" and can exit the While Loop by simply jumping over its edge (notice it "sits on top" of the Structure boundary.

 

The Channel Wire containing the Images is brought down to the lower Consumer Loop.  I like to "snake" the Channel around so it comes in on the left ("input") edge of the Consumer's While Loop, emphasizing the "flow of data".  If I right-click the end of the "pipe" poking into the Consumer loop, I can again choose "Create", and now choose "Channel Reader", which produces the Connector that has as its output the Image that was put into the Channel in the Producer.  Wire it to the IMAQ AVI2 Write Frame, and you are (almost) done.

 

So how do you stop both loops?  You stop the Producer in the "usual way", by wiring a Stop button to its Stop terminal.  The Stream Writer has an input that Queues don't have, called "last element?".  If you also wire the Stop Button to this terminal, it will be transferred to the Stream Reader, where it can be used to stop the Consumer (at the proper time).

 

So give this a whirl.  I make no guarantees for how pleased you will be by your Selfie Image -- be sure to comb your hair!

 

Bob Schor

 

Message 15 of 16
(1,936 Views)

Oh wow! You are a god among men Mr.Bob! I have been spinning my head over this for weeks, probably more than a month now! And there was no help anywhere! I cannot express how much you have helped me and potentially sped up my work, which I hope will be of great help to many. 

I will potentially be making a few adjustments by replacing the camera input with an Imaqdx session in to allow me to select cameras in the front panel, as well as adding the option to allow the user to input the file name and choose the file path. 

Apart from that I only have one thing to say, You Are the Man! 

Thanks so much for working and figuring out a solution to a problem that I believe has had a lot of people going crazy over for a while now. Once again, thanks so very much!

0 Kudos
Message 16 of 16
(1,929 Views)