CPU usage

RVMedia support and discussion (components for displaying and controlling IP cameras, webcams, video conferencing, video chats, recording audio and video files)
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

CPU usage

Post by Spartak86 »

Hello.

When using the component, the following situation arose: when starting the rtsp video stream, the computer processor load increases to 100%, and, as a result, the video stream slows down, and recording, respectively, also slows down, even when starting one camera. The picture shows the task managers when the TRVCamera and TPasLibVlcPlayer components are working: TRVCamera - loads the computer processor, TPasLibVlcPlayer uses a graphics processor, the video does not slow down. Somehow it is possible to solve this issue, to make the TRVCamera component use a GPU?

And at the same time, the question is: is it possible to record an rtsp video stream without running stream, that is, without executing the RVCamera1.PlayVideoStream command?
Thanks.
Attachments
TRVCamera vs VLC.png
TRVCamera vs VLC.png (170.49 KiB) Viewed 52072 times
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: CPU usage

Post by Sergey Tkachenko »

Is this TRVCamera linked with TRVCamView or TRVCamMultiView?
If yes, try to disconnect them and check CPU usage.
Probably, most of this CPU usage comes from TBitmap stretch drawing.
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

Tried two ways:

1 way

Code: Select all

RVCamera := TRVCamera.Create(Form1);
  RVCamera.URL := ListCams.Lines[Count];
  RVCamera.OnStartVideoStream := RVCameraStartVideoStream;
  RVCamera.Name := 'Cam' + IntToStr(Count);
  RVCamera.Tag := Count;

  RVCamSender.VideoSource := RVCamera;
  RVCamera.PlayVideoStream;
2 way

Code: Select all

RVCamera := TRVCamera.Create(Form1);
  RVCamera.URL := ListCams.Lines[Count];
  RVCamera.OnStartVideoStream := RVCameraStartVideoStream;
  RVCamera.Name := 'Cam' + IntToStr(Count);
  RVCamera.Tag := Count;
  
  vCam := TRVCamView.Create(Form1);
  vCam.VideoSource := RVCamera;
  
  RVCamera.PlayVideoStream;
RVCameraStartVideoStream Event

Code: Select all

rCam := TRVCamRecorder.Create(Form1);
    rCam.VideoSource := RVCamReceiver; // RVCamera  in the second case    
    rCam.OutputFileName := 'C:\RecCams\' + (Sender as TRVCamera).Name + '\' +
      'video' + '_' + IntToStr(DateTimeToUnix(Now)) + '.avi';
    rCam.Active := True;
In both cases, the effect is the same
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

You gave me an idea that seemed to help, I'm going to test it now

vCam := TRVCamView.Create(nil);

Instead of "Form1" "nil"

Thank you very much
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: CPU usage

Post by Sergey Tkachenko »

The Owner parameter of the constructor does not affect performance. The owner simply frees the component when the owner is freed itself.

Try testing without connecting senders and viewers.
Also, to understand what happens, we need to know how video is processed. Depending on the video source and available libraries, it may be played using FFmpeg, GStreamer or internal MJpeg decoding, and very different code is used in these cases.
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

That's right, changing the Owner parameter didn't help

Video source: "dahua IPC-HFW 2230 S 2" video camera via local network via rtsp stream by link "rtsp://admin:[email protected]/live"

In the folder with the generated "exe" there are "ffmpeg 64bit" libraries
Attachments
2022-04-07_14-22-55.png
2022-04-07_14-22-55.png (2.34 KiB) Viewed 52037 times
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: CPU usage

Post by Sergey Tkachenko »

Did you try to run it without displaying or sending video?
I still suppose that the most CPU-consuming operation is scaling of bitmaps when displaying.
In FMX version it must be much faster because performed by DirectX instead of GDI.
In the new version (that I plan to upload soon) there is an option for fast low-quality scaling.
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

Sergey Tkachenko wrote: Thu Apr 07, 2022 12:10 pm Did you try to run it without displaying or sending video?
Could you please explain what this means, I don't understand what you're talking about.

If you are talking about creating the TRVCamView component and assigning it the VideoSource RVCamera, then if I don't do this, then empty videoarchive files (5.5 kilobytes) are created for me

Code: Select all

vCam := TRVCamView.Create(nil);
vCam.VideoSource := RVCamera;
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: CPU usage

Post by Sergey Tkachenko »

You can see a high CPU usage when you recording a video file.

There are 3 processes occur on recording:
- receiving and decoding video
- encoding video
- displaying video

Most probably, only one of them have high CPU usage, so the first thing to understand what's happening is trying to separate these processes.
To do it, you can try to implement:
- "playing" video stream in TRVCamera without displaying it in TRVCamView and without recording it in TRVCamRecorder
- playing video stream in TRVCamera without displaying it in TRVCamView but with recording it in TRVCamRecorder
- playing video stream in TRVCamera displaying it in TRVCamView but without recording it in TRVCamRecorder
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

Thanks for the explanation

I have done the following tests (I run 8 video threads):

1.

Code: Select all

RVCamera := TRVCamera.Create(nil);
RVCamera.URL := ListCams.Lines[Count];
RVCamera.PlayVideoStream;
Result: CPU usage increased ~15-20%. That is, it works well

2.

Code: Select all

procedure TForm1.CreateCam(Count: integer);
var
  RVCamera: TRVCamera;
Begin
  RVCamera := TRVCamera.Create(Form1);
  RVCamera.URL := ListCams.Lines[Count];
  RVCamera.OnStartVideoStream := RVCameraStartVideoStream;
  RVCamera.PlayVideoStream;
End;

procedure TForm1.RVCameraStartVideoStream(Sender: TObject);
var
  rCam: TRVCamRecorder;
begin
    rCam := TRVCamRecorder.Create(Form1);
    rCam.VideoSource := (Sender as TRVCamera);
    rCam.OutputFileName := 'C:\RecCams\' + (Sender as TRVCamera).Name + '\' +
      'video' + '_' + IntToStr(DateTimeToUnix(Now)) + '.avi';
    rCam.Active := true;
end;
Result: CPU usage increased ~15-20% (as in the previous test). That is, it works well

3.

Code: Select all

RVCamera := TRVCamera.Create(Form1);
  RVCamera.URL := ListCams.Lines[Count];
  vCam := TRVCamView.Create(nil);
  vCam.VideoSource := RVCamera;
  RVCamera.PlayVideoStream;
Result: CPU usage increased ~50%.

ps. With the increase in the number of threads, the load is also growing.

When all components are activated, even when running four threads, the CPU load is 100%
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: CPU usage

Post by Sergey Tkachenko »

So, as thought, the CPU usage mostly comes from displaying.
And I quite sure, it is because of drawing bitmap using StretchDraw in half-tone mode.
Most probably, if you set vCam.ViewMode = vvmCenter, CPU usage will be lower.
In the new version, there will be an option to use non-half-tone StretchDraw which is faster and uses less CPU resources.
There are also options to change video rendering to OpenGL and DirectX, but currently they are deprecated - they will be restored and reworked in future updates.

About recording. Some property setting may lower CPU usage. For example, check, do you really need 25 frames per second? If not, you can lower rCam.VideoFramePerSec value.
Spartak86
Posts: 7
Joined: Thu Apr 07, 2022 5:26 am

Re: CPU usage

Post by Spartak86 »

Thank you very much for the advice, I will play with different recording parameters
I am waiting for updates on this problem, please let me know if you partially or completely solve this problem
I hope I have provided you with information for reflection.
ssli1133
Posts: 5
Joined: Tue Jun 28, 2022 10:00 am

Re: CPU usage

Post by ssli1133 »

I opened the 9rtsp video at the same time, and the CPU occupies my computer. I optimized it according to my own method, but it was still full. However, the CPU usage of VLC Midea playback is very low.
ssli1133
Posts: 5
Joined: Tue Jun 28, 2022 10:00 am

Re: CPU usage

Post by ssli1133 »

More than 4 link CPU are occupied
ssli1133
Posts: 5
Joined: Tue Jun 28, 2022 10:00 am

Re: CPU usage

Post by ssli1133 »

I looked at the Windows Explorer, and the program did not use the GPU for decoding, so the CPU usage was high.
Post Reply