GStreamer + HLS stream taking up a massive amount of CPU

farzaa farzadoesstuff at
Mon Mar 25 23:33:06 UTC 2019

Hello all! Working on a rather tough problem lately that I've having a hard
time wrapping my head around.

I have an HLS livestream I'm reading from I want to grab one
frame per second from the livestream, and save it locally. But, I need to
stay real time. So, when I save an image from the stream, that image should
be very close to what is actually live. 

This isn't very difficult via GStreamer on the command line. 

But, I actually need to process the stream in Python (because I'm doing some
other processing on the frame before I save it). OpenCV actually has a
gstreamer integration that can be found  here

As for the code itself, it's quite simple:

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",

while True:
    success, frame =

This code is doing exactly what I want it to do. Saving one frame per second
and staying close to real time. This is why I do: max-buffers=1 drop=true
sync=false. I also have a one second sleep, since I only need to read one
frame per second.

The issue is, the above code takes up 250% of my machine's CPU (tested on
Windows, Linux, and OS X). I'm attempting to understand why this is the case
and what I can do to reduce CPU usage.

I'm having a hard time understanding why decoding a single frame from an HLS
stream leads to such high CPU usage. I've tried Python multithreading. 

Thanks for the help!

Sent from:

More information about the gstreamer-devel mailing list