Example Code

DirectShow .NET LabVIEW SDK (Video, Audio, IP streams)

Code and Documents

Attachment

Inspired from LabVIEW portal - reference link

 

Library and examples provided as is, minor bugs (aka. features) included but still can be useful for someone who needs to acquire, compress and edit video/audio streams from various sources, directshow compatible devices and internet streams.

Works with GigE cameras if manufacturer provides directshow compatible filter. (Tested with Basler family).

DirectShow has a steep learning curve but once you get familiar with GraphEdit then samples from internet and examples from below should be sufficient to create sophisticated applications.

 

To back check your LabVIEW creating add

DsROTEntry.png

Wire it to your FilterGraph and open in GraphEdit program for inspection and debugging.

 

Requires:

Microsoft Windows SDK - download

Directshow.net library - download

DirectX.Capture class library - download

References:

MSDN DirectShow documetation

DirectShow Debugging/ConceptProofing Tools:

GraphEdit (Microsoft Windows SDK)

 

Alphabetical and Numerically Logical String Array Sort for user menu facelift

 

BEFORE Opening any vi make sure you have in the same directory:

DirectShowLib-2005.dll

DShowNET.dll

DirectX.Capture.dll

logicalstringarraysort.llb

 

Great links:

 

H.264 CUDA Encoder directshow filter -> Examples Added 02/16/2013

Directshow virtual video capture source - aka printscreen

Other articles from Maxim Kartavenkov

 

02/16/2013 Update

 

H264Encoder requires:

  • BaseClassesNET.dll
  • H264Encoder.dll

 

I went with wrapper mode implementation. Check Maxim Kartavenkov forum for details.

H264 CUDA Encoder directshow filter example can be done entirely in BaseClassesNET.dll. Which might be done one day...

No error checking on CUDA capabilities.

Use with Nvidia GPU's only

H264.png

Examples:

  • Capture Video and H264 CUDA.vi
  • Render Media Stream.vi

 

Updates to Library:

  • Add H264 CUDA Filter.vi
  • Create AviMux.vi - overrite file option added
  • Enum Pin Media Type.vi
  • Enum PinMediaTypes.vi
  • Enum Pins.vi
  • Free PinInfo.vi
  • H264 CUDA Get Filter Options.vi
  • H264 CUDA Set Filter Options.vi
  • H264 Object Wrapper.vi
  • H264 Settings.ctl
  • Media Mode.ctl
  • Media State.ctl
  • MediaFormatType to String.vi
  • MediaSubType to String.vi
  • MediaType to String.vi
  • AMMediaType to String.vi
  • Picture Snap (32-bit RGB Image).vi - updated auto init
  • Picture Snap (DIB Image).vi - updated auto init
  • Set Sample Grabber.vi
  • WaveFormatEx.ctl
  • Capture.vi - updated to reflect above changes
  • Minor tweaks

 

02/07/2013 Update

 

 

Examples:

 

  • Acquire Video.vi
  • Acquire Audio.vi
  • Acquire Video plus Sample Grabber.vi
  • Capture Video.vi
  • Capture Video with Preview.vi
  • Capture Video with Preview and Sample Grabber.vi

Acquire Video.png

Acquire Audio.png

Acquire Video plus Sample Grabber.png

Capture Video.png

Capture Video with Preview.png

Capture Video with Preview and Sample Grabber.png

 

 

Updates to Library:

  • Release Object.vi
  • Init Capture Preview.vi
  • Configure Capture plus Preview.vi
  • Configure Video with Sample Grabber.vi
  • Media Control - StartStopPause.vi

 

 

 

Updates to Capture.vi

  • Preview in Capture Mode
  • Proper Objects release upon start/stop/exit

DS Capture.png

Update 10/08/2014:

DShow - JPEG dump example.

 

-Artur

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
D*
Member
Member
on

FYI, DirectShow is compatible with LabVIEW natively : http://www.ni.com/white-paper/10111/en

GriffinRU
Member
Member
on

This is more advanced library which expands NI Vision avi subvi's and it is free...

Source code is available for cross-checking and editing.

Excellent debugging tool (graphedit) and sufficient online documentation.

Significant performance improvements due to proper rendering and avoiding memory transfer bottlenecks...

-Artur

Igor_Titov
Member
Member
on

Actually, DirectShow is compatible with LabVIEW via IMAQ (not "natively")... Which also contains calls to DirectShow, just like in this very implementation (though I'm not sure that it's done with connecting to .NET). But NI Vision is not free, plus it's quite far from being ideal... So, DirectShow .NET LabVIEW SDK is a very useful tool to check out (IMHO).

dirtyb15
Member
Member
on

Had a couple of questions.  First where can i get

  • BaseClassesNET.dll
  • H264Encoder.dll

Second, i am really just trying to decode a h264 video file in labview, do some operations, then re-encode.  Is this possilbe using this tool kit?  Thanks so much for any help.


GriffinRU
Member
Member
on

You can download them from CODEPROJECT site links provided above. (http://www.codeproject.com/Articles/421869/H-264-CUDA-Encoder-DirectShow-Filter-in-Csharp)

With my examples and toolkit you should be able to extract frame -> manipulate with it and save it again as video.

An example on how to do that would come later, I am currently occupied with different project and set this development temporary on hold...

Secondly you should be able to read AVI file encoded with H264 directly with IMAQ... so you might do not need that at all, unless you are trying to accomplish more than IMAQ tools allow you to.

My original goal was to provide means to encode video with 3rd party compressors and/or provide interface to tune compressors available accessible with IMAQ AVI library. In process a lot more features become available as result, and it is almost impossible to provide example for every case. So I will try to add examples as per request or as I am going with my projects requirements. So far there were no need for me to do re-encoding, there are plenty well developed 3rd party video editing tools.

What is coming soon with version 2.0 is support and examples for .wmv with some bugs fixes and some minor improvements.

-Artur

Ting1224
Active Participant
Active Participant
on

Hi Artur,

This library is so sick and it's exactly what I am looking for.

I download it and play it around for a while.

It seems that there's no way to acquire an image and then convert to the IMAQ format so that we can utilize NI Vision Development Module for further processing.

Also, it's a pity that we can only use CUDA library for h.264 encoding.

Do you have any generic CPU solution to encode the images to video no matter using DirectShow library or native IMAQ acquisition?

I am not a guy that know how to program in dotnet. Thanks for another thread to show us how to convert IMAQ to Bitmap so that I can use a third party vision library in LabVIEW.

In this thread, it would be perfect if we can achieve DirectShow for acquisition, NI VDM for processing, and CPU h264 encoding.

Thank you for sharing

Ting

GriffinRU
Member
Member
on
GriffinRU
Member
Member
on

"In this thread, it would be perfect if we can achieve DirectShow for acquisition, NI VDM for processing, and CPU h264 encoding."

You can do CPU encoding with DivX and Xvid already.

-Artur

Ting1224
Active Participant
Active Participant
on

Hi Artur,

Do you have the link to the CPU encoding with DivX and Xvid using LabVIEW?

I really would like to take a look.

Thank you

Ting

GriffinRU
Member
Member
on

Hi Ting,

Over IMAQ avi library:

  • Download and Install DivX Plus Codec Pack
  • Obtain compressor name from "IMAQ AVI Get Filter Names.vi"
  • Pass compressor name to "IMAQ AVI Create.vi"

You cannot modify compressor parameters in LabVIEW, it would use default settings or last (depends on compressor). Compressor properties can be edited with interface provided by developer. It is possible programmatically to call given dialog and then hijack window and programmatically overwrite values, apply changes and close window... start capture -> just not clean, nor easy.

Same can be done with FFmpeg

and same true about settings...

I use both compressors in LabVIEW without problems. I haven't used Xvid but assume that it should be similar to DivX.

Over DirectShow library:

Download and install Xvid codec or previously mentioned compressors.

Pass compressor pointer to ICaptureGraphBuilder2 (pfCompressor pin).

You can alter parameters with "DirectShow - Property Dialog.vi" by providing the same pointer, see "DirectShow Capture.vi" as example.

Tested DivX, Xvid and FFmpeg, with positive results (Note for Xvid: make sure you set encoder to be hidden when in use, otherwise encoder progress window end up left behind and hangs the process, not sure whom to blame. But once set to be hidden - no problems, and why would you like to see it anyway). But from pure performance issues end up using CUDA.

-Artur

GriffinRU
Member
Member
on
Ting1224
Active Participant
Active Participant
on

Hi Artur,

I followed your procedure and installed both DivX and Xvid codec.

However, I am not able to obtain the filter name through "IMAQ AVI Get Filter Names.vi"

GetFilter Names.pngFilters.png

After some surverying through NI web, I found this thread mentioned that not all codec installed on the computer actually show up in the list.

Could you tell me how do you make the filters shows up using the "IMAQ AVI Get Filter Names.vi"?

If there are no other specific ways, I'll try using the latest Vision Acquistion Software 2013 which has the new "IMAQ AVI2 Get Codec Names.vi" included. You can check this whitepaper for some latest news.

If I got any new progress using the new VAS, I'll post the result here for everybody's reference.

Thank you

Ting

GriffinRU
Member
Member
on

Try to wire "DivX 6.9.2 Codec (n Logical CPUs)" to compressor pin...

Where "n" number of CPU cores. To verify name you can use my DirectShow library or GraphEdit program.

DivX.png

DivX2.png

-Artur

GriffinRU
Member
Member
on

Hello Ting,

Did some testing last night on win7 64bit and looks like you and folks from other thread are correct NI Vision AVI library fails to execute properly with DivX even if it is on the list of available filters, while some system do not enumerate it properly and as result locking LabVIEW for good...

So looks like you have only DirectShow library for CPU encoding or search for another NI friendly 3rd party encoder.

Sorry for misleading, but it was working for me some time ago under winxp 32bit and older version of DivX, by the way same goes for ffmpeg,..

some cool features were striped and never version is so limited that is not useful anymore.

but looks very similar in what NI vision AVI2 offers...

Artur

P.S. Do you need DirectShow example on how to utilize DivX

Working version of ffdshow was 1681 Dec 5 2007 if you lucky you can find it somewhere - works GREAT!!! Still runs on one of my WinXP machines...

GriffinRU
Member
Member
on

Check out this link with ffshow in zip file

-Artur

GriffinRU
Member
Member
on

Hello....,,,,,,,,,,,,,,,,,,,,,,,NI approval office,,,,,,-> anybody home?

GriffinRU
Member
Member
on

I think comments web script is broken...

I haven't seen any updates since last week................

Ting1224
Active Participant
Active Participant
on

Hi Artur,

I installed another codec pack from here.

Then I found that the x264vfw shows up in the filter list.

However, the new "IMAQ AVI2 Get Codec Names" doesn't show anything. I think it didn't improve but make things worse.

Filters2.png

The interesting thing is that the x264vfw actually works. I tuned the configuration as follows.

x264 setting.png

Be sure to make the basic setting to very fast, or the encoder cannot catch up with the 30 fps.

Zero Latency has also need to be checked up to eliminate warning message.

By the way, 64 bit OS with 32 bit LabVIEW can only utilize 32 bit filter. You are not going anywhere to tune the 64 bit filters' configuration.

It's funny to have the h264 in the AVI container instead of a MKV file, but it actually works on my player. (PotPlayer)

Also, I think for now this is the easiest solution for me to stay with the NI VAS without too much headache.

I am going to try your DivX solution. It looks so sick too. I think the advance users will benefit from this thread a lot.

Thank you for the help.

Ting

Edwyn15
Member
Member
on

Hello,

Is there a way to overlay a transparent background picture on top of the video?

GriffinRU
Member
Member
on

Sorry for late responce, missed your question somehow...

Yes, it is possible to manipulate with frames as they passing by sample grabber, but not without external DLL in LabVIEW.

For more information check "GSSF" folder under "Misc" samples in DirectShowSamples or directshow forum.

-Artur

fabnoiry
Member
Member
on

Hi,

I download this driver and i use it with pro intensity card and it works very well.

But now i'm trying tu use it with AVerMedia C127 card but it doesn't work.

I'm creating a graph with graphedit and it works. The only problem is that  i need to use crossbar filter see below

GraphEdit For Aver C127.png

I m trying to control my card with DirectShow Capture.vi on DirectShow SDK.llb

Someone has still with problem or idea to help me

Thanks a lot

Fabien

GriffinRU
Member
Member
on

Hi,

Without hardware it would be difficult to debug this, but instead of using "DirectShow Capture.vi" I would start with "Video Capture.vi" and edit it to match your video hardware. And back check your coding with GraphEdit by "DsROTEntry" node.

-Artur

BruceMoyer
Member
Member
on

I'm also trying to get this to work with an Intensity Pro card but I just get a black image (it seems as though I am not getting any frames).  Any advice?

Thanks,

Bruce

GriffinRU
Member
Member
on

Hello Bruce,

Does it work in GraphEdit?

If yes, try to build the same in LabVIEW.

-Artur

BruceMoyer
Member
Member
on

Okay, I was able to get video using GraphEdit (see below) and now I am trying to make the same connections in LabVIEW.

GraphEdit (BlackMagic).png

I took the Acquire Video example and inserted a new VI from the AVI Decompressor block (AVI Dec block, diagram below) and changed the renderer from "DirectShow - Create Video Mixing Renderer9.vi" to "DirectShow - Create Video Renderer.vi" but it still doesn't show video.  What am I still missing?

Acquire Video diagram (mod1).png

Create AVI Decompressor diagram.png

GriffinRU
Member
Member
on

Hello Bruce,

Add ->

https://decibel.ni.com/content/servlet/JiveServlet/showImage/102-26402-8-37688/DsROTEntry.pngright after IMediaControl -> hit "Run" -> open GraphEdit -> File -> Connect to Remote Graph.

Attach image.

-Artur

P.S. Are you getting AVI stream from camera?

Not sure why you need "AVI Decompressor" if it is RGB (or similar) "Video Renderer" should be able to connect directly to capture pin. Have you tried in GraphEdit to add your video device and then just right click on capture pin and select render pin?

BruceMoyer
Member
Member
on

I connected it and ran the VI, went to FilterGraph and the Connect to Remote Graph window doesn't show any remote graphs.

Acquire Video diagram with DsROTEntry.png

Remote Filter Graph to View.png

BruceMoyer
Member
Member
on

When I do what was suggested in the P.S. the colors are not right.

ActiveMovie Window (Render).png

GriffinRU
Member
Member
on

Bruce,

Have you registered GraphEdit dll's...->

http://msdn.microsoft.com/en-us/library/windows/desktop/dd407274(v=vs.85).aspx

We will address colors later...

-Artur

BruceMoyer
Member
Member
on

The AVI Decompressor was actually inserted automatically in the FilterGraph.

I have not registered the dll's yet because my company is very restrictive and requires permissions to be granted for my computer.    I'll let you know when I get the dll's registered.

BruceMoyer
Member
Member
on

So I registered the dll's for FilterGraph am now able to view more of the properties in FilterGraph and things seem to be working a bit better in FilterGraph, but when I try to connect to a Remote FilterGraph, I see the remote graph, but when I select it I don't see the full chain I'm expecting.

ActiveMovie Window 2.png

GraphEdit (BlackMagic) (v3).png

Remote Filter Graph to View 2.png

Remote FilterGraph (LabVIEW).png

GriffinRU
Member
Member
on

Ok,

Looks like you have pin names mismatched. Try to get pins by name (get actual name from GraphEdit or enum pins) instead of "Capture" or "Input". Also, check if you have any errors adding AVIDecompressor, it should be somewhere on GraphEdit if added properly but not connected.

Note:

You do not need to build entire Filter Graph to see it in GraphEdit, build step-by-step and check how it grows in GraphEdit, while correcting errors (do not forget to clean up, i.e. remove entry after you done with it).

-Artur

BruceMoyer
Member
Member
on

Thanks for your continued help and replies.  I was able to use the pins to connect (instead of capture) and I now see the remote graph connect although I still do not get video in LV.  In Filter Graph I need to setup the properties of the BlackMagic WDM Capture filter in order to display video.  How do I make sure the properties are setup correctly using LabVIEW?

Since you have this working with BlackMagic, is it possible to get a sample VI?

GraphEdit (BlackMagic) remote.png

GriffinRU
Member
Member
on

Hello Bruce,

You should be able to do that over "DirectShow - Property Dialog.vi" or over Get/Set "DirectShow - Current Video Format.vi" programmatically.

You can always check properties in GraphEdit by right-clicking on pin, after you created the chain in LabVIEW.

I haven't work with BlackMagic, but I can take a pick on your VI and help you out.

-Artur

BruceMoyer
Member
Member
on

I didn't realize until now that in the DirectShow SDK.llb there's a DirectShow Capture.vi that is a full-fledged example!  Now I'm getting somewhere, I am able to get video into LabVIEW.  All this time I've been trying to get the example VIs in the DirectShow Examples.llb to work without success.

GriffinRU
Member
Member
on

Sometimes more complicated example can be more helpful...

-Artur

Saswati
Member
Member
on

hello,

I was trying to run your application. But I get constructor error at Filter Graph, error 1386.

I have all the dll needed. Could you please help.

GriffinRU
Member
Member
on

Hello,

Have you tried to add constructor manually, from dll?

Are you running 32-bit or 64-bit LabVIEW?

Windows version?

-Artur

Saswati
Member
Member
on

Hello Arthur,

sorry for late reply. I am using 32 bit labview 2013. Running on windows 7.

To give you a bit more details if the error, I get it in Create filter graph vi and it is as follows :

Code 1386 , Constructor Node in directShow - Create filter graph .vi . The specified .NET class is not available in labview.

i have created a directshow code in visual studio but i want to explore it in labview, although I am not that knowledgable with COM and directshow.

Could you please explain you first point of adding constructor manually?

Saswati

GriffinRU
Member
Member
on

Hello,

  • Functions/Connectivity/.NET - drop constructor node on block diagram
  • In "Select .NET Constructor" dialog, click Browse button and select "DirectShowLib-2005.dll"
  • Once selected as DirectShowLib-2005(2.1.0.0) search for FilterGraph
  • Place on Block diagram

Let me know if you have any problems at this point.

-Artur

Saswati
Member
Member
on

Hello,

I did as you mentioned the only difference being i am using DirectShowLib-2005(2.0.0.0) instead of 2.1.0.0 as said.

Unfortunately I still get the same error.

Saswati

GriffinRU
Member
Member
on

Hello,

Can you load "DirectShowLib-2005.dll" into LabVIEW?

Can you select FilterGraph?

Have you installed all required software?

-Artur

Saswati
Member
Member
on

Hi Arthur,

Everything works now. The problem was the way I was loading the dll's.

thanks

Saswati

GriffinRU
Member
Member
on

You welcome,

-Artur

Saswati
Member
Member
on

Hi Arthur,

Now that it all works alright, I wanted to share my requirement with you.

I want to create a avi from a number of bitmap images or png, whatever is convenient.

I have written a code in COM using the pushsource filter provided in windows SDK to read the bitmap images from a directory and create an avi.

I was wondering if that can be done with labview and was wondering how to do the pushsource filter or any otherway out.

My filtergraph sequence is as follows:

Pushsource -> AviMux -> AviCompressor -> Filewriter.

Thanks

Saswati

GriffinRU
Member
Member
on

Hello,

If you can do that in GraphEdit, than you can automate this process in LabVIEW.

You can do that with Vision AVI palette as well, if you just need to stitch images to avi.

-Artur

CuriousCoder
Member
Member
on

I have been trying to use the SDK to invoke the directshow property pages, as the drivers I have do not expose the exposure property in a way labview can access, but they are present in the capture pin/filter dialogues. If I try to use the menu items I get the following error:

Error 1172 occurred at Invoke Node Error calling method DirectX.Capture.DirectShowPropertyPage.Show, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

    Inner Exception: System.DllNotFoundException: Unable to load DLL 'olepro32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E))

Possible reason(s):

LabVIEW:  A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation.

System.DllNotFoundException in DirectShow - Property Dialog.vi->DirectShow Capture.vi

If I then regsvr32 olepro32.dll I get:

Error 1172 occurred at Invoke Node Error calling method DirectX.Capture.DirectShowPropertyPage.Show, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

    Inner Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))

Possible reason(s):

LabVIEW:  A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation.

System.BadImageFormatException in DirectShow - Property Dialog.vi->DirectShow Capture.vi

I am using Labview 2013 64bit on Windows 7 Enterprise, can anyone advise how I can fix this?

Thanks,

Oliver

GriffinRU
Member
Member
on

Hello Oliver,

I do not have 64-bit LabVIEW at the moment, but what you discribing is related to using 32-bit library on 64-bit target. I haven't used 64-bit LabVIEW, but if you can verify/set identification of this library as 32-bit -> that might solve your problem. And do not register 32-bit library on 64-bit machine, run in compatability mode instead.

Other options:

  • 32-bit LabVIEW
  • Ask sourceforge.net developer to create 64-bit version

-Artur

Sergiv
Member
Member
on

Could you show an example of a video capture from a video stream? for example, rstp

GriffinRU
Member
Member
on

Hi,

Have you tried "DirectShow - Example - Render Media Stream.vi"? (default stream doesn't work anymore, but you can find mms stream online, i.e. mms://live1.wm.skynews.servecast.net/skynews_wmlz_live300k

As far rtsp streams, you can use 3rd party rtsp filter or directshow filter provided by camera manufacture.

-Artur

Contributors