user5715: Background
Recording a screen-cast (no audio) in Xubuntu Linux. The following image shows a side-by-side comparison of the video (left) versus the desktop (right):

The screen-cast is recorded using:
ffmpeg -r 30 -f x11grab -s $WIN_GEO -i :0.0+$WIN_XY -vcodec huffyuv -preset ultrafast -qp 0 output.mkv

Here, $WIN_GEO stores the browser dimensions (1030x794) and $WIN_XY has the browser location (1020x221).
$ cat /etc/issue
Ubuntu Trusty Tahr (development branch) \n \l

Problem
The colours in the video differ from the colours shown on the desktop, resulting in a slightly blurry playback. I have read that this could be due to conversion between RGB and YUV colours.
Question
How do you record a desktop video (screen-cast) that when played back (e.g., using mplayer, VLC, or ffplay) results in an exact match to the original desktop colours and crispness?
Related
Relevant pages:

http://www.unixuser.org/~euske/vnc2swf/
http://technically.us/pictures/test.html
http://ubuntuforums.org/showthread.php?t=1392026
https://askubuntu.com/questions/347574/how-to-do-screencasting-desktop-recording-with-high-quality-audio-and-video
http://step4wd.com/2012/08/03/recording-screencast-in-ubuntu-linux/
https://unix.stackexchange.com/questions/73622/how-to-get-near-perfect-screen-recording-quality
https://unix.stackexchange.com/questions/65970/washed-out-colours-with-screencast-software-but-not-screenshot-on-ubuntu-all-ve
https://trac.ffmpeg.org/wiki/How%20to%20grab%20the%20desktop%20%28screen%29%20with%20FFmpeg
http://rayslinux.blogspot.ca/2012/04/capturing-linux-desktop-via-command.html


user5715: Capturing the video frames in XWD format then converting to PNG yields results that are almost pixel perfect when encoded with ffmpeg.
Install xvidcap:
mkdir -p $HOME/dev
cd $HOME/dev
svn checkout svn://svn.code.sf.net/p/xvidcap/code/trunk xvidcap-code
cd xvidcap*
./autogen.sh
LIBS="-ldl -lX11 -lXext" ./configure --prefix=/usr/local
make && sudo make install

Capture stills at 25 frames per second:
mkdir -p $HOME/video
cd $HOME/video
xvidcap --fps 25 --quality 100 --cap_geometry 1024x768+768+288 --file out%05d.xwd

This creates a series of X Windows capture files inside $HOME/video. Convert the files to PNG format using ImageMagick then combine into a video:
for i in out*.xwd; do convert -define png:color-type=2 $i $(basename $i .xwd).png; done
ffmpeg -i out%05d.png -c:v huffyuv -preset veryslow -qp 0 -qscale:v 0 output.avi

An example script:
echo "Click window to capture..."

INFO=$(xwininfo -frame)
WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )

OUTPUT_DIR=$HOME/video

echo Capturing to $OUTPUT_DIR...
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR
cd $OUTPUT_DIR

WIN_XY=$(echo $WIN_XY | tr , +)

xvidcap --fps 25 --quality 100 --cap_geometry $WIN_GEO+$WIN_XY --file out%05d.xwd

# Convert captured images to PNG format
echo "Converting XWD to PNG..."
for i in out*.xwd; do convert -define png:color-type=2 $i $(basename $i .xwd).png; done

ffmpeg -i out%05d.png -c:v huffyuv -preset veryslow -qp 0 -qscale:v 0 output.avi

This creates a high-quality video that looks sharp with VLC, can be edited in OpenShot, and uploaded to various video hosts. Playback with MPlayer yields slightly fuzzy and off-coloured results.

5715: <h1>Background</h1>

<p>Recording a screen-cast (no audio) in Xubuntu Linux. The following image shows a side-by-side comparison of the video (left) versus the desktop (right):</p>

<p><img src="https://i.stack.imgur.com/lSXXY.png" alt="Lossless encoding"></p>

<p>The screen-cast is recorded using:</p>

<pre><code>ffmpeg -r 30 -f x11grab -s $WIN_GEO -i :0.0+$WIN_XY -vcodec huffyuv -preset ultrafast -qp 0 output.mkv
</code></pre>

<p>Here, <code>$WIN_GEO</code> stores the browser dimensions (1030x794) and <code>$WIN_XY</code> has the browser location (1020x221).</p>

<pre><code>$ cat /etc/issue
Ubuntu Trusty Tahr (development branch) \n \l
</code></pre>

<h1>Problem</h1>

<p>The colours in the video differ from the colours shown on the desktop, resulting in a slightly blurry playback. I have read that this could be due to conversion between RGB and YUV colours.</p>

<h1>Question</h1>

<p>How do you record a desktop video (screen-cast) that when played back (e.g., using mplayer, VLC, or ffplay) results in an <em>exact</em> match to the original desktop colours and crispness?</p>

<h1>Related</h1>

<p>Relevant pages:</p>

<ul>
<li><a href="http://www.unixuser.org/~euske/vnc2swf/" rel="nofollow noreferrer">http://www.unixuser.org/~euske/vnc2swf/</a></li>
<li><a href="http://technically.us/pictures/test.html" rel="nofollow noreferrer">http://technically.us/pictures/test.html</a></li>
<li><a href="http://ubuntuforums.org/showthread.php?t=1392026" rel="nofollow noreferrer">http://ubuntuforums.org/showthread.php?t=1392026</a></li>
<li><a href="https://askubuntu.com/questions/347574/how-to-do-screencasting-desktop-recording-with-high-quality-audio-and-video">https://askubuntu.com/questions/347574/how-to-do-screencasting-desktop-recording-with-high-quality-audio-and-video</a></li>
<li><a href="http://step4wd.com/2012/08/03/recording-screencast-in-ubuntu-linux/" rel="nofollow noreferrer">http://step4wd.com/2012/08/03/recording-screencast-in-ubuntu-linux/</a></li>
<li><a href="https://unix.stackexchange.com/questions/73622/how-to-get-near-perfect-screen-recording-quality">https://unix.stackexchange.com/questions/73622/how-to-get-near-perfect-screen-recording-quality</a></li>
<li><a href="https://unix.stackexchange.com/questions/65970/washed-out-colours-with-screencast-software-but-not-screenshot-on-ubuntu-all-ve">https://unix.stackexchange.com/questions/65970/washed-out-colours-with-screencast-software-but-not-screenshot-on-ubuntu-all-ve</a></li>
<li><a href="https://trac.ffmpeg.org/wiki/How%20to%20grab%20the%20desktop%20%28screen%29%20with%20FFmpeg" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/How%20to%20grab%20the%20desktop%20%28screen%29%20with%20FFmpeg</a></li>
<li><a href="http://rayslinux.blogspot.ca/2012/04/capturing-linux-desktop-via-command.html" rel="nofollow noreferrer">http://rayslinux.blogspot.ca/2012/04/capturing-linux-desktop-via-command.html</a></li>
</ul>
 5715: <p>Capturing the video frames in XWD format then converting to PNG yields results that are <em>almost</em> pixel perfect when encoded with ffmpeg.</p>

<p>Install <a href="http://xvidcap.sourceforge.net/" rel="nofollow">xvidcap</a>:</p>

<pre><code>mkdir -p $HOME/dev
cd $HOME/dev
svn checkout svn://svn.code.sf.net/p/xvidcap/code/trunk xvidcap-code
cd xvidcap*
./autogen.sh
LIBS="-ldl -lX11 -lXext" ./configure --prefix=/usr/local
make &amp;&amp; sudo make install
</code></pre>

<p>Capture stills at 25 frames per second:</p>

<pre><code>mkdir -p $HOME/video
cd $HOME/video
xvidcap --fps 25 --quality 100 --cap_geometry 1024x768+768+288 --file out%05d.xwd
</code></pre>

<p>This creates a series of X Windows capture files inside <code>$HOME/video</code>. Convert the files to PNG format using <a href="http://www.imagemagick.org/" rel="nofollow">ImageMagick</a> then combine into a video:</p>

<pre><code>for i in out*.xwd; do convert -define png:color-type=2 $i $(basename $i .xwd).png; done
ffmpeg -i out%05d.png -c:v huffyuv -preset veryslow -qp 0 -qscale:v 0 output.avi
</code></pre>

<p>An example script:</p>

<pre><code>echo "Click window to capture..."

INFO=$(xwininfo -frame)
WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )

OUTPUT_DIR=$HOME/video

echo Capturing to $OUTPUT_DIR...
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR
cd $OUTPUT_DIR

WIN_XY=$(echo $WIN_XY | tr , +)

xvidcap --fps 25 --quality 100 --cap_geometry $WIN_GEO+$WIN_XY --file out%05d.xwd

# Convert captured images to PNG format
echo "Converting XWD to PNG..."
for i in out*.xwd; do convert -define png:color-type=2 $i $(basename $i .xwd).png; done

ffmpeg -i out%05d.png -c:v huffyuv -preset veryslow -qp 0 -qscale:v 0 output.avi
</code></pre>

<p>This creates a high-quality video that looks sharp with <a href="http://www.videolan.org/vlc/index.html" rel="nofollow">VLC</a>, can be edited in <a href="http://www.openshotvideo.com/" rel="nofollow">OpenShot</a>, and uploaded to various video hosts. Playback with MPlayer yields slightly fuzzy and off-coloured results.</p>
