C# 使用LibVLC.NET从RTSP流录制音频

C# 使用LibVLC.NET从RTSP流录制音频,c#,wpf,audio,vlc,rtsp,C#,Wpf,Audio,Vlc,Rtsp,我正在开发WPF应用程序,它可以播放RTSP流中的视频,同时尝试将其录制到文件中 这就是它的工作原理: 我创建了LibVLC.NET.MediaPlayer实例并绑定了一个处理图像的事件处理程序: _vlcPlayer = new LibVLC.NET.MediaPlayer(VLCLibrary, null); _vlcPlayer.Display += VLC_Display; VLC_Display将每个帧写入WriteableBitmap,因此它显示在ImageBox上。 然后将其写入

我正在开发WPF应用程序,它可以播放RTSP流中的视频,同时尝试将其录制到文件中

这就是它的工作原理:

我创建了LibVLC.NET.MediaPlayer实例并绑定了一个处理图像的事件处理程序:

_vlcPlayer = new LibVLC.NET.MediaPlayer(VLCLibrary, null);
_vlcPlayer.Display += VLC_Display;
VLC_Display将每个帧写入WriteableBitmap,因此它显示在ImageBox上。 然后将其写入视频文件

private void VLC_Display(object sender, EventArgs e)
  {
         // write frame to bitmap
         VideoBuffer videoBuffer = _vlcPlayer.VideoBuffer;

         _vlcBufferBitmap.Lock();
         _vlcBufferBitmap.WritePixels(new Int32Rect(0, 0, (int)videoBuffer.Width, (int)videoBuffer.Height), videoBuffer.FrameBuffer, (int)videoBuffer.Stride, 0);
         _vlcBufferBitmap.Unlock();

         [...]

         // write frame to file
         using (var bitmap = MediaUtils.ConvertToBitmap(_imageBox.Source as BitmapSource))
            {
                     _aforge.AddFrame(bitmap, timestamp);
            }


         // ??? write sound ???

}
这个很好用。问题是,如何书写声音? 我想将声音写入一个单独的文件,但我找不到读取音频流的方法

我试图在LibVLC.NET.MediaPlayer中创建一个属性来处理声音:

    private int length = 1024;
    public unsafe byte[] AudioBuffer
    {
        get
        {
            IntPtr mediaPointer = m_Library.libvlc_media_player_get_media(m_MediaPlayerHandle);
            if (mediaPointer == IntPtr.Zero)
                return null;

            try
            {
                using (var memoryStream = new UnmanagedMemoryStream((byte*)mediaPointer.ToPointer(), length))
                {
                    byte[] audioBytes = new byte[length];
                    memoryStream.Read(audioBytes, 0, length);

                    return audioBytes;
                }
            }
            finally
            {
                m_Library.libvlc_media_release(mediaPointer);
            }
        }
    }
但它不返回音频内容

任何帮助都将不胜感激

提前谢谢