LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-22-2019, 01:15 AM   #1
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Rep: Reputation: Disabled
ffmpeg HIGH cpu usage while streaming


Hi Folks,

I have a streaming and recording script for an embedded ARM7 SoC. It's done under Yocto Project. The issue is the intense CPU usage around 97-100% for 1 core out of 4. Do you have any idea how could I distribute the streaming task over the 4 cores? I've been testing with -threads 4 ffmpeg option, with not much success. I double checked the Yocto recipie file, and ffmpeg was compiled with multi threading feature and to arm7 architecture.

here is the script:
Code:
#!/bin/bash

if [ ! -e $(uci get application.audio.ffserver_config) ];then
cat > $(uci get application.audio.ffserver_config) <<EOF

HTTPPort $(uci get application.audio.streaming_port)
HTTPBindAddress 0.0.0.0
MaxHTTPConnections $(uci get application.audio.max_http_conns)
MaxClients $(uci get application.audio.max_clients)
MaxBandwidth $(uci get application.audio.max_bandwidth)
CustomLog $(uci get application.audio.ffserver_log)

<Feed audio.ffm>
        File /tmp/audio.ffm
        FileMaxSize 32M
</Feed>

<Stream audio>
	Feed audio.ffm
        Format wav
        AudioCodec pcm_s16le
        AudioBitRate 256
        AudioChannels 2
        AudioSampleRate $(uci get application.audio.streaming_sample)
        NoVideo
        StartSendOnKey
</Stream>

<Stream stat.html>
        Format status
</Stream>
EOF
fi
#
ffserver -f $(uci get application.audio.ffserver_config) &
#
sleep 1

mkdir -p $(uci get application.audio.recording_path) || exit 1

mkdir -p $(uci get application.audio.recording_path)/$(date '+%Y-%m-%d') || exit 1

ffmpeg -f alsa -i hw:0,0 -acodec pcm_s16le -f segment -strftime 1 -segment_time $(uci get application.audio.duration) -segment_format wav -ar $(uci get application.audio.recording_sample) $(uci get application.audio.recording_path)/$(date '+%Y-%m-%d')/%Y-%m-%d__%H_%M_$(uci get application.audio.recording_sample)_$(sed 's/://g' /sys/class/net/eth0/address).wav -shortest http://localhost:$(uci get application.audio.streaming_port)/audio.ffm
 
Old 10-22-2019, 05:33 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by kzo81 View Post
I've been testing with -threads 4 ffmpeg option, with not much success.
That's not a valid statement.
Please do some troubleshooting, see if you can tickle ffmpeg to tell you why it doesn't do as you told it.
 
Old 10-22-2019, 05:49 AM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
if it is the one thread that is high cpu then it will be bound to the one cpu

I guess the scheduler could share the load, but I imagine that will just switch through the cores

I wouldn't expect wav encoding to be cpu intensive, but I have no idea what that SoC is

you could try adding audio bitrate/samplerate to the ffmpeg
I'm not certain if the application.audio.ffserver_config influences ffmpeg or if it just provides metadata to client
 
1 members found this post helpful.
Old 10-23-2019, 02:39 AM   #4
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
That's not a valid statement.
Please do some troubleshooting, see if you can tickle ffmpeg to tell you why it doesn't do as you told it.
Yes, you're right. I meant that I was debugging with inserting the -threads 4 to several places in the ffmpeg line, just after the -i option, before it, etc.
I seems it does not have any effect on how ffmpeg works internally.

Here it is:
Code:
ffmpeg -f alsa -i hw:0,0 -threads 4 -acodec pcm_s16le -f segment -strftime 1 -segment_time 300 -segment_format wav -ar 48000 /home/$USER/rec/$(date '+%Y-%m-%d')/%Y-%m-%d__%H_%M_.wav -shortest http://localhost:1234/audio.ffm

ffmpeg -f alsa -i hw:0,0 -acodec pcm_s16le -f segment -strftime 1 -segment_time 300 -segment_format wav -ar 48000 -threads 4 /home/$USER/rec/$(date '+%Y-%m-%d')/%Y-%m-%d__%H_%M_.wav -shortest http://localhost:1234/audio.ffm

ffmpeg -f alsa -i hw:0,0 -acodec pcm_s16le -threads 4 -f segment -strftime 1 -segment_time 300 -segment_format wav -ar 48000 /home/$USER/rec/$(date '+%Y-%m-%d')/%Y-%m-%d__%H_%M_.wav -shortest http://localhost:1234/audio.ffm

Last edited by kzo81; 10-23-2019 at 02:44 AM.
 
Old 10-23-2019, 02:45 AM   #5
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
no effect how the initial sample rate is set.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid 3 near 100% cpu usage and high RAM usage piman Linux - Software 1 11-16-2013 02:20 AM
mysql server not responding with high cpu usage and high load avgs landysaccount Linux - Server 2 09-15-2013 03:46 AM
[SOLVED] High CPU load, but low CPU usage (high idle CPU) baffy Linux - Newbie 5 03-13-2013 09:24 AM
High load and high cpu kernel usage enid Linux - Server 8 09-30-2010 03:33 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration