title: ffmpeg sws_scale YUV420p to RGBA not giving correct scaling result (c++)
body: <p>I am trying to scale a decoded YUV420p frame(1018x700) via sws_scale to RGBA, I am saving data to a raw video file and then playing the raw video using ffplay to see the result.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>sws_ctx = sws_getContext(video_dec_ctx-&gt;width, video_dec_ctx-&gt;height,AV_PIX_FMT_YUV420P, video_dec_ctx-&gt;width, video_dec_ctx-&gt;height, AV_PIX_FMT_BGR32, SWS_LANCZOS | SWS_ACCURATE_RND, 0, 0, 0);
  ret = avcodec_decode_video2(video_dec_ctx, yuvframe, got_frame, &amp;pkt);
      if (ret &lt; 0) {
          std::cout&lt;&lt;"Error in decoding"&lt;&lt;std::endl;
          return ret;
      }else{
          //the source and destination heights and widths are the same
          int sourceX = video_dec_ctx-&gt;width;
          int sourceY = video_dec_ctx-&gt;height;
          int destX = video_dec_ctx-&gt;width;
          int destY = video_dec_ctx-&gt;height;
  
          //declare destination frame
          AVFrame avFrameRGB;
          avFrameRGB.linesize[0] = destX * 4;
          avFrameRGB.data[0] = (uint8_t*)malloc(avFrameRGB.linesize[0] * destY);
  
          //scale the frame to avFrameRGB
          sws_scale(sws_ctx, yuvframe-&gt;data, yuvframe-&gt;linesize, 0, yuvframe-&gt;height, avFrameRGB.data, avFrameRGB.linesize);
  
          //write to file
          fwrite(avFrameRGB.data[0], 1, video_dst_bufsize, video_dst_file);
   }
  </code></pre>
  
  <p>Here is the result without scaling (i.e. in YUV420p Format)
  <a href="https://i.stack.imgur.com/am38V.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/am38V.gif" alt="Here is the result without scaling (i.e. in YUV420p Format)"></a></p>
  
  <p>Here is the after scaling while playing using ffplay (i.e. in RGBA format)
  <a href="https://i.stack.imgur.com/i83rm.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i83rm.gif" alt="enter image description here"></a></p>
  
  <p>I run the ffplay using the following command ('video' is the raw video file)</p>
  
  <pre><code>ffplay -f rawvideo -pix_fmt bgr32 -video_size 1018x700 video
  </code></pre>
  
  <p><strong>What should I fix to make the correct scaling happen to RGB32?</strong></p>