Created
February 13, 2017 22:00
-
-
Save 1kane/491b6e9646655daa551915844b9266be to your computer and use it in GitHub Desktop.
Test the new mmal methods from picam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from time import sleep | |
from picamera import mmal, mmalobj as mo, PiCameraPortDisabled | |
def main(output_filename): | |
camera = mo.MMALCamera() | |
preview = mo.MMALRenderer() | |
encoder = mo.MMALVideoEncoder() | |
target = mo.MMALPythonTarget(output_filename) | |
# Configure camera output 0 | |
camera.outputs[0].framesize = (640, 480) | |
camera.outputs[0].framerate = 24 | |
camera.outputs[0].commit() | |
# Configure H.264 encoder | |
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 | |
# Connect everything up and enable everything (no need to enable capture on | |
# camera port 0) | |
preview.inputs[0].connect(camera.outputs[0]) | |
encoder.inputs[0].connect(camera.outputs[1]) | |
target.inputs[0].connect(encoder.outputs[0]) | |
target.connection.enable() | |
encoder.connection.enable() | |
preview.connection.enable() | |
target.enable() | |
encoder.enable() | |
preview.enable() | |
try: | |
sleep(10) | |
finally: | |
# Disable everything and tear down the pipeline | |
target.disable() | |
encoder.disable() | |
preview.disable() | |
target.inputs[0].disconnect() | |
encoder.inputs[0].disconnect() | |
preview.inputs[0].disconnect() | |
if __name__ == '__main__': | |
main('output.h264') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment