title: Downloading an MJPEG stream frame by frame
body: <p>I've got an IP camera set up and I can browse to its IP and get an MJPEG stream, I'm trying to download it frame by frame so I can analyse the images on another server. However I'm having troubles reading the stream. My code is: </p>
  
  <pre><code>import cv2
  import urllib.request
  import numpy as np
  import ssl
  
  ctx = ssl.create_default_context()
  ctx.check_hostname = False
  ctx.verify_mode = ssl.CERT_NONE       
  
  stream = urllib.request.urlopen('https://x.x.x.x:8602/Interface/Cameras/GetJPEGStream?Camera=Bosch%20NBE6502AL%20Bullet&amp;ResponseFormat=XML&amp;AuthUser=username&amp;AuthPass=password',context=ctx)
  bytes = ''
  while True:
      bytes += stream.read(1024)
      a = bytes.find('\xff\xd8')
      b = bytes.find('\xff\xd9')
      if a != -1 and b != -1:
          jpg = bytes[a:b+2]
          bytes = bytes[b+2:]
          i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.CV_LOAD_IMAGE_COLOR)
          cv2.imshow('i', i)
          if cv2.waitKey(1) == 27:
              exit(0)  
  </code></pre>
  
  <p>It gives me the following error: </p>
  
  <pre><code>Traceback (most recent call last):
  File "mjpeg.py", line 15, in &lt;module&gt;
  bytes += stream.read(1024)
  TypeError: can only concatenate str (not "bytes") to str
  </code></pre>
  
  <p>I think the stream outputs strings, but how do I go about converting the stream to bytes and saving the file? </p>
  
  <p>Kind regards,</p>
  
  <p>Ellens</p>