ffmpeg HIGH CPU, http streaming with libmp3lame

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

ffmpeg HIGH CPU, http streaming with libmp3lame

Zoltan Kerenyi Nagy
Hi All,

For some reason the CPU is insanely high, hitting almost all the time 100%,
I run ffmpeg on an ARM7 4 core embedded device.

This is the setup, how I do it:

ffserver -d -f /etc/ffserver.conf
ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm

##

/etc/ffserver.conf :

HTTPPort 4444
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 10
MaxClients 10
MaxBandwidth 1024
CustomLog -

<Feed audio.ffm>
    File /tmp/audio.ffm
    FileMaxSize 128M
</Feed>
#
<Stream audio>
    Feed audio.ffm
    Format mp2
    Audiocodec libmp3lame
    AudioBitRate 128
    AudioChannels 2
    AudioSampleRate 8000
    NoVideo
    StartSendOnKey
</Stream>

<Stream stat.html>
    Format status
    FaviconURL http://pond1.gladstonefamily.net:8080/favicon.ico
</Stream>

I was experimenting with these parameters, however the CPU usage never
changed:

ffmpeg -f alsa -i hw:0,0-ar 8000 http://localhost:4444/audio.ffm
ffmpeg -f alsa -i hw:0,0 -b:a 128k http://localhost:4444/audio.ffm

Do you have any idea, why this procedure  is so CPU intense? FFmpeg is
installed to my device via the Yocto Project, so the arm cpu was taken into
consideration, I checked the bblayer file.

Thanks,

Zoli
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Carl Eugen Hoyos-2
2019-02-04 21:31 GMT+01:00, Zoltan Kerenyi Nagy <[hidden email]>:

> I was experimenting with these parameters, however the CPU
> usage never changed:
>
> ffmpeg -f alsa -i hw:0,0-ar 8000 http://localhost:4444/audio.ffm
> ffmpeg -f alsa -i hw:0,0 -b:a 128k http://localhost:4444/audio.ffm
>
> Do you have any idea, why this procedure  is so CPU intense?

I am not sure iirc but FFmpeg requests a sample fmt from alsa
that alsa does not natively provide and therefore starts to do
useless conversions, you have to find out which format avoids
these.
(Iirc!)

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Lou Logan
In reply to this post by Zoltan Kerenyi Nagy
On Mon, Feb 4, 2019, at 11:31 AM, Zoltan Kerenyi Nagy wrote:
> Hi All,
>
> For some reason the CPU is insanely high, hitting almost all the time 100%,
> I run ffmpeg on an ARM7 4 core embedded device.
>
> This is the setup, how I do it:
>
> ffserver -d -f /etc/ffserver.conf
> ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm

You can see if libshine gives you better performance likely at the cost of quality per bit but it may not matter. You'll need to compile with "--enable-libshine" and encode with "-c:a libshine" unless it is the only MP3 encoder.

> ffmpeg -f alsa -i hw:0,0-ar 8000 http://localhost:4444/audio.ffm

Use the "-sample_rate" ALSA private option (before the input) if you want to change the sample rate, otherwise ffmpeg will use the default ALSA value of 48000 and resample to 8000.

https://ffmpeg.org/ffmpeg-devices.html#alsa
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Zoltan Kerenyi Nagy
Hi,

The CPU usage is still abobe 90% with libshine. Do you think that something
is buggy with my script?
https://pastebin.com/dyHK6ATh

Zoli

On Tue, 5 Feb 2019 at 01:19, Lou Logan <[hidden email]> wrote:

> On Mon, Feb 4, 2019, at 11:31 AM, Zoltan Kerenyi Nagy wrote:
> > Hi All,
> >
> > For some reason the CPU is insanely high, hitting almost all the time
> 100%,
> > I run ffmpeg on an ARM7 4 core embedded device.
> >
> > This is the setup, how I do it:
> >
> > ffserver -d -f /etc/ffserver.conf
> > ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm
>
> You can see if libshine gives you better performance likely at the cost of
> quality per bit but it may not matter. You'll need to compile with
> "--enable-libshine" and encode with "-c:a libshine" unless it is the only
> MP3 encoder.
>
> > ffmpeg -f alsa -i hw:0,0-ar 8000 http://localhost:4444/audio.ffm
>
> Use the "-sample_rate" ALSA private option (before the input) if you want
> to change the sample rate, otherwise ffmpeg will use the default ALSA value
> of 48000 and resample to 8000.
>
> https://ffmpeg.org/ffmpeg-devices.html#alsa
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Lou Logan
On Tue, Feb 5, 2019, at 8:15 AM, Zoltan Kerenyi Nagy wrote:
> Hi,
>
> The CPU usage is still abobe 90% with libshine. Do you think that something
> is buggy with my script?
> https://pastebin.com/dyHK6ATh
>
> Zoli

1. I've never used ffserver so I can't comment on that.

2. We don't provide support for scripts here: it complicates matters. Please just provide your actual, unscripted ff* commands and the complete console outputs in a reply (not a link).
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Zoltan Kerenyi Nagy
I see, however do you think it is normal that recording to 300 sec wav
segments digests 4% CPU, in contrast with streaming with mp3 conversion and
recording to wav at the same time digest 90-100% CPU on an ARM7 device
which has 4 cores an 625 Mhz CPU and 256MB ram?

On Tue, 5 Feb 2019 at 19:14, Lou Logan <[hidden email]> wrote:

> On Tue, Feb 5, 2019, at 8:15 AM, Zoltan Kerenyi Nagy wrote:
> > Hi,
> >
> > The CPU usage is still abobe 90% with libshine. Do you think that
> something
> > is buggy with my script?
> > https://pastebin.com/dyHK6ATh
> >
> > Zoli
>
> 1. I've never used ffserver so I can't comment on that.
>
> 2. We don't provide support for scripts here: it complicates matters.
> Please just provide your actual, unscripted ff* commands and the complete
> console outputs in a reply (not a link).
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

kumowoon1025


> On Feb 5, 2019, at 3:05 PM, Zoltan Kerenyi Nagy <[hidden email]> wrote:
>
> I see, however do you think it is normal that recording to 300 sec wav
> segments digests 4% CPU, in contrast with streaming with mp3 conversion and
> recording to wav at the same time digest 90-100% CPU on an ARM7 device
> which has 4 cores an 625 Mhz CPU and 256MB ram?

Probably not, even if there was an increase it shouldn’t be much more than twice at its worst


> On Feb 5, 2019, at 12:15 PM, Zoltan Kerenyi Nagy <[hidden email]> wrote:
>
> The CPU usage is still abobe 90% with libshine. Do you think that something
> is buggy with my script?
> https://pastebin.com/dyHK6ATh <https://pastebin.com/dyHK6ATh>

> #!/bin/bash
> folder="/home/$USER/recordings"
> ffserver -f /etc/ffserver.conf &
> sleep 2
>  
> mkfifo /tmp/fifo1 2>/dev/null
> mkdir -p "$folder"
>  
> while true;do
>     day=$(date '+%Y-%m-%d')
>     mkdir -p "$folder"/"$day"
>     ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm -f wav pipe:1 > /tmp/fifo1 &
>     ffmpeg -i /tmp/fifo1 -ss 0 -t 300 -ar 44100 "$folder"/"$day"/"$(date '+%Y-%m-%d__%H_%M')".wav
> done
>  
> exit 0

Does this script work? I am suspicious of the while loop with the fifo. Pretty sure it wouldn’t do what you want, there would be a break in the audio every five minutes. Maybe you could use the segment muxer?

ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm <http://localhost:4444/audio.ffm> -ar 44100 -f segment -strftime 1 -segment_time 300 %Y-%m-%d__%H_%M.wav

Only thing is it wouldn’t create the directory structure.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg HIGH CPU, http streaming with libmp3lame

Moritz Barsnick
In reply to this post by Zoltan Kerenyi Nagy
On Tue, Feb 05, 2019 at 21:05:33 +0100, Zoltan Kerenyi Nagy wrote:
> I see, however do you think it is normal that recording to 300 sec wav
> segments digests 4% CPU, in contrast with streaming with mp3 conversion and
> recording to wav at the same time digest 90-100% CPU on an ARM7 device
> which has 4 cores an 625 Mhz CPU and 256MB ram?

Did you read Carl Eugen's hint that there may be some format conversion
involved, which you can avoid if you request the correct format from
ALSA (IIUC)?

https://ffmpeg.org/pipermail/ffmpeg-user/2019-February/043140.html

Aprart from that, encoding to WAV (i.e. PCM) is extremely easy on the
CPU, unlike encoding to "more" compressed formats.

Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".