code_junkie

Creating an MJPEG video stream in c#

Nov 11th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. Response.Clear();
  2. Response.ContentType = "multipart/x-mixed-replace; boundary=--myboundary";
  3. ASCIIEncoding ae = new ASCIIEncoding();
  4. HCData data = new HCData();
  5. var videos = (from v in data.Videos
  6. select v).Take(50); // sample the first 50 frames
  7. foreach (Video frame in videos)
  8. {
  9. byte[] boundary = ae.GetBytes("rn--myboundaryrnContent-Type: image/jpegrnContent-Length:" + frame.VideoData.ToArray().Length + "rnrn");
  10. var mem = new MemoryStream(boundary);
  11. mem.WriteTo(Response.OutputStream);
  12. mem = new MemoryStream(frame.VideoData.ToArray());
  13. mem.WriteTo(Response.OutputStream);
  14. Response.Flush();
  15. Thread.Sleep(200);
  16. }
Add Comment
Please, Sign In to add comment