14

Is there a command line tool out there that can record your computer screen and audio device and then save that to a file?

3
  • Any reason why this needs to be a CLI tool? You get screen capture for free with QuickTime.
    – igorw
    Jul 17, 2010 at 18:38
  • I would like to call it in a shell script and do it unattended.
    – Keith
    Jul 17, 2010 at 18:54
  • Hi Keith, welcome to StackOverlow. This doesn't look programming related at a glance, although it actually could be if you're planning to script it in a batch file or something. You might want to reword it so that it doesn't get closed out of hand. Jul 17, 2010 at 19:53

7 Answers 7

14

Mac OS X offers the ability to capture static screenshots from the command line using a utility called unimaginatively screencapture. You can find more information by running man screencapture.

eg. screencapture ~/Desktop/picture.png


As for recording motion and computer audio you can do this via AppleScript using QuickTime Player X if you're using Mac OS X 10.6 or newer. (However it's definitely not "silent" and will only run when someone is logged in)

(Recording the screen for 5 seconds, just a possible starting point)

tell application "QuickTime Player"
    --activate
    new screen recording
    start document 1
    delay 5
    stop document 1
    save document 1 in file "/tmp/test.mov"
    quit
end tell
4
  • screencapture only allows to do still images, no video or sound recordings.
    – MacLemon
    Jul 19, 2010 at 9:56
  • @MacLemon: Added some clarification.
    – Chealion
    Jul 19, 2010 at 21:20
  • 2
    FYI, just referencing a blog post that has improved version to the Quicktime Applescript above: netjunki.org/blog/…
    – David
    Jul 15, 2012 at 4:41
  • 1
    The blog @David mentioned is still available in Google's cache, and notes: "It seems that when you try and call save in 10.7 quicktime just ignores the call. Or something like that. The script will hang there forever and then time out." This is true for me in 10.8…
    – ptim
    Oct 16, 2014 at 6:02
2

I'm using SOX and VLC for capture, crontab for scheduling, XLD to create m4a and MP4Box for multiplexing. It is quite flexible, but requires knowledge of Bash scripting (perhaps also Apple script) I found my inspiration in Diego Massanti's mkmp4 script.

core processes to launch:

rec -q -c $C -r 48000 -b 16 $AFILE trim 0 $HH:$MM:00 &

VLC -I dummy screen:// --screen-fps=25 --quiet --sout "#transcode{vcodec=h264,vb=3072}:standard{access=file,mux=mp4,dst=$FILE}" --run-time $TIME vlc://quit

Scheduling recording:

crontab -l
0       8       *       *       1-5     ~/capture.sh 3 0 recording-name 1

you can get an idea what the script is doing: record 3h capture, mono sound, every working day at 8AM


I did not find nor compile SOX enabled for MPEG audio streams, hence using FLAC to save some space; I'm using XLD to convert it to AAC-HE 16kbps, which is enough for voice.

Next step: multiplex audio and video to create mp4. If you don't mind to use GUI, then MPEG StreamClip (or QuickTime) serves also well.

MP4Box -add $1.m4a -sbr -add $1.m4v -fps $2.0 -inter 500 $1.mp4

I'm using this daily to create archive of GoToWebinar, but when next release of FFmpeg supports G2M4 codec, I won't bother anymore. Yes, there's also OSAscript to launch the webinar which also required getting rid of com.apple.quarantine flag to disable warning (Are you sure you want to open it?).

links:

http://blog.massanti.com/2008/09/26/mkmp4-automated-h264-aacplus-encoder-script-mac-linux/

1
  • This may be related as well for VLC, there's a small quip about how to use it in this blog post: netjunki.org/blog/…
    – David
    Jul 15, 2012 at 5:00
2

You can use ffmpeg. To install it on a Mac, follow the instructions here. Then use the command:

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output.mkv
1
  • 2
    I doubt that would work on OSX, alsa and x11grab are likely only available on linux builds of ffmpeg.
    – Adam M-W
    Sep 10, 2014 at 7:45
0

For capturing screen, there is several Open Source tools. You should search "screen capture" using a package manager on Linux. Tools like scrot can be called in a script. If you plane to do it programatically, there is the needed entry points in Imlib2.

Capturing sound is really recording for microphone sound device. It's not really a snapshot and you should manage how long the recording should be done.Any sound recorder will do.

There is also tools that makes a video of your desktop.

0

Dumping the contents of the Linux framebuffer device to a file may be something similar to what you are looking for. Below, I have quoted the relevant portion of the Linux 2.2 Framebuffer Device Programming Tutorial, take a look. You will need to configure your system to enable the framebuffer device (check if you have /dev/fb0 on your system), I don't have it on my Ubuntu 9.04.

When you have got high-res textmodes, then you can start experimenting. You wi ll have a device /dev/fb0 that you can look at like any normal file. To take a screenshot, all you have to do is

cat /dev/fb0 > ~/sshot

And you will have a pretty big file with the contents of your graphics card's memory inside. Now, if you clear the screen, and type

cat ~/sshot > /dev/fb0

You should have a display that looks exactly like before. Of course, the secon d you start typing the display reverts to normal.

0

You can use import from ImageMagick, but it's Linux only. Then you could go to a terminal and execute:

import screenshot.png
0

I am also running Snow Leopard on an aging macbook and since I am trying to learn Objective C, I spend some time to build a tool that can capture specific windows.

https://github.com/vorgos/QuickGrab

It is a command line tool that will capture the top most active window or any window you specify.

Hope that helped.

You must log in to answer this question.