Skip to content

Instantly share code, notes, and snippets.

@AlexanderVott
Last active May 18, 2020 06:24
Show Gist options
  • Select an option

  • Save AlexanderVott/2307db46c86f91dcf1eaf96d3eb09539 to your computer and use it in GitHub Desktop.

Select an option

Save AlexanderVott/2307db46c86f91dcf1eaf96d3eb09539 to your computer and use it in GitHub Desktop.
Скрипт для трансляции видео-потока с IK-камеры на экран для очков VR
from picamera import mmalobj as mo, mmal
from signal import pause
from time import sleep
camera = mo.MMALCamera()
splitter = mo.MMALSplitter()
render_l = mo.MMALRenderer()
render_r = mo.MMALRenderer()
encoder = mo.MMALVideoEncoder()
target = mo.MMALPythonTarget('low.h264')
camera.outputs[0].framesize = (400, 480)
camera.outputs[0].framerate = 30
camera.outputs[0].commit()
camera.outputs[1].framesize = (400, 480)
camera.outputs[1].framerate = 30
camera.outputs[1].params[mmal.MMAL_PARAMETER_CAPTURE] = True
camera.outputs[1].commit()
#encoder settings
encoder.inputs[0].framesize = (400, 480)
encoder.inputs[0].framerate = 25
encoder.inputs[0].format = mmal.MMAL_ENCODING_I420
encoder.inputs[0].commit()
encoder.outputs[0].format = mmal.MMAL_ENCODING_H264
encoder.outputs[0].bitrate = 2000000
encoder.outputs[0].commit()
p = encoder.outputs[0].params[mmal.MMAL_PARAMETER_PROFILE]
p.profile[0].profile = mmal.MMAL_VIDEO_PROFILE_H264_HIGH
p.profile[0].level = mmal.MMAL_VIDEO_LEVEL_H264_41
encoder.outputs[0].params[mmal.MMAL_PARAMETER_PROFILE] = p
encoder.outputs[0].params[mmal.MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER] = True
encoder.outputs[0].params[mmal.MMAL_PARAMETER_INTRAPERIOD] = 30
encoder.outputs[0].params[mmal.MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT] = 22
encoder.outputs[0].params[mmal.MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT] = 22
encoder.outputs[0].params[mmal.MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT] = 22
p = render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION]
p.set = mmal.MMAL_DISPLAY_SET_FULLSCREEN | mmal.MMAL_DISPLAY_SET_DEST_RECT
p.fullscreen = False
p.dest_rect = mmal.MMAL_RECT_T(0, 0, 400, 480)
render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p
p.dest_rect = mmal.MMAL_RECT_T(400, 0, 400, 480)
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])
encoder.inputs[0].connect(camera.outputs[1])
target.inputs[0].connect(encoder.outputs[0])
target.connection.enable()
encoder.connection.enable()
splitter.connection.enable()
target.enable()
encoder.enable()
splitter.enable()
render_l.enable()
render_r.enable()
try:
pause()
#test timer - switch with pause()
sleep(3)
finally:
# Disable everything and tear down the pipeline
target.disable()
encoder.disable()
#preview.disable()
splitter.disable()
render_l.disable()
render_r.disable()
target.inputs[0].disconnect()
encoder.inputs[0].disconnect()
#preview.inputs[0].disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment