16

Is there a command we can use via terminal to start recording audio through my macbook microphone?

1 Answer 1

29

Use FFMPEG.

(This has become one of my favorite command line utilities for video/audio conversion and streaming). It's an open source framework for audio/video encoding, decoding, streaming, converting, and muxing. It's included with many (paid) AV utilities.

You can capture the audio as a stream through Apple's AVFoundation.

Get the device ID

$ ffmpeg -f avfoundation -list_devices true -i ""

[AVFoundation input device @ 0x7fda1bc152c0] AVFoundation video devices:
[AVFoundation input device @ 0x7fda1bc152c0] [0] FaceTime HD Camera (Built-in)
[AVFoundation input device @ 0x7fda1bc152c0] [1] Capture screen 0
[AVFoundation input device @ 0x7fda1bc152c0] AVFoundation audio devices:
[AVFoundation input device @ 0x7fda1bc152c0] [0] USB Audio CODEC
[AVFoundation input device @ 0x7fda1bc152c0] [1] Built-in Microphone

The device you're going to need is ":1" AVFoundation uses the convention "V:A" for "Video:Audio" so, if you want to capture video from your FaceTime camera the the audio from your Microphone, you would use "0:1". If you wanted just the audio only, you would use ":1" and leave the video out.

Record the Audio:

$ ffmpeg -f avfoundation -i ":1" -t 10 audiocapture.mp3

The above command will record 10 seconds of audio from the built in microphone and save it as audiocapture.mp3. You can set how long you want FFMPEG to record by changing the value for -t. If you want to record a full hour, set it to "3600".

$ ffmpeg -f avfoundation -i ":1" -t 3600 audiocapture.mp3

What the flags mean

  • -f = "force format". In this case we're forcing the use of AVFoundation
  • -i = input source. Typically it's a file, but you can use devices.
    • "0:1" = Record both audio and video from FaceTime camera and built-in mic
    • "0" = Record just video from FaceTime camera
    • ":1" = Record just audio from built-in mic
  • -t = time in seconds. If you want it to run indefinitely until you stop it (ControlC) omit this value (not recommended)

Input Volume

Keep in mind that you're using the built-in microphone which isn't great to begin with. Ensure that you set the gain high enough (System Preferences, Sounds) so that the Mic can hear you. It would probably be best to get a quality USB microphone instead.

10
  • 1
    This works great, thank you. What exactly is the -f, -i and -t here? What do they stand for? t = time? -i = input? -f = ??
    – user290246
    Commented May 27, 2018 at 9:16
  • 1
    Would it be possible to pipe the ffmpeg output into another command like SSH? ffmpeg -f avfoundation -i ":1" -t 10 | ssh user@host -. This doesn't work, ffmpeg complains "At least one output file must be specified"
    – user290246
    Commented May 27, 2018 at 10:03
  • 1
    It's not conducive to pipe the output to an SSH "stream". You can have ffmpeg stream to multiple outputs including a file and a stream (like streaming music) . See: trac.ffmpeg.org/wiki/Creating%20multiple%20outputs
    – Allan
    Commented May 27, 2018 at 15:19
  • 1
    Yikes. All the info on codecs and filtering is a little over my head. If I create a new question here, would you try to answer it?
    – user290246
    Commented May 27, 2018 at 15:24
  • I'll give it my best shot... I might not get to it right away..I am just responding to things at the moment..
    – Allan
    Commented May 27, 2018 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .