Search code examples
xamarinxamarin.ioslibvlclibvlcsharpmobile-ffmpeg

Is there a way to use libvlc / libvlcsharp to non interactively transcode or compress a video on iOS?


I am using libVLCSharp (Xamarin bindings to the libvlc library) for video playback. I am adding a feature to transcode / compress downloaded videos to the local filesystem. Normally I'd use mobile-ffmpeg for this, but since internally VLC uses ffmpeg with different build configurations, ffmpeg transcoding does not work - android it crashes the app, ios returns a 'Invalid data found when processing input' error message when attempting to convert. The code works fine when libvlcsharp is uninstalled and there is only one instance of the ffmpeg library being used.

So, I'm looking for video compression / transcode options for Xamarin.iOS.

I've looked into the docs for libvlcsharp and it sounds like we can transcode, but it's somewhat vague on how to do that:

https://github.com/videolan/libvlcsharp/blob/3.x/docs/how_do_I_do_X.md

How do I do transcoding? Pretty similarly to how you would do it from the CLI. Read https://wiki.videolan.org/Transcode/ and try media options with Media.AddOption.

In my case, I'd like to transcode non-interactively / in the background of the app. There is a 'dummy' option in the command line interface for doing this, so I was wondering how we'd do this from libvlc / libvlcsharp.

So far, my code from these docs looks like this:

using(var vlc = new LibVLC())
{
    Media media = new Media(vlc, source, FromType.FromLocation);

media.AddOption($":sout=#transcode{{vcodec=h264,venc=x264{{cfr=40}},vb=2048,scale=auto,acodec=mp4a,ab=96,channels=2,samplerate=44100}}:std{{access=file,mux=ts,dst={destination}}}");

    media.AddOption("dummy");

    //How do I start the transcoding non interactively??
}

Solution

  • As replied on the libvlc discord server, when you are transcoding a video, it is not displayed at all and you just don't need to create a VideoView, the MediaPlayer alone is enough. The rest is finding the correct transcoding options, and you already found the correct wiki page for that.