title: How to access PiCamera start_preview data from fb0 using python
body: <p>I want to display picamera's preview on fb1 in raspberry pi 4.</p>
  <p>My environment is 64-bit aarch64 self compiled system.
  use vc4-fkms-v3d dtoverlay.</p>
  <p>It seems that the preview image was direct draw on fb0 by GPU, someone suggest rpi-fbcp, but it can't be compile on rpi4 due to lack dispmanx api.</p>
  <p>so I use python to implement a similar program, numpy.memmap open fb0, grab data, then write to fb1.
  it works and very fast! I can saw mouse point track was mirrored in realtime, even spinning gears of glxgear, but no luck with picamera's preview screen.</p>
  <p>the picamera's preview was live in fb0 and overlay everything, I can mirror everything below it.</p>
  <p>how to access the picamera's preview data? it shows on screen, but did not leave any footprint in fb0.</p>
  <p>python code:</p>
  <pre><code>import numpy as np
  fb0 = np.memmap('/dev/fb0', dtype='uint8',mode='r+', shape=(480,800,4))
  fb1 = np.memmap('/dev/fb1', dtype='uint8',mode='r+', shape=(240,240,2))
  img0 = fb0[0:240, 0:240]
  img1 = BGRAtoBGR565(img0)
  fb1[0:240,0:240] = img1
  </code></pre>
  <p>to produce preview image</p>
  <pre><code>from picamera import PiCamera
  camera = PiCamera()
  camera.start_preview(fullscreen=False,window=(0,0,240, 240))
  </code></pre>
  <p>I have tried python-mss, only grab image below preview screen too.</p>
  <p>I have tested mmalobj follow the tutorial to draw a crosshair on preview, it's so lag and throws many exceptions.</p>
  <pre><code>picamera.exc.PiCameraMMALError: no buffers available: Resource temporarily unavailable; try again later
  Traceback (most recent call last):
    File &quot;_ctypes/callbacks.c&quot;, line 232, in 'calling callback function'
    File &quot;/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py&quot;, line 1227, in wrapper
      self._pool.send_buffer(block=False)
    File &quot;/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py&quot;, line 1931, in send_buffer
      super(MMALPortPool, self).send_buffer(port, block, timeout)
    File &quot;/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py&quot;, line 1881, in send_buffer
      raise PiCameraMMALError(mmal.MMAL_EAGAIN, 'no buffers available')
  </code></pre>
  <p>It seems picamera's preview draws on screen directly and does not via /dev/fb0. I have found another project py-videocore6 which can access GPU memory, but I don't know where to grap video data.</p>