Poor audio quality with LibVLCSharp

Hello, I am a newbie in C# and WinForm and i'm developing a Windows Form application in C#, .NET Framework 4.8, with the LibVLCSharp.Winforms library (the latest version downloaded from NuGet). It works like that : you import a file (video file, for exemple), you select it, you press a button, it open a new window on the 2nd screen, it get in fullscreen and it launch the video. I am facing a persistent audio quality issue : the sound in my application seems really weird (compressed, or poor quality). However when i play the exact same video file with the official VLC software, the audio quality is perfect. I have tried a lot of things, such as forcing the audio ouput module. The code that initialize the player
public VideoPlayerForm(Screen screen, string videoPath)
{
this.Shown += VideoPlayerForm_Shown;
}

private void VideoPlayerForm_Shown(object sender, EventArgs e)
{
Core.Initialize();
_libVLC = new LibVLC();
_mediaPlayer = new MediaPlayer(_libVLC);

_videoView = new VideoView { MediaPlayer = _mediaPlayer, Dock = DockStyle.Fill };
this.Controls.Add(_videoView);

using (var media = new Media(_libVLC, new Uri(videoPath)))
{
_mediaPlayer.Play(media);
}
}
public VideoPlayerForm(Screen screen, string videoPath)
{
this.Shown += VideoPlayerForm_Shown;
}

private void VideoPlayerForm_Shown(object sender, EventArgs e)
{
Core.Initialize();
_libVLC = new LibVLC();
_mediaPlayer = new MediaPlayer(_libVLC);

_videoView = new VideoView { MediaPlayer = _mediaPlayer, Dock = DockStyle.Fill };
this.Controls.Add(_videoView);

using (var media = new Media(_libVLC, new Uri(videoPath)))
{
_mediaPlayer.Play(media);
}
}
I would really like to know why the audio quality is so bad, or where I made a mistake.
11 Replies
J0nathan550
J0nathan5505w ago
I have a bad feeling that WinForms library has a poor quality. In WPF or Avalonia I never had issues like this. Can you share full source code? as zip file
FichierCorrompu
FichierCorrompuOP5w ago
what file do you need exactly ? Or do you want the full project files ?
J0nathan550
J0nathan5505w ago
I need project file yes exclude bin, obj.
J0nathan550
J0nathan5505w ago
what is "AxWMPLib"?
FichierCorrompu
FichierCorrompuOP5w ago
Its for the Windows media player I use it for the preview of the video
J0nathan550
J0nathan5505w ago
that is the problem. You are using old windows media player. Not the LibVLC. You should use just https://github.com/videolan/libvlcsharp
GitHub
GitHub - videolan/libvlcsharp: Cross-platform .NET/Mono bindings fo...
Cross-platform .NET/Mono bindings for LibVLC. Contribute to videolan/libvlcsharp development by creating an account on GitHub.
FichierCorrompu
FichierCorrompuOP5w ago
I don't understand, i use the old Windows Media Player for the preview in the 1rst window of the software (and the audio if fine here), and for the main video viewer on the 2nd screen, it use the LibVLCSharp, not the Windows media player.
Stone_Red
Stone_Red2w ago
Hi there, I just had the same issue. In my case the audio resampler was the problem because it defaulted to the "ugly" resampler. Setting --audio-resampler=speex_resampler in the LibVLC constructor fixed the issue. I hope it helps
FichierCorrompu
FichierCorrompuOP2w ago
Oh bro it works, thank you so much ! How did you find that ?
Stone_Red
Stone_Red2w ago
You are welcome I enabled the debug logs (by passing true to the LibVLC constructor) and found these two lines:
[000001ce02f51a50] main audio resampler debug: looking for audio resampler module matching "any": 2 candidates
[000001ce02f51a50] main audio resampler debug: using audio resampler module "ugly"
[000001ce02f51a50] main audio resampler debug: looking for audio resampler module matching "any": 2 candidates
[000001ce02f51a50] main audio resampler debug: using audio resampler module "ugly"
I thought "ugly" doesn't sound good so I checked how I can change the resampler and found that CLI option. The CLI arguments are listed here btw: https://wiki.videolan.org/VLC_command-line_help/

Did you find this page helpful?