Ok. We're moving now into live streaming this. I thought this would be very straightforward yet I've not been able to get it operational. My streaming server (NGINX0 works and the other code (server code, etc) are correctly calibrated to handle the stream. It had been operational when using the older Raspivid-->FFMPEG code.
Here is the streaming code. (Obviously my server is blocked out).
This code always yields the error:
[NULL @ 0x5555b27a1200] Unable to find a suitable output format for 'rtmp://34.106
.245.116/live/pcr1720361196451j'
rtmp://34.106.245.116/live/pcr1720361196451j: Invalid argument
Neither I (nor Chat GPT) can find the problem.
Here is the streaming code. (Obviously my server is blocked out).
Code:
#!/usr/bin/python3# Encode and stream a pair of side-by-side 1000x1000 image streams to give 2000x1000 video at ~15fps.from picamera2 import Picamera2, MappedArrayfrom picamera2.encoders import H264Encoderfrom picamera2.outputs import FfmpegOutputfrom libcamera import Transformimport timeimport osimport sysfrom threading import Lock# Base RTMP server URLrtmp_base_url = "rtmp://#,#,#,#/live/"# Append variable to the RTMP URL if provided as an argumentstream_key = sys.argv[1]rtmp_url = f"{rtmp_base_url}{stream_key}"# Set video parametersfps = 15height = 1000bitrate = 2000000 # 2 Mbpsleftsize = (2 * height, height) # define 2:1 format for left main streamrightsize = (height, height) # define 1:1 right main streamFrameTime = int(1000000 / fps)# Select fastest full format sensor modebinned2x2ffmode = 2# Initialize the locklock = Lock()# Merge views of left and right camerasdef mergeviews(request): global cam2_request with lock: request_2 = cam2_request if request_2 is None: return request_2.acquire() with MappedArray(request, "main") as m1, MappedArray(request_2, "main") as m2: # fill left half of original left array with half-width downsampled left camera view m1.array[:, :height] = m1.array[:, ::2] # fill right half of left array with 1:1 right camera view m1.array[:, height:] = m2.array request_2.release()def save_request(request): global cam2_request with lock: # Store most recent request for use by other camera if cam2_request is not None: cam2_request.release() request.acquire() cam2_request = request# Initialize cameraslcam = Picamera2(0)rcam = Picamera2(1)# Select best modemode = lcam.sensor_modes[3]# Calculate dimensions for crop of central square full height region of sensorsensorsize = lcam.camera_properties['PixelArraySize']sensorwidth = sensorsize[0]sensorheight = sensorsize[1]x = (sensorwidth - sensorheight) // 2crop = (x, 0, sensorheight, sensorheight)# Configure both cameras for full format mode and croppinglconfig = lcam.create_video_configuration(sensor={"output_size": mode['size'], 'bit_depth': mode['bit_depth']}, main={"format": "RGB888", "size": leftsize}, controls={"ScalerCrop": crop, "FrameDurationLimits": (FrameTime, FrameTime)}, transform=Transform(hflip=True, vflip=True), queue=False)rconfig = lcam.create_video_configuration(sensor={"output_size": mode['size'], 'bit_depth': mode['bit_depth']}, main={"format": "RGB888", "size": rightsize}, controls={"ScalerCrop": crop, "FrameDurationLimits": (FrameTime, FrameTime)}, transform=Transform(hflip=True, vflip=True), )lcam.configure(lconfig)rcam.configure(rconfig)# Prepare to encode and output to RTMP streamencoder = H264Encoder(bitrate)output = FfmpegOutput(rtmp_url)lcam.start()rcam.start()cam2_request = Nonercam.pre_callback = save_requestlcam.pre_callback = mergeviews# Short delay to allow Ae and AWB to settle, and avoid recording unprocessed first frametime.sleep(1)# Start streaming indefinitely until stopped manuallylcam.start_recording(encoder, output)# Infinite loop to keep streamingtry: while True: time.sleep(1)except KeyboardInterrupt: # Stop streaming when interrupted (Ctrl + C) lcam.stop_recording()
[NULL @ 0x5555b27a1200] Unable to find a suitable output format for 'rtmp://34.106
.245.116/live/pcr1720361196451j'
rtmp://34.106.245.116/live/pcr1720361196451j: Invalid argument
Neither I (nor Chat GPT) can find the problem.
Statistics: Posted by MRV — Thu Oct 31, 2024 1:12 pm