Calculate the attenuation and optimize CPU usage from encoding stream

ldvhai
ldvhai used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
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).
Fractional CTO
Distinguished Expert 2018
Commented:
Easy way to reduce ffmpeg CPU churn is to remove all video codec options you've specified, replacing them all with...

-c:v copy

Open in new window


This means the CPU is only running packet copy operations, rather than running x264 in background to produce h.264 compressed footage.

Tip: Compressing footage will always run 100% of all threads near max... even for slow frame rates + low bit rates.

Trick: If you must generate compressed footage, add -preset superfast or -preset ultrafast as both these presets will unload the CPU by roughly the same burden, with ultrafast producing a much smaller output stream.

Author

Commented:
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.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
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.

Author

Commented:
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.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
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).
David FavorFractional CTO
Distinguished Expert 2018

Commented:
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.
nociSoftware Engineer
Distinguished Expert 2018

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial