Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rtsp Player High memory, cpu usage #888

Open
DongkyuK25 opened this issue Nov 7, 2023 · 1 comment
Open

Rtsp Player High memory, cpu usage #888

DongkyuK25 opened this issue Nov 7, 2023 · 1 comment

Comments

@DongkyuK25
Copy link

im novice developer using c#. I made User Control for playing rtsp from emgu.cv. I used this user control for my main program for playing 9 rtsp. but when i used my user control 9 times, it makes my cpu overflow, more than 70% cpu usage, also 1.3GB memory usage. i don't know what's wrong with my code. please help me anyone used emgu.cv in c#. it doesn't matter when playing only one rtsp. also tell me if my code seems bad, how to fix it! i don't know reason. please help me as fast as you can! this is my code

capture = new VideoCapture(rtspUrl, VideoCapture.API.Ffmpeg);
capture.SetCaptureProperty(CapProp.Fps, frame);
capture.Start();

Task.Run(async () =>
{
while (isPlaying)
{
UpdateFrame();
await Task.Delay(1000 / frame);
Thread.Sleep(1);
}
});
}

using (Mat frame = new Mat())
{
capture.Retrieve(frame, 0);
if (!frame.IsEmpty)
{
using (Image<Bgr, byte> image =
frame.ToImage<Bgr, byte>())
{
lock (captureLock)
{
try
{
if (!isRecording && videoWriter !=null)
videoWriter.Dispose();
else if (isRecording && videoWriter != null)
{
if(frame!=null)
videoWriter.Write(frame);
}
}
catch (System.AccessViolationException) { }
}
pictureBoxRTSP1.Invoke((MethodInvoker)(() =>pictureBoxRTSP1.Image = image.ToBitmap()));
}
}
else
{
}
}

@emgucv
Copy link
Owner

emgucv commented Nov 9, 2023

Performance issue are usually a result of the Open CV implementation.

You can try Open CV for python. If the performance is the same as Emgu CV, you can report the bug to the Open CV team. It will need to be fixed on the Open CV side. Once it is fixed in Open CV, Emgu CV will have the fix included.

Sample Open CV for python code ( reference from https://www.geeksforgeeks.org/python-opencv-capture-video-from-camera/ ):


# import the opencv library 
import cv2 
  
  
# define a video capture object 
vid = cv2.VideoCapture("{your_rtsp_url}") 
  
while(True): 
      
    # Capture the video frame 
    # by frame 
    ret, frame = vid.read() 
  
    # Display the resulting frame 
    cv2.imshow('frame', frame) 
      
    # the 'q' button is set as the 
    # quitting button you may use any 
    # desired button of your choice 
    if cv2.waitKey(1) & 0xFF == ord('q'): 
        break
  
# After the loop release the cap object 
vid.release() 
# Destroy all the windows 
cv2.destroyAllWindows() 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants