Creating an MJPEG video stream in c#
I have some images that is sent to the database from a remote location and treated as video source at about 5 frames per second as JPEG images.I am going to show you the code which can help you to figure out the problem and you can be helpful form this .
Code:
Response.Clear();
Response.ContentType = "multipart/x-mixed-replace; boundary=--myboundary";
ASCIIEncoding Ascen = new ASCIIEncoding();
HCData Hdata = new HCData();
var vds = (from v in Hdata.Vds
select v).Take(50);
foreach (Video frame in vds)
{
byte[] boundary = Ascen.GetBytes("\r\n--myboundary\r\nContent-Type: image/jpeg\r\nContent-Length:" + frame.VideoData.ToArray().Length + "\r\n\r\n");
var memo = new MemoryStream(boundary);
memo.WriteTo(Response.OutputStream);
memo = new MemoryStream(frame.VideoData.ToArray());
memo.WriteTo(Response.OutputStream);
Response.Flush();
Thread.Sleep(200);
}
Bookmarks