LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Error creating AVI file" when using x264 codec with IMAQ avi functions

I'm trying to export x264 compressed movies from Labview using the IMAQ avi functions of the Vision module, but I can't get it to work with the x264 VFW (video for Windows) codec. I use Labview and Vision version 2023 Q1. The latest version of the x264 VFW codec (2.00) from the official source shows up in the IMAQ codec list (IMAQ AVI2 Get Codec Names) for both 32bit and 64bit Labview:

Novgorod_0-1686334344241.png

Older versions of the codec (version 44 from 2017 and below) don't show up in the list at all (both 32bit and 64bit). I can select the codec and run IMAQ AVI2 Create without error, which creates an empty avi file. But as soon as I try to write the first RGB U32 image to the avi file (IMAQ AVI2 Write Frame), I get "Error creating AVI file". All other available codecs run without issues (except for the built-in VP8 and VP9 codecs which are extremely slow, but that seems to be a known bug). The "quality" parameter doesn't change the behavior and it's also not a file path issue (I tried with an avi file directly on C:\ without spaces or special characters in the path). I get the same behavior on 2 different machines, one with Windows 11 and one with Windows 10 (otherwise same software versions).

 

What can cause the error with the x264 codec? Any information on x264 with Labview I could find is many years old and it looks like the older x264 VFW codec versions were working fine, so maybe it was broken in a recent Labview/Vision version? What other x264/h264 codec can I try which is compatible with the current IMAQ avi functions? I really want to get it to work with IMAQ because it's by far easier than using external x/h264 libraries like ffmpeg or cisco or (god forbid) the Windows Media Foundation API...

0 Kudos
Message 1 of 6
(1,436 Views)

I also tested it in an old Windows 7 VM with Labview (and Vision) 2018 - exactly the same behavior.

0 Kudos
Message 2 of 6
(1,394 Views)

I can confirm that LabVIEW 2021 does not list the H264 codec for AVI files with IMAQdx.  I believe it is also called MPEG-4, which one could find on the LabVIEW Tools Network (VIPM), but you needed to purchase a license.  I haven't installed more recent versions of LabVIEW, so it is possible that you have a "not-quite-working" Codec installed.  Might be worth a Service Request.

 

Bob Schor

0 Kudos
Message 3 of 6
(1,372 Views)

I think you're talking about the (very old, very expensive) Multimedia for Labview package, which is basically just a wrapper DLL for an old ffmpeg version. There's also the (equally old but free) DirectShow .NET Labview SDK which uses an old DirectShow wrapper DLL, but also includes another .NET wrapper for the H264 encoder built-in in Windows (I think) with CUDA support, so kind of the Media Foundation route in a convoluted way. I think the latter could be a viable option if everything else fails - or just embrace the pain and use Media Foundation directly through the .NET wrapper (using only the H264 encoder might be still "manageable" though).

 

In any case, I'd really prefer a simple solution through a VFW codec, but the Vision avi encoder is completely undocumented, so it's just guesswork what codecs are compatible. Some (like ffdshow VFW) even cause Labview to crash when enumerating the list of codecs...

0 Kudos
Message 4 of 6
(1,351 Views)

I am having a similar problem, to open an AVI file.
Is there any progress on this topic?

0 Kudos
Message 5 of 6
(916 Views)

I ended up implementing the Media Foundation interface (MFExtern) completely in Labview through the MFLib (v3.1) .NET functions, which is a hot mess (a little excerpt is attached). There are various tutorials how to do it in text-based (C-like) languages, including directly from Microsoft along with the interface documentation. I only implemented a tiny part to export frames as a H264 or H265 file (video only) with user-definable bitrate. Reading frames from a file should be very similar using the create source reader methods instead of the sink writer.

WMF.png

0 Kudos
Message 6 of 6
(876 Views)