0

I am working on a web app using Django on the server side and I'd like to stream from the camera to the browser. I already tried methods like HLS with the ffmpeg segment muxer, but with such methods I don't have the full control over the stream. So I thought about sending the video manually over a websocket and then playing it with Media Source Extensions.

On the server side I use UV4L and OpenCV to capture the video, but I found no good way of writing a segment over a websocket, because OpenCV only writes the data to a file. The only possible solution I found involves some changes to OpenCV itself.

Does anyone know an alternative or how to do this?

dav20011
  • 71
  • 3
  • 14
  • You could try to read the file's output inside a loop and stream each chunk every n milliseconds. – Mr. bug Oct 29 '17 at 17:57
  • I forgot to explain why that is a problem. I only use a flash storage for the Pi and I don't want to destroy it by constant write operations. – dav20011 Oct 29 '17 at 19:58
  • Have you tried with tmpfs ? https://www.howtoforge.com/storing-files-directories-in-memory-with-tmpfs in memory directories, you won't use your flash storage. You will also have to delete each chunk from the file or you could exhaust your allocated memory . – Mr. bug Oct 29 '17 at 20:08
  • It kind of depends what the other end is expecting. Do you have a specification of what formats/containers/codecs Media Source Extensions can handle? – Mark Setchell Oct 29 '17 at 22:06
  • MSE doesn't add any new supported formats, so I am pretty much limited to MP4 H.264. It just makes it possible to put a video together out of multiple segments. tmpfs is a possible solution, but I think that there should be a better one. I also found out that OpenCV works with GStreamer, but then I need to split the video with it. – dav20011 Oct 29 '17 at 22:29

1 Answers1

0

Here's a minimalistic example that uses in-memory Redis key-value store. The Redis database is an intermediary between continuous camera capture process and a Tornado web server:

https://github.com/vmlaker/hello-websocket

Velimir Mlaker
  • 10,664
  • 4
  • 46
  • 58