Link to home
Start Free TrialLog in
Avatar of ldvhai
ldvhai

asked on

Calculate the attenuation and optimize CPU usage from encoding stream

Dear Experts,

I'm currently using ffmpeg on RaspberryPi 4 (4 CPU, 4GB RAM, 16GB SD Card) for encoding bitrate from Camera (experimental environment).

As my first though when running encode process, from 1024Kbps input (Camera) to 512Kbps output (RaspPi4), the CPU consumption/ usage is quite a lot: 220->260% in the total 400% CPU Power (4 CPU).

This is my encode command:
/usr/bin/ffmpeg -re -rtsp_transport tcp -i rtsp://testing:testing123@172.16.1.200:554/Streaming/Channels/101 -an -c:v libx264 -b:v 512k -strict experimental -flags +global_header -f flv rtmp://172.16.1.201:1935/RTMP/testing-storage

Open in new window


I just wondering if there is anything I could do to reduce this CPU consumption.
And if i keep using that RaspPi with that much CPU, how long till it go down? What I mean is, can we calculate the attenuation, and the time the device can be used with such a load?

Many thanks for reading this Experts.
Avatar of noci
noci

Does the CPU run hot?   if so did you try to put a set of heat dissipation ribs on it?
with CPU fan?..

As long as the CPU can get rid of the heat you can keep it running at full throttle.
is the GPU active? are you using encodings that are supported with the GPU for hardware compressions (might need an extra license).
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ldvhai

ASKER

Dear Mr.David,

I'm trying to reduce the bandwidth going outside the Internet by compressing/ encoding the stream to lower bitrate, so your trick about preset parameter - which was tested a whole day - is very helpful :)

And about the second question of my problem, i'll be very appreciate if you can share some experience on calculating the attenuation when using the RaspPi or other devices with such a load, or perhaps just some keywords for researching.

Thanks and best regards.
I have the impression attenuation is a translation... what do you exactly mean with it:
See this for clarification: https://en.wikipedia.org/wiki/Attenuation

I you mean Heat dissipation (radiation of heat) then the amount of electrical power is the best measrement.
5V @ 2Amps is 10W (10 Watts), worst case option for Raspberry PI.

You may assume almost all energy used will goto heat. You may need to measure the current to get an estimate.
modern CPU's will throttle back clockspeed, or # of active CPU's to limit this waste of cycles.
Avatar of ldvhai

ASKER

Dear Experts,

I think I had use the wrong word to describe my question, so we have misunderstanding some.

What I actually mean is, "How long will my device go down/ die with such a load? (over 80%CPU usage or more)"

I'm really sorry for this inconvenience.

Thanks and best regards.
As long as the CPU does not overheat then it can run on sustained full CPU load.
The setup of a Raspberry PI is not ideal for that, you will need cooling fins & use thermo paste in mounting them to have a cpu run continuously.
Also you need an encasing that will allow air to pass to help cooling the fins.

Examples are here: https://www.makeuseof.com/tag/keep-raspberry-pi-cool/

Modern CPU's have some extra power for short bursts. allowing some cooldown a little later. They will also throttleback if programmed correctly.
(RPi  may need up to date firmware for that, there were issues with it earlier this year).
1) I'm trying to reduce the bandwidth going outside the Internet by compressing/ encoding the stream to lower bitrate, so your trick about preset parameter - which was tested a whole day - is very helpful :)

This is very different than optimizing CPU usage during transcoding.

How you do this relates directly to codecs available on the player end.

For example, HEVC (h.265) produces best compression + highest quality + smallest data stream at the expense of taking massive CPU resources. It's unclear if a Raspberry could even run real time HEVC compression.

Also the player side is a consideration here. If you're using Set Top devices like Rokus or VLC for playback, then HEVC will work. If you're doing browser playback, currently many mobile browsers will work + almost 100% of all Desktop browsers will fail.

Suggestion: Open another question about producing high quality, highly compressed bitstreams. This will likely require replacing your Raspberry.

2) And about the second question of my problem, i'll be very appreciate if you can share some experience on calculating the attenuation when using the RaspPi or other devices with such a load, or perhaps just some keywords for researching.

Unsure what "attenuation" might mean. Maybe you mean bit stream quality, which will directly relate to your starting device CPU resources + playback codec available.

3) "How long will my device go down/ die with such a load? (over 80%CPU usage or more)"

As noci suggested any CPU can run at high CPU usage in bursts.

Also, any CPU can run at 100% all the time, if suitable cooling is available.

For example, if you run a 60X core Intel CPU at 100% all the time (like running back to back HEVC transcodes), then you'll likely use a closed loop liquid coolant system for your CPU.

So you can run your CPU at 100% all the time, if you have budget for correct cooling.

Tip: Likely you won't be using a Raspberry for an application like this, as you'd have to rip out the Raspberry board + cobble on some custom cooling system.

Suggestion: For continual video stream transcoding... best open a new question describing your exact type of transcoding situation, asking for design assistance.
RPi 4 does have HEVC hardware on board and FFMpeg in recent version should start seeing code to support it.

This article seem to indicate the HEVC hardware is decode assistence only.
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=243873&p=1490349&hilit=RPI4+CPU+H.265+encoding#p1490349

H.264 encoding seems achievable: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=258545&p=1576322&hilit=RPI4+CPU#p1576322

For Realtime encoding HEVC files: https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=255078&p=1556065&hilit=RPI4+CPU+H.265+encoding#p1556065

Which implicates linking up with some other systems dto do the actual GPU assisted encoding.