title: Making a ffmpeg screen capture on Mac OS X using YUV 4:2:0 Planar color model
body: <p>I make screen recordings with <code>ffmpeg</code>, using <code>avfoundation</code> on <em>Mac OS X</em>, <code>x11grab</code> on <em>Linux</em> and <code>gdigrab</code> on <em>Windows</em>.</p>
  
  <p>The resulting files should be compatible with modern web browsers (<code>&lt;video/&gt;</code>), so I use H.264 codec and request YUV 4:2:0 Planar pixel format.</p>
  
  <p>On <em>Mac OS X</em>, however (unlike <em>Linux</em> and <em>Windows</em>), I receive the following logging:</p>
  
  <pre><code>/usr/local/bin/ffmpeg -y -v error -f avfoundation -threads 0 -hide_banner -i 1:none -f mp4 -vcodec h264 -pix_fmt yuv420p -r 25/1 -qscale:v 1 -vf scale=-1:1080 target.mp4
  [avfoundation @ 0x7fdba2003a00] Selected pixel format (yuv420p) is not supported by the input device.
  [avfoundation @ 0x7fdba2003a00] Supported pixel formats:
  [avfoundation @ 0x7fdba2003a00]   uyvy422
  [avfoundation @ 0x7fdba2003a00]   yuyv422
  [avfoundation @ 0x7fdba2003a00]   nv12
  [avfoundation @ 0x7fdba2003a00]   0rgb
  [avfoundation @ 0x7fdba2003a00]   bgr0
  </code></pre>
  
  <p>Still, according to <code>mplayer</code>, the resulting MP4 file seems to have YUV 4:2:0 Planar color model:</p>
  
  <pre><code>[h264 @ 0x1048a8ac0]Format yuv420p chosen by get_format().
  [h264 @ 0x1048a8ac0]Reinit context to 1728x1088, pix_fmt: yuv420p
  [h264 @ 0x1048a8ac0]Format yuv420p chosen by get_format().
  [h264 @ 0x1048a8ac0]Reinit context to 1728x1088, pix_fmt: yuv420p
  [swscaler @ 0x1048c3cc0]bicubic scaler, from yuv420p to yuyv422 using MMXEXT
  *** [scale] Exporting mp_image_t, 1728x1080x12bpp YUV planar, 2799360 bytes
  *** [vo] Allocating mp_image_t, 1728x1080x16bpp YUV packed, 3732480 bytes
  </code></pre>
  
  <p>the same confirmed by <code>ffmpeg</code>:</p>
  
  <pre><code>$ ffmpeg -i target.mp4 -hide_banner
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'target.mp4':
    Metadata:
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf58.20.100
    Duration: 00:00:04.72, start: 0.000000, bitrate: 201 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1728x1080, 197 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
      Metadata:
        handler_name    : VideoHandler
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Can someone explain the above <code>ffmpeg</code> logging?</li>
  <li>If I still need to convert the <code>avfoundation</code> video stream to <code>yuv420p</code>, how do I make it on the fly (in a single <code>ffmpeg</code> pass)?</li>
  </ol>