Open lida2003 opened 23 hours ago
I just used python code for test, which is much better.CPU is 300%, and it reached 22 FPS with software encoding.
As I'm 64bit bookworn OS. It might be the same as Pi4, which do not have hardware encorder "libOMX_Core.so".
import socket
import subprocess
import numpy as np
import picamera2
import time
import cv2 # Import OpenCV module
# Set up RTP streaming
rtp_host = "192.168.1.19"
rtp_port = 5400
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Use ffmpeg to encode video with specified profile and level
ffmpeg_command = [
'ffmpeg',
'-f', 'rawvideo',
'-pix_fmt', 'yuv420p', # Change to YUV 4:2:0 pixel format
'-s', '640x480', # Frame size
'-r', '30', # Frame rate
'-i', '-', # Input from stdin
'-c:v', 'libx264', # Use H.264 codec
'-profile:v', 'baseline', # Set profile to baseline
'-level', '5.0', # Set level to 5
'-f', 'rtp', # Output format
f'rtp://{rtp_host}:{rtp_port}'
]
process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE)
camera = picamera2.Picamera2()
camera.configure(camera.create_video_configuration(main={"size": (640, 480)}))
camera.start()
try:
while True:
frame = camera.capture_array()
# Convert frame to YUV 4:2:0
frame_yuv = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420)
process.stdin.write(frame_yuv.tobytes()) # Send the frame to ffmpeg
time.sleep(0.033) # Sleep for ~30 FPS
except KeyboardInterrupt:
pass
finally:
camera.stop()
process.terminate()
sock.close()
Tried 32bit bookworm, Not good!
Current code on my RPI3B+ bookwrom system, FPS can't be more over 6.5.
The performance is significantly degraded, any way to boost?