6

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?

0
6

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.

0
4

Note: This answer doesn’t use libav but this question comes up first when searching for “mac screen record command line” in Google.


As of macOS Catalina, you can now record screen from your command line using the screencapture tool with -v flag.

See the help page (screencapture --help) for a description of all options. The options listed in the man page may be incorrect.

Meanwhile, here are some examples:

  • Record your main screen until you hit Ctrl+C in Terminal. There is no stop button at the the menu bar.

    screencapture -v out.mov
    
  • Use -D 2 to use a secondary screen.

    screencapture -D 2 -v out.mov
    
  • Use -g to also record audio using the default input. (The man page stay -A but it did not work.)

    screencapture -v -g out.mov
    

Some general notes:

  • If the file already exists, recording will fail after the screen recording is completed. Please beware.

  • There is a little bit of delay after recording has started before it actually records your screen.

  • -i (interactive mode) does not work with -v.

  • -iU (interactive toolbar mode) works with -v, but it will not use the filename specified on the command line.

4
  • Yes! This is the solution I've been waiting for. Do you know what screencapture is looking for when asking for the audio device id in the -G command line option? I've tried the name of a device and an index but neither work: Capture audio device 1 not found.
    – cgenco
    May 15 '20 at 23:21
  • It works pretty well. Unfortunately, it does not work with -i (Capture screen interactively), at least not with video capturing. So, one has to use -R rectangle, and determine the rectangle by trial and error.
    – Gabriel
    Nov 28 '20 at 11:51
  • Is there any way to get screencapture to open with the menu bar to get the stop button?
    – Markus
    Oct 7 at 16:48
  • @Gabriel did you find any solution to specify the audio device?
    – Markus
    Oct 7 at 16:50
3

For taking screenshots (not movies) there is screencapture:

pse@Mithos:~$ screencapture -h
screencapture: illegal option -- h
usage: screencapture [-icMPmwsWxSCUtoa] [files]
  -c         force screen capture to go to the clipboard
  -C         capture the cursor as well as the screen. only in non-interactive modes
  -d         display errors to the user graphically
  -i         capture screen interactively, by selection or window
               control key - causes screen shot to go to clipboard
               space key   - toggle between mouse selection and
                             window selection modes
               escape key  - cancels interactive screen shot
  -m         only capture the main monitor, undefined if -i is set
  -M         screen capture output will go to a new Mail message
  -o         in window capture mode, do not capture the shadow of the window
  -P         screen capture output will open in Preview
  -s         only allow mouse selection mode
  -S         in window capture mode, capture the screen not the window
  -t<format> image format to create, default is png (other options include pdf, jpg, tiff and other formats)
  -T<seconds> Take the picture after a delay of <seconds>, default is 5
  -w         only allow window selection mode
  -W         start interaction in window selection mode
  -x         do not play sounds
  -a         do not include windows attached to selected windows
  -r         do not add dpi meta data to image
  -l<windowid> capture this windowsid
  -R<x,y,w,h> capture screen rect
  -B<bundleid> screen capture output will open in app with bundleidBS
  files   where to save the screen capture, 1 file per screen

For capturing video, the easiest way is to use the Screen Capture option in Quicktime Player. It even should be possible to initiate this from Terminal with some Applescript (which is beyond my skills).

2
-1

I can't get ffcast installed on mac (as it cant find libx11, though I installed xquartz), otherwise that would be perfect

https://github.com/lolilolicon/FFcast

You must log in to answer this question.

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