CPU usage
CPU usage
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.
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 (170.49 KiB) Viewed 52121 times
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: CPU usage
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.
If yes, try to disconnect them and check CPU usage.
Probably, most of this CPU usage comes from TBitmap stretch drawing.
Re: CPU usage
Tried two ways:
1 way
2 way
RVCameraStartVideoStream Event
In both cases, the effect is the same
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;
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;
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;
Re: CPU usage
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
vCam := TRVCamView.Create(nil);
Instead of "Form1" "nil"
Thank you very much
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: CPU usage
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.
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.
Re: CPU usage
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:Qq123456@172.17.1.246/live"
In the folder with the generated "exe" there are "ffmpeg 64bit" libraries
Video source: "dahua IPC-HFW 2230 S 2" video camera via local network via rtsp stream by link "rtsp://admin:Qq123456@172.17.1.246/live"
In the folder with the generated "exe" there are "ffmpeg 64bit" libraries
- Attachments
-
- 2022-04-07_14-22-55.png (2.34 KiB) Viewed 52086 times
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: CPU usage
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.
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.
Re: CPU usage
Could you please explain what this means, I don't understand what you're talking about.Sergey Tkachenko wrote: ↑Thu Apr 07, 2022 12:10 pm Did you try to run it without displaying or sending video?
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;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: CPU usage
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
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
Re: CPU usage
Thanks for the explanation
I have done the following tests (I run 8 video threads):
1.
Result: CPU usage increased ~15-20%. That is, it works well
2.
Result: CPU usage increased ~15-20% (as in the previous test). That is, it works well
3.
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%
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;
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;
3.
Code: Select all
RVCamera := TRVCamera.Create(Form1);
RVCamera.URL := ListCams.Lines[Count];
vCam := TRVCamView.Create(nil);
vCam.VideoSource := RVCamera;
RVCamera.PlayVideoStream;
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%
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: CPU usage
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.
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.
Re: CPU usage
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.
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.
Re: CPU usage
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.
Re: CPU usage
More than 4 link CPU are occupied
Re: CPU usage
I looked at the Windows Explorer, and the program did not use the GPU for decoding, so the CPU usage was high.