title: High Quality Screen Capture with FFmpeg
body: <p>I'm trying to figure out a command for high quality screen capture on REHL.</p>
  
  <p>I have tried various options, but none really worked. The quality is not good enough. I'm quite new to ffmpeg and doesn't quite understand all the different flags. So any help would be appreciated!</p>
  
  <p>The commands I have tried:</p>
  
  <pre><code>ffmpeg -y -f x11grab -r 30 -s 1920x1080 -i :0.0+0,0 -vcodec libx264 -strict -2 -b:v 16M output.mov
  </code></pre>
  
  <p>The first command I tried. The weird thing is it doesn't seem to preserve the bitrate specified <code>-b:v 16M</code>. The output video's bitrate is only 2mb/s. Is that not the correct way to specify bitrate when doing screen capture?</p>
  
  <pre><code>ffmpeg -f x11grab -s 1920x1080 -r 30 -i :0.0 -qscale 0 -vcodec huffyuv output.mov
  </code></pre>
  
  <p>The huffyuv codec is supposed to be lossless, but the quality doesn't seem to be any better than the libx264 output.</p>
  
  <pre><code>ffmpeg -f x11grab -r 30 -s 1920x1080 -i :0.0+0,0 -vcodec copy -pix_fmt yuv420p -qscale 0 -an output.mkv
  ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 30 -i output.mkv -an -c:v libx264 -qscale 0 result.mov 
  </code></pre>
  
  <p>I'm even trying to capture rawvideo and then convert it to libx264 codec viedeo. But the output is corrupted.</p>
  
  <p>I'm using the version of ffmpeg that's built on April 23rd this year. It doesn't have the preset like <code>-vpre lossless_ultrafast</code> which I see mentioned in a lot posts.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>After more research, this is the command I end up using. I have to use h264 codec and yuv420p as pixel_fmt since I need to be able to play the quicktimes using quicktime.</p>
  
  <pre><code>ffmpeg -y -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0+0,0 -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast output.mov
  </code></pre>
  
  <p>The quality doesn't seem to be much improved even though -qp is set to 0. But it could also because of the rgb conversion to yuv color space according to this post.</p>
  
  <p><a href="https://trac.ffmpeg.org/wiki/Encode/H.264" rel="noreferrer">https://trac.ffmpeg.org/wiki/Encode/H.264</a></p>