How to record audio from mic using FFmpeg aka audio grabbing

Recently a linuxer pointed out that in spite of the amazing and widespread capabilities of FFmpeg, I have just been focused upon its media conversion feature. If you take a look at all our previous ffmpeg articles, the guy is right. So, from now we will discuss other features of the superstar too, starting with audio recording.

Why don't you try out the command first and we will see later how it actually works.

[shredder12]$ ffmpeg -f oss -i /dev/dsp audio.mp3

Once you run this command you will see ffmpeg saving some data in the file audio.mp3. What is it? Its actually recording all the audio that is going through the device /dev/dsp. Try speaking something on your microphone and play the file.

We can even do some pretty cool stuff using the device /dev/dsp.

But first, what is this device /dev/dsp? It is an audio sampling and recording device, stands for Digital Signal processor. It converts audio signal(from microphone) to digital(for computer) and vice versa. This device only understands complete raw audio, playing an encoded file (mp3, ogg etc.) will just result in garbage sound. And by raw audio file I meant a meaningful music, you can literally give any file to this device as input and it will play it. All it care for are bits and bytes which is what every file is made of. Try playing any of your hard disk partition for fun sake .

[shredder12]$ cat /dev/sda1 > /dev/dsp

After doing that, you can say and actually mean "Windows doesn't sound good" .

8 Comments

Luis Alvarado (not verified)
August 5th, 2010 09:04 am
I have actually showed many of my students that on Ubuntu you can actually "hear a document file" by doing that. For example cat FILE > /dev/dsp cat FILE > /dev/audio But what i have been trying for almost a year now is a way to send data via waves of sound. what i mean is, you could in theory send files while listening to music. The computers next to each other would get the information via a mic and save the file. That way you could listen to music while working with sound. It is just a thing i came up for the curious part but i know there must be a way to do it. The tricky part would be the clients when the get the sound, they should somehow know what part of the sound is the file and what part is not. Like a high pitch or something that repeats itself in a cicle.
August 8th, 2010 09:50 am

Thats a brilliant thought. Its a pretty sneaky way of sending files. I don't have much experience in such form of communication but what if it could be used in a way similar to encryption, using some seed/keys to decipher the pattern. It could actually be turned into a secure way to communicating.

Luis Alvarado (not verified)
August 8th, 2010 11:08 pm
I agree. Yes when i have time i will continue the work. I find it very good to have the freedom to do this with my computer.
ulitkus (not verified)
August 13th, 2010 02:24 am
How about record both audio and video to a single file? Is it possible?
Minh (not verified)
October 18th, 2010 07:23 am
what about audio grabbing in Windows? what is the command line please?
Minh (not verified)
January 20th, 2011 09:31 am
i tried ffmpeg -f oss -i /dev/dsp audio.mp3 and got unknown input format: 'oss'
Minh (not verified)
January 20th, 2011 09:32 am
i got unknown input format: 'oss'
aungaung (not verified)
January 14th, 2011 08:18 am
hi, I am new to php. I use xampp and Window XP SP2. I want to know how to write source code for recording audio using FFMPEG. But I can't. I want to see some example source codes. If you can guide me, please guide me. I will very thank you.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Use syntax $$latex$$ to insert LaTeX formulas.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.