Screen Recording – How to Achieve Near-Perfect Quality with FFmpeg and X11

avconvffmpegkubuntuscreencastingx11

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.

Goals:

  • 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

Best Answer

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.

Related Question