MacOS – How to do command-line video screen capture on OS X with libav

command linemacosscreen capture

On linux I can do something like:

avconv -f alsa -i pulse -f x11grab -r 25 -s 1400x1050 \
  -i :0.0+0,0 -vcodec libx264 -threads 4 \
  -acodec libmp3lame video.mkv

but of course the alsa and x11 driver should be different on OS X. How would this work to do command-line video screen-capture?

Best Answer

I found a solution that works really well. You're able to record with ffmpeg using an input device called avfoundation.

Here is an example command-line:

ffmpeg -f avfoundation -pix_fmt yuyv422 -i "1:1" -t 10 -vf crop=1280:720:1:65 -r 30 output.mkv
  • You may or may not get asked to specify -pix_fmt when this option is not included; it might be worth trying other formats to see if you get better performance.

  • As explained in the details link, -i selects both video and audio input. If you want to capture audio playing on your computer, you'll need something like iShowU Audio Capture.

    To get that to work, you'll need to press Option + F11, select iShowU Audio Capture as an input device and as an output device. You'll notice that once you select it as an output device that you can no longer hear the audio yourself through your speakers or headphones.

    A quick fix is opening Audio MIDI Setup, create a Multi-Output Device and adding iShowU Audio Capture and your normal output device. Select this new Multi-Output device in your sound outputs and there ya go, you can now hear the audio and have it captured.

    Unfortunately you aren't able to control the audio levels now...if someone knows a solution to this please let me know.

  • -t is the time in seconds to record.

  • -vf is very useful for cropping and offsetting. The current setting is cropped to 1280 width 720 height, offsetting 1 pixel to the left and 65 pixels from the top. You'll need to use a third party tool to get exact pixel measurements of your screen.

  • -r is framerate.