Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created December 19, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hermann-SW/f100b264a146793d7db3ff5969cd3b1c to your computer and use it in GitHub Desktop.
Save Hermann-SW/f100b264a146793d7db3ff5969cd3b1c to your computer and use it in GitHub Desktop.
# Live camera preview on main DPI display as well as HDMI0 monitor.
#
# Works only after running "rpi-update" until this commit will be available:
#
# https://github.com/raspberrypi/userland/commit/2549c149d8aa7f18ff201a1c0429cb26f9e2535a
#
# Values are Dispmanx display enums, therefore predominantly
# 0 = DSI/DPI LCD
# 2 = HDMI0
# 3 = SDTV
# 7 = HDMI1
# Behaviour should the chosen display not be present should be to
# revert to the primary display that is present.
#
# Based on this script:
#
# https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=232991&p=1582640#p1580053
#
from picamera import mmalobj as mo, mmal
from signal import pause
camera = mo.MMALCamera()
splitter = mo.MMALSplitter()
render_l = mo.MMALRenderer()
render_r = mo.MMALRenderer()
camera.outputs[0].framesize = (500, 500)
camera.outputs[0].framerate = 30
camera.outputs[0].commit()
p = render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION]
p.set = mmal.MMAL_DISPLAY_SET_FULLSCREEN | mmal.MMAL_DISPLAY_SET_DEST_RECT | mmal.MMAL_DISPLAY_SET_NUM
# 3 = SDTV -- not present, revert to main display (0 = DSI/DPI LCD)
p.display_num = 3
p.fullscreen = False
p.dest_rect = mmal.MMAL_RECT_T(0, 18, 500, 500)
render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p
# 2 = HDMI0
p.display_num = 2
p.dest_rect = mmal.MMAL_RECT_T(512, 18, 500, 500)
render_r.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p
splitter.connect(camera.outputs[0])
render_l.connect(splitter.outputs[0])
render_r.connect(splitter.outputs[1])
splitter.enable()
render_l.enable()
render_r.enable()
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment