I have the following code that creates a gstreamer pipeline to process an HLS stream.
cap = cv2.VideoCapture(
f"souphttpsrc is_live=true location={hls_stream_link} ! hlsdemux !
queue ! decodebin ! videorate ! video/x-raw,framerate=1/1 !
videoconvert ! appsink max-buffers=1 drop=true sync=false",
cv2.CAP_GSTREAMER)
I now read the stream like this:
while True:
success, frame = cap.read()
time.sleep(1.0)
Note, I read the stream at 1 FPS and have the properties max-buffers=1 drop=true sync=false. By doing this, I always grab the latest frame from the stream the buffer has to offer.
The issue with this is the CPU usage is extremely high, spiking to 120% at times on my i7 machine. Removing the sleep would make it worse.
Any solutions or ideas as to why processing an HLS stream is so CPU intensive would be fantastic. Also, ideas on how to reduce usage would also be great.