picamera2 _encoder.output attribute error #983
Unanswered
denniscd12
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use picamera2 for video streaming over a local network. Within picamera2.Picamera2.start_encoder, I'm receiving the following error: self.start_encoder(encoder, output, pts=pts, quality=quality, name=name)
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1681, in start_encoder
_encoder.output = output
^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'output'
However, it seems that _encoder is a variable, so why is it listed as an object with an attribute of "output" (i.e., _encoder.output)? Here's my code:
import io
import picamera2
import logging
import socketserver
from threading import Condition
from http import server
PAGE="""\
<title>Raspberry Pi - Surveillance Camera</title>Raspberry Pi - Surveillance Camera
"""
class StreamingOutput(object):
def init(self):
self.frame = None
self.buffer = io.BytesIO()
self.condition = Condition()
class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
elif self.path == '/index.html':
content = PAGE.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', len(content))
self.end_headers()
self.wfile.write(content)
elif self.path == '/stream.mjpg':
self.send_response(200)
self.send_header('Age', 0)
self.send_header('Cache-Control', 'no-cache, private')
self.send_header('Pragma', 'no-cache')
self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME')
self.end_headers()
try:
while True:
with output.condition:
output.condition.wait()
frame = output.frame
self.wfile.write(b'--FRAME\r\n')
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', len(frame))
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
logging.warning(
'Removed streaming client %s: %s',
self.client_address, str(e))
else:
self.send_error(404)
self.end_headers()
class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
allow_reuse_address = True
daemon_threads = True
with picamera2.Picamera2() as camera:
opt = StreamingOutput()
#Uncomment the next line to change your Pi's Camera rotation (in degrees)
camera.rotation = 180
camera.start_recording(encoder='H264', output=opt, name='testvideo')
try:
address = ('0.0.0.0', '8000')
server = StreamingServer(address, StreamingHandler)
server.serve_forever()
finally:
camera.stop_recording()
Beta Was this translation helpful? Give feedback.
All reactions