0

I tried the mjpegStreamServer from here but it doesn't seems to work...

First of all, most times, after run it throws errors:

Exception in thread Thread-1:
Traceback (most recent call last):
File “/usr/lib/python2.7/threading.py”, line 552, in __bootstrap_inner
self.run()
File “stream2.py”, line 93, in run
self.camera.stop_preview()
AttributeError: ‘ImageProcessor’ object has no attribute ‘camera’

HTTP server started…

In that case HTTP server doesn’t respond with anything, but throws exception on connection:

0.0.0.0 – – [23/Jul/2015 18:52:50] “GET /1.mjpeg HTTP/1.1″ 200 –
—————————————-
Exception happened during processing of request from (‘217.153.167.44′, 60365)
Traceback (most recent call last):
File “/usr/lib/python2.7/SocketServer.py”, line 593, in process_request_thread
self.finish_request(request, client_address)
File “/usr/lib/python2.7/SocketServer.py”, line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File “/usr/lib/python2.7/SocketServer.py”, line 649, in __init__
self.handle()
File “/usr/lib/python2.7/BaseHTTPServer.py”, line 340, in handle
self.handle_one_request()
File “/usr/lib/python2.7/BaseHTTPServer.py”, line 328, in handle_one_request
method()
File “stream2.py”, line 139, in do_GET
stream = ImageProcessor.getInstance().getStream()
File “stream2.py”, line 122, in getStream
return self.buffer.get()
File “stream2.py”, line 29, in get
return self.data[-1]
IndexError: deque index out of range
—————————————-

But sometimes it does start correctly, but… when trying to see mjpeg on Chrome, it sends something forever, freezing raspberry… and nothing shows up… in log it looks like this:

HTTP server started…
Camera interface started…
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:00] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
0.0.0.0 – – [23/Jul/2015 18:58:01] “GET /1.mjpeg HTTP/1.1″ 200 –
(…)

Any help?

  • It's not MJPEG but I did a little demo of MPEG streaming (a real video format! yay!) a while back: github.com/waveform80/pistreaming.git (I've no idea why everyone wants something ancient like MJPEG ... unless they want to extract frames for analysis, then it's a tolerable choice if only because of the simplicity of frame extraction) – Dave Jones Jul 24 '15 at 14:14
  • That said, if you just want to pipe a straight MJPEG stream over the network just tweak this recipe so set format to 'mjpeg' on the start_recording line (although vlc won't like that as it's being told to decode h264). That won't work with a web-browser though as they don't understand MJPEG directly. – Dave Jones Jul 24 '15 at 14:17
  • @Dave Jones The problem is that I need it to be as responsive as possible... and demuxing H.264 stream seems to be too slow. – Flash Thunder Jul 25 '15 at 11:38
  • There's generally very little difference between decoding JPEG frames (which are larger than H.264 frames of all types) and decoding H.264 frames. That said, if you're basing the latency on experiments with things like raspivid or picamera output piped to VLC, then see Why is there so much latency when streaming video? (tl;dr: the client buffers a lot) – Dave Jones Jul 25 '15 at 15:10
  • Decoding, agree... encoding, don't agree. The problem is in encoding, not decoding. JPEG and not demuxed H.264 are nativly supported by camera module. But to send JPEG as MJPEG, you dont need much processing, but to send demuxed H.264, you need to totally recode the stream... that takes sometimes more time that the stream length itself. And mostly it is about 90% of time. So this is totally usless especially when other processes have to work in background on RPI. – Flash Thunder Jul 26 '15 at 0:38
0

I was looking for the same thing earlier today so I just wrote an example, that's located here: https://gist.github.com/smerkousdavid/c994956b45b000eac4275939b6a6c78d. It allows three interfaces so adding it to the raspberrypi shouldn't be too difficult. Depending on what camera you're using you can select which interface you are going to use, such as pycamera I would create a BytesIO() object and save the image to that then on the MjpgServer class access the pull method with like so

def pull():
  return True, bytearray(picamstream.getvalue(), 'utf8')

Just remember that when using PiCamera don't have the capture loop within the pull method. If you want to hardcode it into the MjpgServer that might be easier here is another SO post that might help you out on getting that stream: https://stackoverflow.com/questions/24947322/bytesio-stream-to-numpy-arrays-picamera

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.