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 twitch.tv. 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
<
https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_gstreamer.cpp>
.
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",
cv2.CAP_GSTREAMER)
while True:
success, frame = cap.read()
save_frame(frame)
time.sleep(1.0)
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:
http://gstreamer-devel.966125.n4.nabble.com/_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel