Search code examples
c#vlctranscodinglibvlcsharp

How can I run VLC command from c#


I'd like to know if there's a way to use vlc arguments from C# program using VlcSharp(any other API for vlc libraries will be acceptable as well). I need to change codec of a video, that's why I have to do something like this: --no-repeat --no-loop -vv "D:\688497.flv"--sout='#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128,deinterlace}:standard{access=file,mux=ts,dst="D:\asd.mpg"}'(I have found this example here).
As far as I know, one can add arguments in LibVLCSharp.Shared.Media construcor like this:

            libVLC = new LibVLC();
            mediaPlayer = new MediaPlayer(libVLC);
            using (var media = new LibVLCSharp.Shared.Media(libVLC, new Uri(CameraViewModel.RtspAddress),
                ":sout=#file{dst=" + destination + "}",
                ":sout-keep"))
            {
                this.mediaPlayer.Play(media);
            }

But when I'm adding argumetns from the prompt above nothing happens(at least the destination file, which has to be the output of the transcoding isn't created), so I am looking for a way to run a vlc command from c# app.


Solution

  • Yes, this is possible. You can give CLI arguments to LibVLC through the LibVLC constructor, or as a Media option. Example:

    new LibVLC("--verbose=2"); 
    

    See documentation here https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/docs/how_do_I_do_X.md#how-do-i-use-libvlcs-advanced-options