Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I try to stream live audio using ffmpeg and external usb microphone. I followed this nearly tutorial : http://prupert.co.uk/2010/08/02/stream-live-audio-from-a-microphone-in-near-real-time-in-ubuntu.

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://192.168.28.116:1234

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 ?

Thanks !

share|improve this question
    
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. –  Steve Robillard Aug 5 '12 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 '12 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 '12 at 9:51
    
What are you recording? –  Alex Chamberlain Aug 6 '12 at 11:25
    
I'm trying to make an ethernet babyphone –  hotips Aug 6 '12 at 21:45
add comment

3 Answers 3

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.

share|improve this answer
    
I tried : ffmpeg -ac 1 -f alsa -i hw:1,0 -acodec libmp3lame -ab 32k -ac 1 -re -f rtp rtp://192.168.1.116:1234 But ffmpeg crashes after somes seconds : [alsa @ 0x7a1510] ALSA buffer xrun. Any other ideas ? –  hotips Aug 10 '12 at 21:48
    
I tested ffmpeg -f oss -i /dev/dsp1 -ab 32k -ac 1 -re -f rtp rtp://192.168.28.116:1234 but the sound is very bad... on the lag is around 6 seconds. Any idea to have a better solution ? –  hotips Aug 10 '12 at 22:27
    
@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 –  Alex Chamberlain Aug 11 '12 at 7:47
add comment

this works without the cpu usage problem.

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

replace default:CARD=U0x46d0x819 with your microphone id,( obtained from arecord -l ) or use hw:0,0 (or whichever device it is).

I had similar problem, mp3 encoding takes up 90%+ of cpu power and just could not keep up with the audio, so I changed it to mp2 encoding instead. This uses about 15-18% of cpu (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 target it at a particular network device on your lan; and your broadband router will keep the traffic local (by default).

share|improve this answer
add comment

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://234.5.5.5:1234

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%.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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