Open rageshS opened 3 years ago
Any update on this? I tried the rstp URL in different ways. but the error still occurred.
url 1 - rtsp://xxx.xxx.xxx.xxx:554//Streaming/Channels/1
url 2 - rtsp://username:password@xxx.xxx.xxx.xxx:554//Streaming/Channels/1
@rageshS - It would be helpful if you showed the code you're using before you attempt ConnectAsync(), the code that sets up the RTSP client. Also, code as text, not screenshot.
I too am using this library in:
https://github.com/victor-david/camera-eye
and it's working fine. This is a snippet of my portion for connecting to RTSP:
// requestUri is a string like: "rtsp://192.168.x.x/pathToVideoStream"
var serverUri = new Uri(requestUri);
var credentials = new NetworkCredential(Parms.UserId, Parms.Password);
var connectionParms = new RtspClientSharp.ConnectionParameters(serverUri, credentials)
{
RtpTransport = RtpTransportProtocol.TCP,
ConnectTimeout = TimeSpan.FromMilliseconds(Parms.Timeout),
};
using (var rtspClient = new RtspClient(connectionParms))
{
rtspClient.FrameReceived += RtspFrameRecieved;
await rtspClient.ConnectAsync(token).ConfigureAwait(false);
await rtspClient.ReceiveAsync(token).ConfigureAwait(false);
}
I got a good deal of help making this work by looking at the RtspClientSharp sample apps.
@victor-david Thank you very much for the support. Now it works fine.
But when I captured the frames, I can only get the blank images.
`private void RtspClient_FrameReceived(object sender, RtspClientSharp.RawFrames.RawFrame e)
{
//my understanding is some decoding must be done here which I cant figure out how before I
//copy the data into bmp, display it and use it to display in an imagebox
using (Bitmap bmp = CopyDataToBitmap(e.FrameSegment.Array))
{
//Bitmap bmp = CopyDataToBitmap(e.FrameSegment.Array);
string frameSavePath = Directory.GetCurrentDirectory().Replace("\\bin\\Debug", string.Empty) + @"\CapturedFrames";
frameSavePath = frameSavePath + "\\" + DateTime.Now.Ticks + ".jpg";
bmp.Save(frameSavePath);
}
}
public System.Drawing.Bitmap CopyDataToBitmap(byte[] data)
{
//Here create the Bitmap to the know height, width and format
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1280, 720, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//Create a BitmapData and Lock all pixels to be written
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat);
//Copy the data from the byte array into BitmapData.Scan0
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
//Unlock the pixels
bmp.UnlockBits(bmpData);
//Return the bitmap
return bmp;
}`
But i can't generate the correct frame that displayed in the IP Camera video.
Yes. As you mention in your code comment, you must decode each frame. For my project, this was one of the most challenging parts. I tried various options such as LibVlc, but found them to be too slow. I wound up using FFMPEG as the decoder backend as it gave me the best performance. This is what the RtspClientSharp sample app uses:
https://github.com/BogdanovKirill/RtspClientSharp/tree/master/Examples/SimpleRtspPlayer
My use case is somewhat different, but I adapted the decoding process from Bogandov's code at the above link. That would be a good start I think. Download the repository and run the sample player. Then you can figure out the decoding process. Worked for me.
Actually, what I did was fork RtspClientSharp and apply some changes as I experimented, such as merging a pending pull request and creating some optimizations. So my fork is a few commits ahead. Once that was working the way I wanted, I adapted the decoding for my camera project.
Thank you very much for your valuable feedback. But it shows a exception like the below image.
This URL works fine in the VLC Player.
The video stream that's mentioned in the other thread: #78
rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov
also gives me errors when I try to connect using the SimpleRtspPlayer. However, it does work in VLC.
Watching the message window in VLC, I notice that VLC first tries UDP and when that doesn't get a response, it tries TCP instead. SimpleRtspPlayer doesn't have a protocol fallback mechanism. So it fails (either through a timeout or something else).
So, in MainWindowViewModel:
I changed the protocol to TCP:
connectionParameters.RtpTransport = RtpTransportProtocol.TCP;
and now SimpleRtspPlayer plays the BigBuckBunny stream successfully. In my camera program (as I posted above), I always set the protocol to TCP. I'm not sure why some streams work with UDP and others need TCP, but maybe try changing the protocol and see what happens.
Thank you very much for your great support. I am stopping to explore this repository because we have an urgent project requirement and need to find a better alternative. Anyway, thank you very much.
You're welcome. All the best.
Hi All,
I have an RSTP URL like - rtsp://xxx.xxx.xxx.xxx:554//Streaming/Channels/1 with a username and password. I tested this URL with the VLC player. It successfully authenticated and shows the real-time video from the IP Camera ( I am using HIKVISION IP Camera DS-2CD1302D-I )
But when I try to connect the same URL with the same credentials using RtspClientSharp it shows an error like the below image.
It always the error invalid login and/or password.
Is this a bug? Any help much appreciated.
Thanks