Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

IMAQ AVI2 Write Frame Issue

Solved!
Go to solution

I am trying to use the IMAQ AVI2 Write Frame vi to create a AVI file from frames generated by a PCIe-1433 and a Basler Ace series camera. 

 

Whenever I try to use the IMAQ AVI2 Write Frame vi it bogs down my applicaton. The result is that I lose frames and my program becomes unrespsonsive. I tried putting the IMAQ AVI2 Write Frame into a consumer loop hoping that if I feed it from my main loop things will speed up, but it still bogs down my program. 

 

If I take 10 seconds or so of data, and stop the program then it takes about a half hour to empty the queue and write all those frames to disk. This is just unacceptable; how do I speed up the generation of the AVI file from the frames that I grabbed?

 

My current settings on saving the AVI file are a frame rate of 30 fps, quality of 250, and using the Cinepak Codec by Radius for the encoding. The camera has both camera link cables installed, so I think I am running the camera in the full configuration mode (not base, but I'm not totally sure). I was doing 100fps earlier and that caused massive issues, so I slow the fps down. Ideally, I'd like to be able to run this at the faster frame rate. 

 

I plan to try experimenting with the fps value and the Codec to see if I can improve performance, but any input or help would be greatly appreciated.

0 Kudos
Message 1 of 15
(5,580 Views)
Cinepak is a codec from the 90's and is really slow compared to modern codecs. I suggest using one of the MJPEG options offered by the AVI2 VIs.
Message 2 of 15
(5,562 Views)

That's good to know. I'm not sure I have the codecs you are refering to. When I run the IMAQ AVI2 Get Codec Names I have the following codecs available. Are any of these the codecs you are refering to? If not, where do I get new codecs from? Are there better codecs that I could be using than the ones I have available?

 

Microsoft Video 1
Intel IYUV codec
Helix I420 YUV Codec
Cinepak Codec by Radius
Helix YV12 YUV Codec
FF Video Codec 1 (FFV1) (NI Vision)
Motion JPEG (NI Vision)
Y800 Uncompressed Grey Scale (NI Vision)
YUV 4:2:0 Planar (NI Vision)

0 Kudos
Message 3 of 15
(5,556 Views)
Solution
Accepted by GreenThumb
Motion JPEG==MJPEG.

You can also use any third-party codec that can be installed and used by AVI functions (in Windows). There are some commercial ones that exist that can use more hardware acceleration features and newer compression codecs (like H.264), but the MJPEG one included by NI Vision is pretty good.
Message 4 of 15
(5,548 Views)

Switch over to the MJPEG. It works much better. Thanks! 

 

I am also facing the issue of how to adjust my frame rate from the camera. Can this be done programttically? Its currently running at 100fps. Can I adjust this to run at 30fps?

0 Kudos
Message 5 of 15
(5,544 Views)
The easiest way to adjust the frame rate would be to use Basler's Pylon application to do so and save that setting to non-volatile memory.
0 Kudos
Message 6 of 15
(5,543 Views)

Awesome. Thank you so much!

0 Kudos
Message 7 of 15
(5,537 Views)
I had some trouble figuring out how to set the frame rate with the Pylon software. I have an email out to then for support on how to do this. I asked Basler this question, but I'll ask it here too: can Pylon communicate with the camera over the camera link cables or do I need some kind of serial cable?

if I do need a serial cable to set it then I can't change my frame rate that way because I don't have that cable. can I change the effective frame rate by having the frame grabber skip acquiring every other frame or something like that?
0 Kudos
Message 8 of 15
(5,522 Views)

There is an internal serial connection over the CameraLink cable. You can directly talk to this port through serial commands in the IMAQ API. Additionally, there is a software infrastructure called "clallserial" that camera vendor software (like Basler's Pylon) can use to talk through this serial port in another vendor's framegrabber (NI) to control the camera. You should be able to simply open Pylon and see the camera as available to be configured.

 

You could certainly write code to skip frames in software, but it would be more complex to write and also would still waste memory bandwidth DMA'ing images to host memory that you never intend on using.

0 Kudos
Message 9 of 15
(5,513 Views)

As I give this more thought, I'm starting to think that changing the frame rate might not be the solution to my next problem. 

 

Changing the codec to the MJPEG seems to help both the time needed to save each frame to the AVI file and other issues I was seeing such a jitter (not sure the technical term, but I think I had jitter from some frames not getting written to the AVI file?). Despite the improvements from using the MJPEG codec, the video still doesn't playback as I'd expect. 

 

I tried collecting about 5 seconds of video. During this collection, my camera was running at about 100fps (99.7 or something like that), and I was generating the AVI file to playback at 100fps. I thought that this would generate an AVI file that showed the 5 seconds of video in "normal" time (not slowed down or sped up). However, when I play the AVI file back it is sped way up and doesn't look natural at all. For example, in the first second or two of the video I waved my hand around in front of the camera. When I playe dthe AVI it showed my hand moving way faster than I moved it during the aquisition. I don't even think I could move my hand as fast as it was moving in the AVI movie. Smiley LOL

 

Even though I am generating at 100fps should I play back at 30fps to get the "natural" time look to the video or do I have something else set up incorrectly? Basically, how should I have things setup to give the natural look for video playback when recording at 100fps?

0 Kudos
Message 10 of 15
(5,506 Views)