Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG record output audio for Mac

Tags:

ffmpeg

I am trying to use ffmpeg recording screen as well as incoming audio on mac, but in the input device lists, there is no "speaker". Is there a way to get output audio?

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

configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
libavutil      55. 18.100 / 55. 18.100
libavcodec     57. 24.105 / 57. 24.105
libavformat    57. 26.100 / 57. 26.100
libavdevice    57.  0.101 / 57.  0.101
libavfilter     6. 34.100 /  6. 34.100
libswscale      4.  0.100 /  4.  0.100
libswresample   2.  0.101 /  2.  0.101
libpostproc    54.  0.100 / 54.  0.100
[AVFoundation input device @ 0x7fd5f9600360] AVFoundation video devices:
[AVFoundation input device @ 0x7fd5f9600360] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7fd5f9600360] [1] Capture screen 0
[AVFoundation input device @ 0x7fd5f9600360] [2] Capture screen 1
[AVFoundation input device @ 0x7fd5f9600360] AVFoundation audio     devices:
[AVFoundation input device @ 0x7fd5f9600360] [0] Soundflower (2ch)
[AVFoundation input device @ 0x7fd5f9600360] [1] Built-in Microphone
[AVFoundation input device @ 0x7fd5f9600360] [2] Soundflower (64ch)
: Input/output error
like image 773
hardier Avatar asked Feb 23 '16 23:02

hardier


People also ask

Can Ffmpeg take screenshots?

Quicktime Player is natively installed on most of Mac computers. This tutorial focuses on Linux and Mac. FFmpeg is a powerful command line tool that allows you to record your computer screen and your voice. You can also easily convert videos to several formats.


1 Answers

"Speaker" audio is your system audio - what Soundflower is giving you access to.

Given that the Soundflower options are recognized as AV Foundation audio devices and are displayed in the output generated by the ffmpeg avfoundation -list_devices command, a basic capture of your desktop ([1] Capture screen 0) and stereo system sound ([0] Soundflower (2ch)) would be:

ffmpeg -f avfoundation -i "1:0" Screen.mov

Note that the "1:0" is "[1] Capture screen 0:[0] Soundflower (2ch)"

I suspect that the reason your audio doesn't sound good is due to a bit depth discrepency. My Mac default audio is set to 24-bit. Per FFmpeg's audio documentation:

ffmpeg -sample_fmts
indicates that ffmpeg has these formats and bit depths available:

u8        8 
s16      16 
s32      32 
flt      32 
dbl      64 
u8p       8 
s16p     16 
s32p     32 
fltp     32 
dblp     64 
s64      64 
s64p     64 

...and I don't see 24 in there. Likely, your audio recording sounds poor because bits are getting truncated.

As Sarge Borsch notes, your Audio Midi Setup will show you what your bit depth and sample frequency are and give you some options. You could change your "speakers" in Audio Midi Setup.app >> Audio Devices::Built-in Output::Format until you find something that works, or you could specify the bit depth in the FFmpeg line command to match your settings. As far as I know FFmpeg will default to the bit depth of the source. Note, in Audio Midi Setup.app your "system audio" device will be indicated by a Finder icon and Speaker icon - I use an external monitor through my thunderbolt port and the "system" audio is routed to that device, not the Built-in Speakers. So depending upon your configuration simply changing your audio bit depth to 16 should work with the basic capture syntax:

ffmpeg -f avfoundation -i "1:0" Screen.mov

enter image description here

Of note, ffmpeg does handle 24 bit PCM audio:

$  ffmpeg -formats | grep PCM | grep 24
 DE s24be           PCM signed 24-bit big-endian
 DE s24le           PCM signed 24-bit little-endian
 DE u24be           PCM unsigned 24-bit big-endian
 DE u24le           PCM unsigned 24-bit little-endian
like image 176
MmmHmm Avatar answered Sep 19 '22 01:09

MmmHmm