Page 1 of 2

Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 10:34
by yabbadidu
I'm trying to perform some rtsp to webm transcoding using libVLC inside a c# project.
For some reasons, hardware acceleration is not working properly on my development machine (and apparently on 3 other machines, with various video cards, I have tested my solution on) ; I get the same situation if I try to do the transcoding directly from vlc.exe by calling it with

Code: Select all

vlc.exe rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov :network-caching=1000 :sout=#transcode{vcodec=VP80,vb=2000,acodec=vorb,ab=128,channels=2,samplerate=44100,scodec=none}:http{mux=webm,dst=:4000/stream} :no-sout-all :sout-keep"
This is the result
Image
On the other hand, if I add the --avcodec-hw=none parameter to the command line, it works flawlessly.

Now, my problem is that it appears that said parameter is ignored by libVNC. I have been using both Vlc.DotNet.Core and LibVLCSharp and in both cases I still get the hardware accelerated, green video; which brings me to think that somehow libVNC is ignoring the parameter? (looking at the source code, it appears it's overwriting the value with "" if libvlc_media_player_set_hwnd is being called, but I don't know if this is the case).
These are the logs I get, if they can be of help (not max verbosity)

Code: Select all

10:20:47.466|Info|Open 10:20:49.418|Warn|decoded zero sample 10:20:49.642|Info|Using D3D11VA (AMD Radeon HD 6570, vendor 1002(ATI), device 6759, revision 0) for hardware decoding
.

Is there something else I should be doing?
Thanks in advance

Re: Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 10:48
by mfkl
Can you share your full c# code using libvlc please?

Re: Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 11:42
by yabbadidu
Sure, there you go

Code: Select all

private static DirectoryInfo VLCPATH = new DirectoryInfo( Path.Combine( Program.SERVICE_PATH, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64" )); private static string[] VLCOPTIONS = new string[] { "--avcodec-hw=none" }; private static string SOURCE = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"; private static string DESTINATION = @":sout=#transcode{vcodec=theo,vb=2000,acodec=vorb,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ogg,dst=:$PORT$/stream},dst=file{dst=$FILE$}}"; private string[] _mediaOptions = new string[] { ":network-caching=1000", String.Empty, ":no-sout-all", ":sout-keep" }; // using LibVLCSharp public void StartStreamLibVLCSharp(string fileName, string port) { var vlc = new LibVLC(VLCOPTIONS); var mediaPlayer = new MediaPlayer(vlc); string filePath = String.Format("somefile-{0}.ogg", fileName); _mediaOptions[1] = DESTINATION.Replace("$PORT$", port).Replace("$FILE$", filePath); var media = new Media(vlc, SOURCE, Media.FromType.FromLocation); foreach (string opt in _mediaOptions) media.AddOption(opt); mediaPlayer.Play(media); } // using Vlc.DotNet.Core public void StartStreamVlcDotNet(string fileName, string port) { var vlc = new VlcMediaPlayer(VLCPATH, VLCOPTIONS); string filePath = String.Format("somefile-{0}.ogg", fileName); _mediaOptions[1] = DESTINATION.Replace("$PORT$", port).Replace("$FILE$", filePath); vlc.SetMedia(SOURCE, _mediaOptions); vlc.Play(); }

Re: Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 12:44
by mfkl
By full I meant... full :-) upload your code on a git somewhere please.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 14:43
by yabbadidu
Thanks, you can find a sample here then https://gitlab.com/SirePi/libvlc-test
You will need to grab manually VideoLAN.LibVLC.Windows from nuGet because, for some reasons, it seems it won't be restored in the target folder if it's already present in the packages' list when you first open the project.

Other than that, just start the solution and open test.html with a browser (it contains 2 video tags, one for each library's streaming port)

Thanks again!

Re: Using libVLC ignores disabled hardware acceleration

Posted: 24 Jan 2019 17:19
by Rémi Denis-Courmont
Stream output support in LibVLC does not exist (yet).

Re: Using libVLC ignores disabled hardware acceleration

Posted: 25 Jan 2019 11:29
by yabbadidu
Sorry, but I don't understand what you mean with your answer.. am I doing something wrong or something that shouldn't be there?
I was always under the impression that VLC is only a graphical wrapper around libVLC, so if it works with VLC, why can't it be done in libVLC?

Re: Using libVLC ignores disabled hardware acceleration

Posted: 28 Jan 2019 09:30
by Moriquendi
Sorry, but I don't understand what you mean with your answer.. am I doing something wrong or something that shouldn't be there?
I was always under the impression that VLC is only a graphical wrapper around libVLC, so if it works with VLC, why can't it be done in libVLC?
So was I. Unfortunately some parameters in libVLC is hard coded, so no matter which parameters you pass, it will always default to that value. You can try to recompile the source code (which may be a really tiresome process if you are a Windows user like me), but there is no guarantee it will do the trick for you. Anyway, good luck.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 28 Jan 2019 11:48
by yabbadidu
The weird part is that, as I said in the opening post, it works from VLC so there must be a way to have it understand that variable but it seems to be ignored if called from the outside.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 28 Jan 2019 19:31
by Rémi Denis-Courmont
LibVLC ignores the user configuration.

This is very much by design - LibVLC developers and application developers reasonably expect the default settings for (almost) everything. You would not want to have to force the thousand or so parameters to their default value one by one, just in case the local user changed them.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 09:22
by yabbadidu
To be honest, I'm a bit surprised by this answer.. I understand that you don't want to have to manually set all parameters to their default value, but at the same time, as a developer and user, I'd like to have my custom values to be taken into account. What's the point of having parameters otherwise?

Anyway, back to the drawing board then.
Thanks for the answers!

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 10:09
by cube45
Rémi,
By "user configuration", you also mean with options passed to libvlc? Why can we pass other options when playing and not when using a stream out chain?

If nothing can be done there, is there a way @yabbadidu can get his/her video card blacklisted for hw acceleration? Or maybe is that a bug that needs to be fixed in a future VLC release?

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 10:22
by yabbadidu
If nothing can be done there, is there a way @yabbadidu can get his/her video card blacklisted for hw acceleration?
Unfortunately I don't think this is a good solution, as although I am currently working on this specific video card, I can't be sure nor force the hardware configuration of the final production system - which could even work properly with hardware acceleration but I can't be sure of that so I have to plan defensively. Thanks for the support though :D

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 17:27
by LuckyT
Rémi,
By "user configuration", you also mean with options passed to libvlc? Why can we pass other options when playing and not when using a stream out chain?

If nothing can be done there, is there a way @yabbadidu can get his/her video card blacklisted for hw acceleration? Or maybe is that a bug that needs to be fixed in a future VLC release?
Right? I can understand ignoring the local user's settings but I cannot understand why parameters the developer passes would be ignored, ever. The Quadro's decoding chip cannot handle many videos at once and basically the same single chip is used on a huge range of cards so upgrading the card makes no difference. Potentially an easy fix by disabled hardware acceleration but I wasn't able to do so because this odd behavior. Seems like a bug.

Additionally I was able to disable acceleration in VLC Player itself just fine, this is a libvlc issue I think.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 19:16
by Rémi Denis-Courmont
Rémi,
By "user configuration", you also mean with options passed to libvlc? Why can we pass other options when playing and not when using a stream out chain?
I believe that the libvlc_new() API documentation has a very clear answer to that question:
The list of valid arguments depends on the LibVLC version, the operating system and platform, and set of available LibVLC plugins. Invalid or unsupported arguments will cause the function to fail (i.e. return NULL). Also, some arguments may alter the behaviour or otherwise interfere with other LibVLC functions.
(...)
There is absolutely no warranty or promise of forward, backward and cross-platform compatibility with regards to libvlc_new() arguments. We recommend that you do not use them, other than when debugging.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 19:21
by Rémi Denis-Courmont
What's the point of having parameters otherwise?
Parameters are there for the VLC executable command line interface and nothing else. If you use them otherwise, you are on your own.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 30 Jan 2019 19:24
by Rémi Denis-Courmont
I can understand ignoring the local user's settings but I cannot understand why parameters the developer passes would be ignored, ever.
I can think of a lot of reasons:
  • They might not apply to the use case.
  • They might no longer exist in a new version.
  • They might not be available within the installed LibVLC platform or set of plugins.
  • They might conflict with documented LibVLC API functionality.
  • They might be overriden by LibVLC internally as part of its documented APU functionality.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 11 Feb 2019 15:48
by robUx4
I don't understand the same app but it is possible to enable/disable `avcodec-hw` through libvlc. There are cases where it's not going to work though. For example if you use `libvlc_video_set_callbacks()` or `libvlc_media_player_set_hwnd()`.

When you create your media to play, you can add options, for example `media.addOption(":avcodec-hw=none")` in libvlcpp. You set it before starting playback of the media you want to play.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 13 Feb 2019 08:59
by MikOfClassX
Apparently, when you set video callbacks, your hw acceleration goes away.
Now, if only the API would give you access to var_SetString()... you could do something more "dev-side". At your own risk.


Code: Select all

void libvlc_video_set_callbacks( libvlc_media_player_t *mp, void *(*lock_cb) (void *, void **), void (*unlock_cb) (void *, void *, void *const *), void (*display_cb) (void *, void *), void *opaque ) { var_SetAddress( mp, "vmem-lock", lock_cb ); var_SetAddress( mp, "vmem-unlock", unlock_cb ); var_SetAddress( mp, "vmem-display", display_cb ); var_SetAddress( mp, "vmem-data", opaque ); var_SetString( mp, "avcodec-hw", "none" ); var_SetString( mp, "vout", "vmem" ); var_SetString( mp, "window", "dummy" ); }

Re: Using libVLC ignores disabled hardware acceleration

Posted: 13 Feb 2019 19:32
by Rémi Denis-Courmont
That is by hardware design. Hardware acceleration outputs decoded frames into video memory that is not generally accessible to the CPU. And even when it is accessible, it is typically in some unusable hardware-specific tiled formats.

If you want hardware acceleration, do not use the video callbacks. It will most probably never be supported because hardware will probably never support it.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 16 Feb 2019 11:08
by Jean-Baptiste Kempf
For that, you'll need the new OpenGL callback, for 4.0

Re: Using libVLC ignores disabled hardware acceleration

Posted: 18 Feb 2019 09:24
by MikOfClassX
GL callback ? Sounds good. Will it support RGBA pixel format ?

Re: Using libVLC ignores disabled hardware acceleration

Posted: 18 Feb 2019 17:24
by Rémi Denis-Courmont
No. It will use opaque surfaces that are not CPU-accessible.

Re: Using libVLC ignores disabled hardware acceleration

Posted: 16 Apr 2019 17:18
by doubleaa93
I'm looking at the new OpenGL callback in 4.0 but I only get sound and a black screen. Is this feature ready or still in development?

I'm using example from https://github.com/videolan/vlc/blob/ma ... player.cpp

Re: Using libVLC ignores disabled hardware acceleration

Posted: 16 Apr 2019 18:36
by sherington
Those new OpenGL callbacks did work for me last time I tried, maybe a month ago or so. I've had video playing in an LWJGL application (I use Java).