I am self hosting OWIN/KATANA in a windows service. Right now I have implemented a way to grab a single image from a camera. I would like to grab multiple frames from the camera and stream them back to a img tag on an html page. Is this possible with OWIN/KATANA?
Asked
Active
Viewed 289 times
0
-
Are you asking "Given a series of still frames, how do I convert that into a video?" or "Given a video, how do i stream that using OWIN/KATANA?" – Moby Disk Oct 22 '15 at 19:23
-
I will be taking a series of still frames that I would like to stream back to the client live. I have a connection to the camera and can probably snap 30 frames per second. Is it possible to stream that back with OWIN/KATANA? – Adam Nester Oct 23 '15 at 12:39
-
You specifically mentioned the – Moby Disk Oct 23 '15 at 14:10
-
https://gist.github.com/n3wtron/4624820. This is what I want to be able todo. I just noticed it uses the img tag so that is what I would use. – Adam Nester Oct 23 '15 at 14:25
-
1Ahhh, I see. That isn't using a video tag though. It looks to be sending a series of JPEG files. Kinda like this: http://stackoverflow.com/questions/2060953 – Moby Disk Oct 23 '15 at 14:33
1 Answers
1
app.Map("/Camera/Video", a =>
{
a.Run(context =>
{
string connectionid = CurrentDevice.Value.ToString();
object ret = DeviceManager.Instance.SendMessageToDevice(connectionid, "startmovie");
context.Response.Headers.Add("Content-Type", new string[] { "multipart/x-mixed-replace; boundary=--jpgboundary" });
bool con = true;
StreamWriter writer = new StreamWriter(context.Response.Body);
while (con)
{
using (MemoryStream ms = new MemoryStream())
{
Image img = (Image)DeviceManager.Instance.SendMessageToDevice(connectionid, "capturestill");
img.Save(ms, ImageFormat.Jpeg);
byte[] buffer = ms.GetBuffer();
writer.WriteLine("--jpgboundary");
writer.WriteLine("Content-Type: image/jpeg");
writer.WriteLine(string.Format("Content-length: {0}", buffer.Length));
writer.WriteLine();
context.Response.Write(buffer);
//writer.WriteLine(Convert.ToBase64String(buffer));
writer.Flush();
}
Thread.Sleep(200);
}
DeviceManager.Instance.SendMessageToDevice(connectionid, "stopmovie");
return context.Response.WriteAsync("");
});
});
I figured out what my issue was. I was using WriteAsync and I needed to use just the Write. The above works great. I just need to figure out how to stop it now.

Adam Nester
- 123
- 1
- 10