LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

AVI refnum with Get File Size

Highlighted

Using LV2014 w/Vision 2014.

 

While saving frames to an .avi file, I want to check the file size prior to each frame write to make sure to not go over the limit.  LV won't let me wire an AVI Refnum to the Get File Size file input (broken wire, incompatible type).  When I connect a regular file (binary, text, etc.) refnum - no problem.  Any idea how to get around this?

 

==============================================

0 Kudos
Message 1 of 4
(711 Views)

Not easily.  An AVI Write is not like a "normal" file Write, as AVI files use compression (in both time and space) to optimize the transfer of pixels to file.  Because AVI files are so data-dependent, you can't easily determine file size.  The trick of closing, sizing, reopening, and "adding to the end of the file" won't work for AVI, as it needs to have the "recent history" in order to do its compression.

 

What you could do is to record videos for set periods of time, using subjects similar to what you'll really be recording (as the size will be scene-dependent).  Now plot File Recording Time vs File Size, and make a model of the resultant function as your "best estimator" of Time vs Size.

 

Bob Schor

Message 2 of 4
(686 Views)

Hi Dave,

 

Bob's answer will give you the most accurate estimate of file size over time, but you can also roughly estimate the file size based on the frame rate, resolution, and bit depth. For example, if you have a 600x800 image with U8 bit depth, you can estimate that each frame will be 600*800*8 ~ 480 kilobytes and restrict an AVI to however many frames compose the maximum AVI size. 

 

Another option is to stream video to disk and write to AVI in post-processing. When you stream to disk, you can use a binary file as an intermediary file and limit the size of the binary file to be under the maximum AVI size. The resulting AVI will be smaller due to compression, but it will prevent you from exceeding the maximum AVI size and losing data. Streaming to disk and post-processing will also give you a more stable frame rate since writing to a binary file is much less computationally intensive than writing to an AVI file. We have an example program that demonstrates how to stream AVI to disk, which I can link you to below:

 

 

IMAQdx Record Video to Binary and Convert to AVI

https://forums.ni.com/t5/Example-Program-Drafts/IMAQdx-Record-Video-to-Binary-and-Convert-to-AVI/ta-...

 

I hope this helps!

Austin
Product Support Engineer
National Instruments
0 Kudos
Message 3 of 4
(657 Views)

I like Austin's idea!  Note when you decide to write AVIs, you have a number of Codecs you can use, each of which has their own tradeoff between compression-in-space, compression-in-time, ultimate size-of-file, and speed of operation.

 

Note that Austin's Method will probably initially take the most disk space for the Binary Images, as nothing is compressed, so this is best saved on a (large) "Scratch" area, like a 1T USB Drive.  Once you have the binary images, you can choose the AVI compression method that works best for you.

 

You can also use Austin's Method to determine the optimal AVI algorithm for direct recording.  Record, say, 10 minutes of (typical) Video using Austin's Binary Write.  This is your "data set".  Now try various forms of creating AVI files, using different Codecs, different values of Compression, etc., to get an idea of the size you can expect with your data.  You can also create "sub-files" for testing, i.e. the first minute of the Binary Images, or the first 10 seconds, and see how well the AVI size scales with the length-of-time of the recording (it might not be linear).

 

Bob Schor

0 Kudos
Message 4 of 4
(650 Views)