BogdanovKirill / RtspClientSharp

Pure C# RTSP client for .NET Standard without external dependencies and with true async nature. I welcome contributions.
MIT License
694 stars 284 forks source link

I can't get to play the video #132

Open EgorBlagodarov opened 8 months ago

EgorBlagodarov commented 8 months ago

Hello! I am writing a program to conduct a video broadcast from the camera. I decided to transmit data via RTSP. Requests are sent to the server and responses begin to arrive, after receiving, I translate the Frame into a byte[] array and try to convert it to a bitmap, but it gives an error. Can you tell me how I can make a broadcast?

public static async void RTSPClient(CancellationToken token) { //параметры и запросы var serverUri = new Uri("rtsp://192.168.0.94:554/cam0_0"); var credentials = new NetworkCredential("root", "root"); var connectionParameters = new ConnectionParameters(serverUri, credentials); connectionParameters.RtpTransport = RtpTransportProtocol.TCP;

RtspClient rtspCl1 = new RtspClient(connectionParameters); try { await rtspCl1.ConnectAsync(token);

              //the process of obtaining frames
              rtspCl1.FrameReceived += (sender, frame) =>
              {

              switch (frame)
              {
                            case RawH264IFrame h264IFrame:
                            Console.WriteLine("Формат RawH264IFrame");

                            //the process of obtaining frames
                            byte[] cv1 = frame.FrameSegment.Array;
                            MemoryStream memoryStream = new MemoryStream(fileBytes);

                            //an error pops up here, the obviously received array is not an image, although the format is RawH264IFrame
                            Bitmap bitmap = new Bitmap(memoryStream);

                            break;

                            default:
                            Console.WriteLine("Формат неизвестен");
                            break;
              }

};

await rtspCl1.ReceiveAsync(token);

} catch (SocketException ex) { Console.WriteLine("Подключение не установлено"); Console.WriteLine("Код ошибки:"); Console.WriteLine(ex.Message);

} }

Revan1985 commented 7 months ago

Hello Egor, you cannot take a rawh264iframe and write directly in a bitmap. there is an example SimpleRtspPlayer that you can use as reference on how to archive your needs. I think you need the RawFramesDecoding folder.