Someone suggested I direct a copy of the unmodified X display to a file and afterwards convert that file to a general purpose video file. What commands would I use to do this on a Kubuntu system? (Edit: He said something about attaching a display port to a file.) If not possible, what is my best option for an excellent quality screen recording that does not depend on fast hardware?

Background: I tried using avconv with -f x11grab and some GUI programs. However, no matter what I try, the resulting video either has artifacts/ blurriness or is choppy (missing frames). This is probably due to CPU/ memory constraints.


  • Video quality must not be noticeably different from seeing the session directly on a screen, because the purpose is to demonstrate an animated application.
  • The final video must be in a common format that can be sent to Windows users and used on the web. I think H.264 MP4 should work.
  • The solution should not presume much prior knowledge. I am familiar with the command line and basic Linux commands, but I am still learning Linux and do not know much about video codecs.

What I already tried:

  • Best command so far: ffmpeg -f x11grab -s xga -r 30 -i :0.0 -qscale 0.1 -vcodec huffyuv grab.avi, then convert to mp4 with ffmpeg -i grab.avi -sameq -vcodec mpeg4 grab.mp4.
    • The picture quality is great, but on my test sytem it lags the computer. On a faster target system it does not lag, but frames are obviously skipped, making the video not very smooth.
    • I am still trying to figure out how to save the grab.avi file to SHM to see if that helps.
  • Using Istanbul and RecordMyDesktop GUI recorders
  • Simple command: avconv -f x11grab -s xga -r 25 -i :0.0 simple.mpg using avconv version 0.8.3-4:0.8.3-0ubuntu0.12.04.1
  • Adding -codec:copy (fails with: Requested output format 'x11grab' is not a suitable output format)
  • Adding -same_quant (results in great quality, but is very choppy/ missing many frames)
  • Adding -vpre lossless_ultrafast (fails with: Unrecognized option 'vpre', Failed to set value 'lossless_ultrafast' for option 'vpre')
  • Adding various values of -qscale
  • Adding various values of -b
  • Adding -vcodec h264 (outputs repeatedly: Error while decoding stream #0:0, [h264 @ 0x8300980] no frame!)
    • Note: h264 is listed in avconv -formats output as DE h264 raw H.264 video format

6 Answers 6


If your HDD allows, you can try to do it this way:

First write uncompressed file:

ffmpeg -f x11grab -s SZ -r 30 -i :0.0 -qscale 0 -vcodec huffyuv grab.avi

here SZ is your display size (e.g. 1920x1080).

After that you can compress it at any time you want:

ffmpeg -i grab.avi grab.mkv

Of course, you can change compression, select codec and so on.

  • 1
    See also: unix.stackexchange.com/a/120001/26227 Commented Mar 17, 2014 at 0:32
  • ubuntu 18.04 doesn't work fails: :0.0: Invalid argument Commented Nov 12, 2020 at 22:48
  • @user1325696, works pretty fine. E.g. ffmpeg -f x11grab -s 2560x1080 -r 30 -i :0.0 -qscale 0 -vcodec huffyuv grab.avi
    – Eddy_Em
    Commented Nov 13, 2020 at 9:56
  • Nowadays, this yields option qscale (use fixed quality scale (VBR)) cannot be applied to input - I guess this answer is not up-to-date anymore. Commented Apr 5, 2021 at 11:20

I've had success with:

ffmpeg -f x11grab -video_size 1920x1080 -framerate 30 -i :1 \
       -vcodec libx264 -preset ultrafast -qp 0 -pix_fmt yuv444p \

Key points:

  • -qp 0: x264 lossless mode
  • -preset ultrafast: smallest cpu usage, large size
  • -pix_fmt yuv444p: the default, but ffmpeg suggests yuv420p, which is lossy

Hint: capture screen and webcam overlay with:

ffmpeg -f x11grab -thread_queue_size 64 -video_size 1920x1080 -framerate 30 -i :1 \
       -f v4l2 -thread_queue_size 64 -video_size 320x180 -framerate 30 -i /dev/video0 \
       -filter_complex 'overlay=main_w-overlay_w:main_h-overlay_h:format=yuv444' \
       -vcodec libx264 -preset ultrafast -qp 0 -pix_fmt yuv444p \


[edit 20180418] Update for Gnome Shell and Wayland:

#!/usr/bin/env python3
from dbus import SessionBus, Interface
from os import getcwd, path
from sys import argv

BUS_NAME = 'org.gnome.Shell.Screencast'
PATH_NAME = '/org/gnome/Shell/Screencast'
PIPELINE='x264enc pass=qual quantizer=0 speed-preset=ultrafast ! queue ! matroskamux'

if path.isabs(argv[1]):
    name = argv[1]
    name = path.join(getcwd(), argv[1])

bus = SessionBus()
screen_cast = bus.get_object(BUS_NAME, PATH_NAME)
screen_cast = Interface(screen_cast, INTERFACE_NAME)

ret, name = screen_cast.Screencast(name, {'pipeline': PIPELINE})

if not ret:
    print('Error starting screencast.')
    raise SystemExit(1)

    i = input()
except (EOFError, KeyboardInterrupt):
  • how can i determine my screensize?
    – chovy
    Commented Dec 29, 2020 at 16:23
  • this works great, even while running a game which takes a lot of CPU, saves it with great quality, no frame dropping AFAIK, and reasonable file size
    – golimar
    Commented Feb 24, 2022 at 16:39

This is a workaround, and probably not "near-perfect" as it may depend on network speed or other factors that may hinder the video stream.

Use VNC or Teamviewer and connect from your laptop or desktop to the other machine. If you have a Windows or OSX laptop available, you probably have tools that can record this, and I believe teamviewer can record a session itself. It's easy to try, and you can then decide if the quality is good enough.

Teamviewer tends to scale, but I don't know if this happens with recorded sessions as well.

VNC does not compress or scale, and your laptop/desktop monitor needs a higher resolution than that of the other machine. The quality is good. Maybe the VNC viewer you use can record. I'm on Ubuntu now, and the standard viewer cannot do this.

Screen recording for displaying to an audience or on the web - there are special tools for this that can catch clicks, follow and zoom in on the mouse, and have other options to make more clear what you're doing. I suggest you take a look at those too. Google for "screen recording software".


Have you tried rfbroxy?

I use it to record X11-screen-sessions.

You can use it in a mode where it only records a picture, if there is a CHANGE.

−-type=WHAT WHAT=screen is even default, according to the man-page.

  • That's interesting. How do you do that? Commented Aug 14, 2020 at 13:47
  • @GunarGessner should be default behaviour. An alternate method is to react on mouse/keyborad events. This can be even better if you have got a clock on screen and do not want to make a picture when only that clock changes...
    – Nils
    Commented Aug 30, 2020 at 10:51

I am using Camtasia to record my gameplay video and online video. I also used fraps video recorder before but the fps drop during playing. Camtasia gives a higher fps but the only troublesome issue is that every time i must convert the output .CAMREC to avi as you can see in enter link description hereenter link description here. The .camrec is the proprietary format of camtasia and cannot be played on any third-party players like Windows Media Player and vlc.


Kazam outputs near-perfect quality with low overhead, or at least it allows recording while gaming on a mid-range PC. I don't know which library it uses but the output file has these formats:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Kazam_screencast_00000.mp4':
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2022-03-11T20:48:55.000000Z
    encoder         : x264
  Duration: 00:22:40.85, start: 0.000000, bitrate: 5826 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p(tv, bt709), 1680x1050 [SAR 1:1 DAR 8:5], 5706 kb/s, 20 fps, 20 tbr, 2k tbn, 40 tbc (default)
      creation_time   : 2022-03-11T20:48:55.000000Z
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 118 kb/s (default)
      creation_time   : 2022-03-11T20:48:55.000000Z
      handler_name    : SoundHandler

You must log in to answer this question.

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