How to record a screencast (full desktop or a window) with ffmpeg

The official FFmpeg wiki gives you the following commands ...

# Linux wo audio
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0+100,200 output.flv
# Linux w audio
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0+100,200 -f alsa -ac 2 -i pulse output.flv
# Windows wo audio
ffmpeg -f dshow -i video="UScreenCapture" output.flv
# Windows w audio
ffmpeg -f dshow -i video="UScreenCapture":audio="Microphone" output.flv
# List available devices
ffmpeg -list_devices true -f dshow -i dummy
# Two phase recording (first record uncompressed, then compress)
# On Linux w audio ...
ffmpeg -f x11grab -r 25 -s 1024x768 -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
# On Windows w audio ...
ffmpeg -f dshow -i video="UScreenCapture":audio="Microphone" -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.flv
ffmpeg -i output.flv -acodec ... -vcodec ... final.flv

Some other blogs use a little different set of FFmpeg options:
ffmpeg -f alsa -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv

Essentially it's the same as the last one from the FFmpeg wiki, but the preset is defined via -vpre (instead of -preset) and it's value is lossless_ultrafast, which means there'll be no quality loss due to the double encoding. And -threads 0 gives FFmpeg all the available computing power there is.

In another blog post the use of xwininfo -frame is explained to get the capture width+height and the offset of the upper-left corner for FFmpeg's -s and -i options.