Search code examples
videovlcvideo-encodinglibvlc

Write video stream from camera into file using VLC


I'm using VLC wrapper VLC.DotNet, libvlc 3.0.3 or 3.0.4 nightly and I try example:

 static void Main(string[] args)
    {
        var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        // Default installation path of VideoLAN.LibVLC.Windows
        var libDirectory =
            new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

        var destination = Path.Combine(currentDirectory, "record.mp4");

        using (var mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(libDirectory))
        {

            var mediaOptions = new[]
            {
                ":sout=file{dst=" + destination + "}",
                ":sout-keep"
            };

            mediaPlayer.SetMedia(new Uri("rtsp://192.168.x.xxx/ch1.h264"),
                mediaOptions);

            mediaPlayer.Play();

            Console.WriteLine($"Recording in {destination}");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }

Everything works great I see recorded file in folder, but when I change media options format, file not recording... F.E:

 var mediaOptions = new[]
        {
            ":sout=#transcode{vcodec=h264}:std{access=file,mux=ffmpeg{mux=flv}),file{dst=" + destination + "}",
            ":sout-keep"
        };

Log screenshot: enter image description here

I need to encode streaming video from camera into H.264 mp4 video file with mp3 or AAC audio. It would be great if anyone help me with this example.


Solution

  • I changed my media options to:

    var lowQualityMediaOptions = new[]
            {
                ":sout=#transcode{vcodec=h264,width=640,height=480,canvas-width=640,canvas-height=480,fps=4}:std{access=file,mux=ts,dst=" + lowQualityDestination + "}",
                ":sout-all"
            };
    

    And everything works good.