wiki:

Capture

/

Desktop


Version 13 (modified by rogerdpack, 4 years ago) (diff)

--

Linux

Use the x11grab device:

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.flv

This will grab the image from desktop, starting with the upper-left corner at (x=100, y=200) with the width and height of 1024x768.

If you need audio too, you can use alsa like this:

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f alsa -ac 2 -i pulse output.flv

OS X

Use the avfoundation device:

ffmpeg -f avfoundation -list_devices true -i ""

This will enumerate all the available input devices including screens ready to be captured.

(Did not work for me; only webcam gets enumerated, desktop/audio devices do not. Any other prerequisites? -Vultaire)

Once you've figured out the device index corresponding to the screen to be captured use:

ffmpeg -f avfoundation -i "<screen device index>:<audio device index>" out.avi

This will capture the screen from <screen device index> and audio from <audio device index> into the output file out.avi.

Windows

Use a dshow device:

ffmpeg -f dshow -i video="screen-capture-recorder" output.flv

This will grab the image from entire desktop. Here is a list of alternative devices to use as well:

If you need audio too, you can use this:

ffmpeg -f dshow -i video="UScreenCapture":audio="Microphone" output.flv

If you want to capture the audio that is playing from your speakers, you may also need to configure so-called "Stereo Mix" device.

or

ffmpeg -f dshow -i video="UScreenCapture" -f dshow -i audio="Microphone" output.flv

You can list your devices with:

ffmpeg -list_devices true -f dshow -i dummy

There is also a "gdigrab" you can use to grab from the screen in windows (video)

Example recipe: live screen capture to webm

Here's a recipe used by one user for doing a live full-screen 1920x1080 screen capture to WebM format (VP8/vorbis). Note that you may need to tweak the -cpu-used or -b:v parameters depending on how fast your system is.

SET "audio_device=<audio_device>"
SET "video_device=<video_device>"
SET "threads=<physical cores minus 1>"
ffmpeg -f dshow -i audio="%audio_device%":video="%video_device%" -c:v libvpx -b:v 2M -deadline realtime -cpu-used -5 -threads %threads% -c:a libvorbis -y output.webm

It seems that the audio and video might not be perfectly in sync, but this should be a good starting point and may be "good enough" for some.

References:

General note

If you have a slow computer, it will not be smart to grab and encode your video at the same time, because slow CPU will not be able to do this. In that case, first grab all you need and save it as uncompressed video/audio and when you finish the grabbing process then start converting it to whatever you need:

Linux:

ffmpeg -framerate 25 -video_size 1024x768 -f x11grab -i :0.0+100,200 -f alsa -ac 2 -i pulse -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.flv
ffmpeg -i output.flv -acodec ... -vcodec ... final.flv

Windows:

ffmpeg -f dshow -i video="screen-capture-recorder":audio="Microphone" -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.flv
ffmpeg -i output.flv -acodec ... -vcodec ... final.flv