mfkl / libvlcsharp-samples

Various samples on different platforms showcasing LibVLCSharp features
GNU Lesser General Public License v2.1
52 stars 16 forks source link

Bug in the library? #126

Closed zydjohnHotmail closed 3 years ago

zydjohnHotmail commented 3 years ago

Hello: I want to download a video and save to local hard drive file using the library. I have created one C# console project, and install 2 nuget packages: PM> Install-Package LibVLCSharp -Version 3.5.1 PM> Install-Package VideoLAN.LibVLC.Windows The following is my C# code, almost the same as the code sample: using LibVLCSharp.Shared; using System; using System.IO; using System.Reflection;

namespace LibVLCSharpRecordHLS { class Program { public const string Video1_URL = @"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";

    static void Main()
    {
        var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        var destination = Path.Combine(currentDirectory, "record.ts");
        Core.Initialize();

        using var libvlc = new LibVLC();
        using var mediaPlayer = new MediaPlayer(libvlc);
        libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}");
        using (var media = new Media(libvlc, new Uri(Video1_URL),
            ":sout=#file{dst=" + destination + "}",
            ":sout-keep"))
        {
            mediaPlayer.Play(media);
        }
        Console.WriteLine($"Recording in {destination}");
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
    }
}

}

I can compile my program, but when I run it, but after more than 30 minutes, the program has NOT finished, and the size of destination file is 0, until I stop debugging, I can see the size of destination file is about 172MB. I think there may be some bug in the library, please investigate. My OS: Windows 10 (Version 21H1), my IDE: Visual Studio 2019 (Version 16.10.4), C# console project target .NET 5.0. Thanks,

mfkl commented 3 years ago

The recorded file is written to disk when you call mediaplayer.Stop, usually or dispose of the mediaplayer.

zydjohnHotmail commented 3 years ago

Hello: Please show me the code, if I want to save the video to local disk drive. Thanks,

mfkl commented 3 years ago

See https://github.com/mfkl/libvlcsharp-samples/commit/d5a828a5fa1ef50a7c0fe355dff10830bcf66f5c