0

我正在尝试使用 libvlc 将实时视频流保存到 Android 应用程序的存储中。我可以用命令行在 PC 上完成它,它工作正常,我记录了文件,然后可以查看它。

但是在应用程序中的文件记录,它只有 151B 大,可能是空的,如果我尝试打开它,我会收到消息“无法播放此视频格式”

我的问题是,是否可以使用 libvlc 记录到 Android 中的存储?

我对编程很陌生,所以任何建议都会有所帮助

    const string VIDEO_URL = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";

    public MainPage()
    {
        InitializeComponent();
        Core.Initialize();           
        using (var libvlc = new LibVLC())
        using (var mediaPlayer = new MediaPlayer(libvlc))
        {
            var media = new Media(libvlc, VIDEO_URL, FromType.FromLocation);
            var currentDirectory = "/storage/emulated/0/dcim/";
            var destination = Path.Combine(currentDirectory, "record4.mp4");

            // Define stream output options. 
            // In this case stream to a file with the given path and play locally the stream while streaming it.
            media.AddOption(":sout=#transcode{vcodec=h264}:std{access=file,dst=" + destination + "}");

            // Start recording
             mediaPlayer.Play(media);
        }
    }   
4

2 回答 2

0

媒体播放器必须停止才能关闭应用程序。这是一个临时解决方案。一旦我有适当的解决方案,将立即更新它。

   public partial class MainPage : ContentPage
{
    const string VIDEO_URL = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";

    public MainPage()
    {
        InitializeComponent();
        Core.Initialize();           
        using (var libvlc = new LibVLC())
        using (var mediaPlayer = new MediaPlayer(libvlc))
        {
            var media = new Media(libvlc, VIDEO_URL, FromType.FromLocation);
            var currentDirectory = "/storage/emulated/0/dcim/";
            var destination = Path.Combine(currentDirectory, "record7.mp4");

            // Define stream output options. 
            // In this case stream to a file with the given path and play locally the stream while streaming it.

            media.AddOption(":sout=#file{dst=" + destination + "}");
            media.AddOption(":sout-keep");


            // Start recording
             mediaPlayer.Play(media);

            *// Added these lines that create event handler error for Xamarin.forms, 
            // but at least it stops mediaplayer before closing App. and the 
            // recording can be play afterwards.*
            Console.WriteLine($"Recording in {destination}");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
}
于 2019-06-10T11:11:45.603 回答
0

首先创建一个目标文件并将 URL 解析为 URI 而不是路径,将以下 arg 添加到 libvlc

Final ArrayList<String> args = new ArrayList<>();
args.add (" &ndash; aout=opensles");
args.add (" &ndash; vout=android_display");
args.add (" &ndash; audio-time-stretch");
args.add (" &ndash; no-sub-autodetect-file");
args.add (" &ndash; swscale-mode=0");
args.add (" &ndash; network-caching=500");
args.add (" &ndash; no-drop-late-frames");
args.add (" &ndash; no-skip-frames");
args.add (" &ndash; avcodec-skip-frame");
args.add (" &ndash; avcodec-hw=any");
mLibVLC = new LibVLC (mContext, args);
于 2020-04-15T12:23:45.043 回答