Insanely high cpu usage for simple videocapture (50% cpu usage)

asked 2020-10-26 11:15:43 -0500

System information (version)

  • OpenCV => 4.4.0.44 (opencv-contrib-python)
  • Operating System / Platform => Windows 10 Pro 64 Bit
  • Compiler => Visual Studio Build Tools 2019 (MSVC VS2019, C++ Cmake)

I'm trying to do some image processing using python and an IP camera input stream (H264 encoded) using an rtsp link. However when I just do a simple capturing of the frames (using the default read operation) then I see really high cpu usage, insanely high just for reading out a stream. I did some digging and I found that this might be because it is not using the correct backend system for decoding the images. I see that you could use FFMPEG or Gstreamer or something. But most of those threads are quite old, doesn't opencv have support for this built in already?

import numpy as np
import cv2
import imutils

cap = cv2.VideoCapture("rtsp://admin:password@192.168.178.107")

while(True):
    ret, frame = cap.read()
    frame = imutils.resize(frame, width=400)

    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

What am I missing? I installed FFMPEG and tried to pass the apiPreference flag "cv2.CAP_FFMPEG" to it but it still uses 50% of my CPU (i'm running this on a NUC server)

edit retag flag offensive close merge delete

Comments

I see that you could use FFMPEG or Gstreamer or something.

on windows, it will use ffmpeg for ip streams by default (and prebuilt cv2 won't have any gstreamer support)

I installed FFMPEG

no, it will use the opencv_ffmpeg.dll that comes with your cv2 install

berak gravatar imageberak ( 2020-10-26 11:37:20 -0500 )edit

Ok thank you berak, so am I missing something? Why is it still using the cpu for the image processing? If i look at my task manager i can see that it barely uses any GPU, while using around 50% cpu

Rickvanhek gravatar imageRickvanhek ( 2020-10-26 13:26:51 -0500 )edit