title: What is the GLFW screen format for ffmpeg encoding?
body: <p>I have a program where I have a GLFW window and read that window using <code>glReadPixels(0, 0,window_width, window_height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) Buffer);</code> then use that <code>Buffer</code> to encode a frame via ffmpeg. It works fine however the resolution is a bit low.</p>
  <p>I tried changing bit-rates to no avail so I started experimenting with formats. Normally I'm using <code>AV_PIX_FMT_YUV420P</code> in my encoder as my format since the data that comes from the glfw window is RGBA but this format result in the said low resolution video. The result video is a lot more pixelated than whats seen on the GLFW window.</p>
  <p>What could be the optimal pixel format for reading GLFW window? Some formats straight up not work resulting in <code>Specified pixel format  yuyv422 is invalid or not supported</code> error.</p>
  <p>And here is where I got that error from:</p>
  <pre class="lang-c prettyprint-override"><code>ret = avcodec_open2(c, codec, &amp;opt);
  </code></pre>
  <p>This line causes me to get <code>Specified pixel format  yuyv422 is invalid or not supported</code> error when I use something other than YUV420.</p>
  <p>I also have this setting <code>#define SCALE_FLAGS SWS_BICUBIC</code> which im not sure what it does but may also cause my error. (Not likeliy since this comes after the line mentioned above, but I could just keep the format at YUV420 and change <code>SWS_BICUBIC</code> instead.)</p>
  <p>I'm using ubuntu, ffmpeg, glfw and glad (GLSL) to render the texture writeen in the frames. I got the encoder from ffmpegs <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c" rel="nofollow noreferrer">muxing.c</a> example.</p>
  <p>Edit: Using <code>AV_PIX_FMT_RGBA</code> also results in a similar error.</p>
  <p>Edit: Here is my sample code where I convert <code>Buffer</code> to ffmepg format:</p>
  <pre class="lang-cpp prettyprint-override"><code>#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
  ...
  void video_encoder::set_frame_yuv_from_rgb(AVFrame *frame, struct SwsContext *sws_context) {
      const int in_linesize[1] = { 4 * width };
  
      sws_context = sws_getContext(
              width, height, AV_PIX_FMT_RGBA,
              width, height, STREAM_PIX_FMT,
              SWS_BICUBIC, 0, 0, 0);
  
      sws_scale(sws_context, (const uint8_t * const *)&amp;rgb_data, in_linesize, 0,
              height, frame-&gt;data, frame-&gt;linesize);
  }
  </code></pre>