Example Code

VLC scripting in LabVIEW

Code and Documents

Attachment

VLC media control's ActiveX (while great under Internet Explorer) crashes LabVIEW upon insertion (LabVIEW Vers. 09/10/11/12 - R&D - any ideas why?), and functionality is limited due to security attributes applied to ActiveX itself. With examples below much more advanced features can be accessed and utilized while building interface in LabVIEW enviroment.

Requires VLC media player installed. No Error check provided if VLC not installed

Tested under Windows XP/VISTA/7 32bit and 64bit

Get Program Location (path).vi was created to simplify integration into 32-64 bit systems, other methods can be used or constants can be wired instead.

Supports:

  • Video/Audio file playback
  • IP cameras stream playback
  • DirectShow playback
  • Video/Audio streaming
  • Video/Audio encoding/decoding
  • see more details on VideoLAN forums and documentations

VLC media player can be used with command prompt (.NET implementation):

VLC dotnet scripting.png

Process refnum can be used to control VLC application, i.e. proper closing (close main or kill process methods)

Note: --drawable-hwnd command from command prompt doesn't work properly, VLC media player end up creating it's own Direct3D output window. Tryied to create non-LabVIEW generated windows over API/DOTNET/VB scripting with no success. (with or without WS_CHILD and WS_CLIPSIBLINGS flags).

Or over DLL (example where VLC embedded into LabVIEW window):

VLC Embedded.png

Check for tipstrips...

Update: 8/19/2013

VLC - Fullscreen.vi - example how to pass options to VLC media player and fullscreen option.

Update: 7/30/2014

VLC - Convert Video to mp4.vi - example how to convert video file for Iphone/IPad playback (Web hosting)

Update: 8/19/2014

VLC - Play Stream&Snapshot.vi

Update: 9/03/2014

VLC - Save Stream.vi - save video stamp with text and logo

Note: snapshot function doesn't work...https://forum.videolan.org/viewtopic.php?f=14&t=104610

One of the solutions can be to use 'scene" filter instead...

Update: 08/31/2015

VLC - Play Stream&Snapshot&speed.vi

-Artur

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

Comments
GriffinRU
Member
Member
on

Hi Daniel,

You do not need to use activeX controls with this examples, all what you need is VLC installed.

You should be able to pass VLC commands with either script example or DLL call - check script options in VLC:

  • Open VLC
  • Menu -> Convert/Save -> select source (File/Disk/Network/Capture Device) -> click "Show more options -> script to pass resides in "Edit Options" ->

Or

  • Open VLC
  • Menu -> Stream...

Let me know, if you need help.

-Artur

Ancle
Member
Member
on

Dear Artur,

You are very kind to everyone. Last time I asked you how to play mov files. Finally, I got a file. That's combine from mov files. And I used  "libvlc_media_player_set_position", it works fine. Thank you again.

B/R

Ancle

GriffinRU
Member
Member
on

VLC video convert to MP4 script:

VLC - Video convert.png

-Artur

Jochen_B
Member
Member
on

Hi Artur,

nice work. I am trying to embed a video stream from VLC into my front panel and after playing around with your vis, I am stuck. I have no idea how to get the stream displayed somwhere inside a frame on my fp. Am I misunderstanding the whole thing? What do I have to do to get the stream displayed?

Thank you very much in advance.

GriffinRU
Member
Member
on

Hi,

All you need is window handle, pass it to VLC (libvlc_media_player_set_hwnd) and you good to go.

VLC - LabVIEW Embedded.vi should do the trick...

If not, attach your vi.

-Artur

Sergiv
Member
Member
on

With the help of your program, you can view the video stream in rtsp. Is it possible to save an image?

rtsp: //: @ 192.168.1.10 / user = admin_password = DuTIbxbU_channel = 1_stream = 0.sdp? real_stream

С помощью вашей программы можно просмотреть видеопоток по rtsp. Можно ли сохранить изображение ?

rtsp://:@192.168.1.10/user=admin_password=DuTIbxbU_channel=1_stream=0.sdp?real_stream

GriffinRU
Member
Member
on

Hi Sergiv,

Yes, "libvlc_video_take_snapshot", I will attach example, later.

-Artur

WeinmannP
Member
Member
on

But how to get a "Window Handle" from something which resides inside of my front Panel? When I run the Embedded-VI It just runs and shows its front panel.

ATM I go with a modified Version of your "fullscreen-VI" where I disabled the fullscreen, rename the Window using WinAPI32, put it in a specified place and disable its close-button. I am really not aware of a possibility to get a Window Handle from some object which in fact is not a windows window....

GriffinRU
Member
Member
on

Well, You can place activeX or .Net control on your front panel, window handle from properties.

Other ways (more complex  programming wise):

  • develop XControl
  • create floating window from VI
  • use API calls to draw at location
  • use VLC's window and embed it into your FP
  • ...

-Artur

Sergiv
Member
Member
on

Hi Sergiv,

Yes, "libvlc_video_take_snapshot", I will attach example, later.

-Artur

Thank you very much for your help! I'll wait for an example.

Sergiv
Member
Member
on

Tell me, please, how to play a video stream in ALS? In the application, when I insert a link (rtsp://@192.168.1.10/user=admin_password=DuTIbxbU_channel=1_stream=0.sdp?real_stream) it played perfectly and displays the video. But how to add this feature, I can not figure out. The list "funсtion name" I have not found a suitable (((

tried instead to add a link path - does not work (

343434.jpg

GriffinRU
Member
Member
on

Hi Sergiv,

I would try "libvlc_media_new_location" and specify location without "@" unless your are providing credentials.

-Artur

Sergiv
Member
Member
on

You were right. I removed the @, changed it to "libvlc_media_new_location" and was able to see your video. But I do not understand why this is so. Why VLC application works even with @?

Вы были правы. Я убрал @ , поменял на "libvlc_media_new_location" и смог увидеть своё видео. Но я не пойму почему так получается. Почему в приложении VLC работает даже с @ ?

GriffinRU
Member
Member
on

Hi Sergiv,

VLC stream player with snapshot attached.

As far as "@" you can write your own program and let it handle user input anyway you like

-Artur

Sergiv
Member
Member
on

Thank you very much! Everything turned out!

GriffinRU
Member
Member
on

Ну вот и супер, теперь только вперед

Будут вопросы, пишите - помогу,

-Артур

Jonzarwal
Member
Member
on

Hi everyone,

Thanks for all your precious advice. It was very helpful.
However, I don't find find any example to record what is displayed in the picture box container, which is possible in VLC. I guess there must be a couple of functions to do that, but I don't find them. Any idea?
And more generally, did you find somewhere a good documentation that describes all the functions in the dll?

Jonas

GriffinRU
Member
Member
on

Hi Jonas,

Documentation at: https://wiki.videolan.org/Documentation

Script for saving with VLC can be found on the web with various options...

For a example: " sout=#transcode{vcodec=h264,vb=4096,fps=30,scale=1,soverlay,sfilter={marq{marquee='Enter text here',position=9}:logo{file='Enter Logo path here',position=5,transparency=128}}}:duplicate{dst=std{access=file,mux=ts,dst='Enter Video path to save here'}}

Script above should re-encode video stream/file (source) to .ts file - with H264 codec with overlayed text and logo.

-Artur

Jonzarwal
Member
Member
on

Hi Artur, thank you for your answer.

I must be misunderstanding something. Where should i enter this srcipt? I use and want to update your vi VLC - Play Stream&Snapshot.vi. If i enter your example in the "Script" control, the video file is created, but seems to be empty, and there is no error shown.

GriffinRU
Member
Member
on

Example attached,

-Artur

Jonzarwal
Member
Member
on

Great ! It works well! Thank you so much.

Last question: Is there a way to stop the record without stopping  the VI (i want to handle the start/stop of the record independently of the display) ?

GriffinRU
Member
Member
on

Yes and no,

If you would like to connect to your video source (display it on screen) and at given time record stream to file, then probably not.

VLC media player allow you to do that, but over dll or command prompt such move is not easy to implement.

What you can do is start and stop media player with options (view and record or view only...), while keeping your VI running.

Check libvlc_media_player_stop; libvlc_media_player_play; libvlc_media_player_pause functions.

-Artur

Jonzarwal
Member
Member
on

Ok it works. the video is stopped for a few seconds when starting and stopping the rec. but it's ok for me. So thank you again for your great VIs!

Sergiv
Member
Member
on

Hello, GriffinRU

I have a question. I want to broadcast monitor in the VLС. He translates perfectly, but with frequent 1 frame per second. Is it possible to increase the frame rate? Is it possible to figure out the monitor for broadcast? (or need to use a third-party software)

Снимок.JPG

Thank you !

GriffinRU
Member
Member
on

Hi Sergiv,

You should be able to specify framerate for desktop capture with VLC, no 3rd party software required.

I will try to add example later...

-Artur

Sergiv
Member
Member
on

I did not understand a bit of what you wrote (the complexity of the translation).

In setting VLC can select the frame rate (fps) and it works. And how to do it programmatically is not entirely clear. With a choice of the captured Monitor also a question. It captures only the primary monitor.

снимок 2.JPG

GriffinRU
Member
Member
on

Hi,

Media Source:      "screen://"

Script:                   ":screen-fps=24 :live-caching=300 :screen-top=100 :screen-left=100 :screen-width=640 :screen-height=480"

I've added desktop region in case you would like to be more creative.

-Artur

P.S. Сергей как получилось? Правильно я вас понял? Кстати, можно через личку на русском писать, ответить в рабочие часы на русском сложновато, а прочитать без проблем.

Кстати, заметил новая версия VLC ни адекватно реагирует на screen-width, screen-height, screen-top и screen-left команды, поэтому либо задавать придеться через transcoding параметры либо по спрашивать на VLC форуме в чем суть игнорирования.

10.06.2014 9:50 PM

Just checked at home, from command prompt "screen-left" working properly for second display. But from VLC directly fails... I bet someone forgot something during last compilation.

Проверил дома, screen-left работает исправно для второго монитора, а вот с VLC на прямую отказывается выполнять. Сложно сказать в чем дело, но скорее последняя компиляция VLC ни без изъянов.

Думаю, коряво, но через command prompt можно сочинить бродкастинг определенной части второго монитора.

Sergiv
Member
Member
on

Спасибо, всё получилось, кроме выбора регионов. Я, кстати, попробовал многие версии VLC плеера, начиная от версии 1.0.0 Нигде не работает выбор регионов захвата. Попробую узнать на форуме VLC.

Думаю, коряво, но через command prompt можно сочинить бродкастинг определенной части второго монитора.

а что такое "command promt" ?

Thank you, everything turned out, except for the selection of regions. Incidentally, I have tried many versions of VLC player, starting from version 1.0.0 does not work anywhere selection of regions of capture. Try to find out on the forum VLC.

I think ugly, but through command prompt, you can compose Broadcasting certain part of the second monitor.

what is a "command promt"?


GriffinRU
Member
Member
on

Sergei,

Good, as far as "screen-left" and others, at the moment looks like they are working only for primary display and only from VLC directly or over Command prompt.

Command prompt -> cmd.exe

-Artur

Sergiv
Member
Member
on

Got it, thanks for the clarification

Sergiv
Member
Member
on

Dear Arthur.

Could you tell me with another program? With stereoscopic?

Здравствуйте, Артур.

Вы не могли бы мне подсказать с другой программой ? Со stereoscopic ?

GriffinRU
Member
Member
on

Hello,

I will check over the weekend.

-Artur

Danielweng
Member
Member
on

Hi Artur

May i ask a question about the VLC. i hope to capture desktop video. And this function can be used by VLC manually. i follow your previous suggestion that all the setup i take " Convert/Save" to save them. I originally want to take labview to simulate HOT KEY to press the Record. But i do not find it, so may i ask how can i use dll function to achieve this function or take VLC script to achieve them.

i take your save stream.VI and change souce to "Screen://" and change file type to MP4. but the file can not be saved successfully.

So hope you can help me to solve this issue or give me some suggestion about it.

Thanks

Daniel

GriffinRU
Member
Member
on

Hi Daniel,

I will add example later, over the weekend.

-Artur

GriffinRU
Member
Member
on

Placing " :sout=#duplicate{dst=display,dst="transcode{vcodec=h264,venc=x264{scenecut=100,bframes=0,keyint=10}, vb=1024,acodec=none,scale=1.0}"}:duplicate{dst=std{access=file,mux=mp4,dst='D:\Video\LabVIEW_VLC_Script.mp4'}}" into script control with Media Source as "screen://" should do the trick. Later you can adjust other parameters to match your preferences.

-Artur

Danielweng
Member
Member
on

Hi Arutr

  Thank you for your reply, i follow your suggestion and place these script into "save Stream.VI" But  there is no displaying in the "pictrueBox" and no information in the saved file.

Thanks

Daniel

GriffinRU
Member
Member
on

Can you attach printscreen of your front panel?

-Artur

Danielweng
Member
Member
on

Hi Artur

   please see the front panel print screen.123.jpg

GriffinRU
Member
Member
on

You are correct, I was able to re-produce your problem (I have computers which are capturing properly and one which doesn't). I will try to fix it over the weekend.

-Artur

Danielweng
Member
Member
on

Hi Artur

  Thank you very much for your great help. Because i want to achieve the function of "Record","Pause","stop" screen saving. May i ask where i can find the document that introduce the detail script in the VLC.

Thanks

Daniel

GriffinRU
Member
Member
on

Hi Daniel,

I think there is a problem with syntax when addressing capture devices (only first command accepted, others ignored. Without setting fps for capture device, VLC's transcoding fails. Setting for fps (:screen-fps=1, disables other commands) , in the past it was working.

I am sorry at the moment I am occupied, but I will try to solve this later. You probably can post question at VLC forums and ask what we are doing wrong with 'options'.

You can find documentation at VLC Developers Corner -> https://wiki.videolan.org/Developers_Corner/

Under "Modules" -> http://www.videolan.org/developers/vlc/doc/doxygen/html/modules.html

-Artur

Danielweng
Member
Member
on

Hi Artur:

Thank you for your continuous support.

Thanks

Daniel

leito
Member
Member
on

Hi everyone and thanks for sharing your codes

The vlc codes have worked properly on my computer running labview 2012 and vlc 2.1.5. However, I need to develop a code to change the reproduction speed of an avi/mp4 file. I have red the libvlc.dll documentation over the internet without luck.

Specifically, I am wondering what is the appropiate function and its parameter to programatically change the reproduction speed of an avi/mp4 file.

thanks everyone

Leonel

Anudeeproyal
Member
Member
on

Many Thanks for your work!!!

Royal
mnb123
Member
Member
on

Hi,

I need to change audio output module by using libvlc_audio_output_set function,(because when i use above vis , during disconnecting ts audio will be at loop. from the vlc player exe file from the setting when i changed audio to "waveout audio output" it will be ok.)

i would be grateful if sombody could help me to doing this by labvew function.

NQ1111
Member
Member
on

Hi,

Can someone guide me to play .h264 file?

_ Naeem Qaiser

brendan111
Member
Member
on

Artur,

I'm looking to eventually play IP audio from a webcam, but I don't need video.  I don't have the webcam yet, so I've been trying to get your code to work with various streaming sources online, including youtube and NPR (MP3 -- http://www.npr.org/streams/mp3/nprlive24.pls

WMP -- http://www.npr.org/templates/dmg/dmg.php?getProgramStream=true&NPRMediaPref=WM)  I haven't been able to get any of these to work.  I've spent a few hours reading through the libVLC documentation, but I'm not sure what I'm leaving out.  Are these simply sources I can't play?  Or am I failing to add a necessary component to your code?

Thanks,

Brendan

GriffinRU
Member
Member
on

Hi Brendan,

Are you required to use VLC for audio playback?

What is your final goal, I might offer you better solution...

-Artur

brendan111
Member
Member
on

Hi Artur,

I don't need to use VLC, it's just seemed like the easiest solution so far.  My final goal is to both play (speakers/headphones) and save streaming audio in labview.  The code for simultaneous playing and saving is done, but it's currently for a USB microphone, rather than a wireless/IP source.

Brendan

GriffinRU
Member
Member
on

VLC - Save Audio Stream.vi - attached.

-Artur

Contributors