0

I have this code for detecting movement and recording said movement. This is my code:

import RPi.GPIO as GPIO

from picamera import PiCamera

import time

from datetime import datetime 

GPIO.setmode(GPIO.BCM)

PIR_PIN = 7

GPIO.setup(PIR_PIN, GPIO.IN)

camera = PiCamera()

try:
    time.sleep(5)
    print("Ready")

    while True:
        if GPIO.input(PIR_PIN):

            print("Motion Detected!")

            timestamp = time.strftime("%Y%m%d-%H%M%S")
            video_name = 'VID_' + timestamp + '.h264'

            camera.start_recording(video_name)
            time.sleep(10)
            camera.stop_recording()
            camera.stop_preview()

            time.sleep(2)
            print("Ready")

        time.sleep(1)

When I run the code I get this:

Ready
Motion Detected!

Traceback (most recent call last):
  File "/home/david/pir-camera-case/examples/pir-camera-code/videoproject.py", line 24, in <module>
    camera.start_recording(video_name)

  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1045, in start_recording
    encoder = self._get_video_encoder(

  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 722, in _get_video_encoder
    return encoder_class(

  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 600, in __init__
    super(PiVideoEncoder, self).__init__(

  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 187, in __init__
    self._create_encoder(format, **options)

  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 724, in _create_encoder
    raise PiCameraValueError(
picamera.exc.PiCameraValueError: output resolution 4096x2160 exceeds macroblock limit (8192) for the selected H.264 profile and level

I have been at this project for weeks setting this up and this is my last snag. Any help would be appreciated!!!

New contributor
Martin Culligan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • The error message seems clear. You need to correct the error.
    – joan
    Jun 21 at 15:21
  • I would try reducing the resolution!
    – CoderMike
    Jun 21 at 16:42
  • @CoderMike That worked. Many thanks Jun 21 at 21:30

0

Your Answer

Martin Culligan is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.