butterfly
butterfly

Reputation: 1

When using VLClib to play video streams, I wanted to play and store videos simultaneously, but it crashed

I used a vlcunity plugin to play video streams, and here is its code:

`public void Open()
    {
        string outputFilePath = "\\path\\test.mp4";
        path ="rtsp://127.0.0.1:2334";
        if (mediaPlayer.Media != null)
            mediaPlayer.Media.Dispose();

        var trimmedPath = path.Trim(new char[]{ '"' });
        if(string.IsNullOrEmpty(trimmedPath)) return;
        // var mediaOptions = new[] {
        //     ":network-caching=300",
        //     $":sout=#file{{dst={outputFilePath}}}"
        // };
        var mediaOptions = new[] {
            ":network-caching=300",
            $":sout=#duplicate{{dst={outputFilePath},dst=display}}"
        };
        mediaPlayer.Media = new Media(trimmedPath, FromType.FromLocation, mediaOptions);
        Play();
    }

If the $":sout=#duplicate{{dst={outputFilePath},dst=display}}" attribute is removed, the video can be played normally in Unity. When adding the duplicate attribute and setting dst=display, running Unity will crash directly. If only the $":sout=#file{{dst={outputFilePath}}}" attribute is retained, it will store video files but cannot play them in real-time。

I tried using various attribute combinations provided by VLClib, but it still couldn't achieve my goal。 I hope that when using the VLCUnity plugin, I can play real-time video stream images such as RTSP while storing video data, and use this stored file to play in other businesses.

Upvotes: 0

Views: 40

Answers (0)

Related Questions