I try to stream live audio using ffmpeg and external USB microphone. I followed this nearly tutorial

I had to adapt some steps but finally, I achieved to receive the stream my laptop using this command :

ffmpeg -f oss -i /dev/dsp1 -acodec libmp3lame -ab 32k -ac 1 -re -f rtp rtp://

The CPU is near 100%, i have a bad sound during two seconds and after nothing... I see in Wireshark that the board is sending frames continuously.

Does someone have ideas to lower the CPU usage ?

  • You may want to look into overclocking and a different memory split. If you have the choice of codec you may be able to achieve some improvement by switching. You may also want to investigate compression of the stream - though this may be a zero some gain - anything you gain in transfer time may be lost in compression. Aug 5, 2012 at 22:46
  • Did you try writing to a local file first? I'd try to go step by step: 1) realtime recording to a wave file, 2) realtime recording to an mp3 file 3) streaming stuff over the network
    – pixelistik
    Aug 6, 2012 at 9:36
  • not at the moment. seems to be complicated to do all thoses steps manually instead of full automatic ffmpeg ;-)
    – hotips
    Aug 6, 2012 at 9:51
  • What are you recording? Aug 6, 2012 at 11:25
  • 1
    I'm trying to make an ethernet babyphone
    – hotips
    Aug 6, 2012 at 21:45

4 Answers 4


To answer your specific question, you can reduce CPU by piping arecord into ffmpeg:

arecord -f cd -D plughw:1,0 | ffmpeg -i - -acodec libmp3lame -ab 32k -ac 1 -re -f rtp rtp://

You'll need to replace plughw:1,0 with your specific sound card. See arecord -l for info. On my Rasp Pi it went from ~95% CPU to ~35%.


ALSA Input

One alternative is to go via ALSA. A similar command to above would be

ffmpeg -ac 1 -f alsa -i hw:0,0 -acodec libmp3lame -ab 32k -ac 1 -re -f rtp rtp://localhost:1234

I'm not sure how this will affect the CPU usage.

  • I tried : ffmpeg -ac 1 -f alsa -i hw:1,0 -acodec libmp3lame -ab 32k -ac 1 -re -f rtp rtp:// But ffmpeg crashes after somes seconds : [alsa @ 0x7a1510] ALSA buffer xrun. Any other ideas ?
    – hotips
    Aug 10, 2012 at 21:48
  • I tested ffmpeg -f oss -i /dev/dsp1 -ab 32k -ac 1 -re -f rtp rtp:// but the sound is very bad... on the lag is around 6 seconds. Any idea to have a better solution ?
    – hotips
    Aug 10, 2012 at 22:27
  • 1
    @si2w I think 32k for mp3 is a bit of a joke. Either up that, or try a different codec. Maybe one of the G2xx series designed for telephones Aug 11, 2012 at 7:47

This works and reduces cpu usage:

ffmpeg -f alsa -i default:CARD=U0x46d0x819 -acodec mp2 -ac 1 -re -f rtp rtp:// 2> /tmp/mylog.log &

Be sure to replace default:CARD=U0x46d0x819 with your microphone ID, ( obtained from arecord -l ) or you cad specify -i hw:0,0 (or whichever device it is).

I had a similar problem -- mp3 encoding took up 90%+ of cpu power and just could not keep up with the audio -- so I changed it to mp2 encoding. This used about 15-18% of CPU (measured vi top) and streams smoothly to VLC on my LAN. It would make a perfect baby monitor, or whatever. There is just a second or so delay, which is the buffering at the VLC end.

Note: The ip address is a multicast address ([224-239].x.y.z). You don't have to aim it at a particular network device on your LAN, and your broadband router will keep the traffic local (by default).


You can significantly reduce the CPU load by reducing the audio sample rate of the input device (-ar 8000 before -f alsa), and setting the codec audio bit rate to 128k (-b:a 128k). Also ironically reducing the number of channels (-ac 1) seemed to increase the CPU load so I have found this command runs at pretty low CPU:

ffmpeg -ar 8000 -f alsa -i hw:0 -acodec mp2 -b:a 128k -f rtp rtp://other:4444

Although one needs to remember that it also depends on the capabilities of the capture hardware one is trying to use, and the versions of ffmpeg/avconv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.