0

I'm making a project using c# 2013, windows forms and this project will use an IP camera to display a video for a long time using CGI Commands. I know from the articles I've read that the return of the streaming video of the IP camera is a continuous multi-part stream. and I found some samples to display the video like this one Writing an IP Camera Viewer in C# 5.0

but I see a lot of code to extract the single part that represents a single image and displays it and so on. Also I tried to take continuous snap shots from the camera using the following code.

    HttpWebRequest req=(HttpWebRequest)WebRequest.Create("http://192.168.1.200/snap1080");
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

    Stream strm = res.GetResponseStream();
    image.Image = Image.FromStream(strm);

and I repeated this code in a loop that remains for a second and counts the no. of snapshots that were taken in a second and it gives me a number between 88 and 114 snapshots per second

IMHO the first example that displays the video makes a lot of processing to extract the single part of the multi-part response and displays it which may be as slow as the other method of taking a continuous snapshots. So I ask for other developers' experiences in this issue if they see other difference between the 2 methods of displaying the video. Also I want to know the effect of receiving a continuous multi-part stream on the memory is it safe or will generate an out of memory errors. Thanks in advance

Ahmed
  • 559
  • 1
  • 5
  • 14

2 Answers2

2

If you are taking more than 1 jpeg per 1-3 seconds, better capture H264 video stream, it will take less bandwidth and cpu.

Usually mjpeg stream is 10-20 times bigger than the same h264 stream. So 80 snapshots per second is a really big amount.

Max Lapshin
  • 822
  • 7
  • 15
  • I tried to play H264 video stream using VLC but it's worse in delay than the previous 2 methods I mentioned before. is it normal for the H264 to be like this? – Ahmed Dec 03 '17 at 14:44
0

As long as you dispose of the image and stream correctly, you should not have memory issues. I have done a similar thing in the past with an IP Camera, even converting all the images that I take as a snapshot back into a video using ffmpeg (I think it was).

netniV
  • 2,328
  • 1
  • 15
  • 24
  • I'm not worried about the memory issues in case of doing snapshots and playing them as a video because as you said I can dispose the image and if i didn't dispose it the stream will not hold more than the image bytes. I'm worried about memory in the second case, I think I can't dispose the memory stream in this case. – Ahmed Nov 28 '17 at 13:15
  • When you call Image.FromStream() you are copying the data over so the stream isn't used again. If you are using the Video with constant returning data, then you don't close the HttpResponse stream but use the bytes that are sent to create the image. That can be done using a MemoryStream and the memory stream can be disposed of once the Image is created. – netniV Nov 28 '17 at 13:27
  • netniV, thanks for your cooperation. you are right we take the bytes that creates a single image in a separate stream and this could be disposed , but what about the HttpResponse stream itself (that's what I'm worried about) – Ahmed Nov 28 '17 at 13:32
  • If an error occurs with the stream or if you stop wanting the data, you should call Close and Dispose(). Until that point, if it is a multiple jpeg stream, you just leave it open. – netniV Nov 28 '17 at 13:34