How To Remove Black Bars from Videos using VLC Control C#

2.3k Views Asked by At

I have created vlcControl added on my windows form. I would like to know how can get rid of black bars on my vlc videos (image consumes black space). An example is shown below: enter image description here

I have tried the line vlc --aspect-ratio 16:9 -L -f /directory/to/file/filename. The line changes the aspect ratio but did not work as expected. I have tried the following lines of code:

Line 1:

vlcCustomer.Play(new Uri("rtsp://192.168.1.10/2/media/video1"), ":network-caching=50 :aspect-ratio=16:9 -L -f /directory/to/file/filename");

Line 2:

vlcCustomer.Play(new Uri("rtsp://192.168.1.10/2/media/video1"), ":network-caching=50 vlc --aspect-ratio 16:9 -L -f /directory/to/file/filename");
3

There are 3 best solutions below

0
mfkl On

No need to use CLI args for this, libvlc has an API for changing aspect ratio and it is available in Vlc.DotNet. Example: https://github.com/ZeBobo5/Vlc.DotNet/blob/f0d3e2aca37500ccd2710c8b9b286ccc485f1636/src/Samples/Samples.WinForms.Advanced/Sample.cs#L167

0
cube45 On

The thing is that your control will have the same size, whatever the aspect ratio you give to it, and it will need to fill with black bars. to get rid of it, you will need to resize your control and center it based on the aspect ratio you can get from the media info.

0
Sorry IwontTell On

Modify this code according to your screen and paste after your code:

VideoWidth = "1280";
VideoHeight = "750";
VlcControl2.Video.AspectRatio = VideoWidth + ":" + VideoHeight;