title: avcodec YUV to RGB
body: <p>I'm trying to convert an YUV frame to RGB using libswscale.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>AVFrame *RGBFrame;
  SwsContext *ConversionContext;
  
  ConversionContext = sws_getCachedContext(NULL, FrameWidth, FrameHeight, AV_PIX_FMT_YUV420P, FrameWidth, FrameHeight, AV_PIX_FMT_RGB24, SWS_BILINEAR, 0, 0, 0);
  RGBFrame = av_frame_alloc();
  
  avpicture_fill((AVPicture *)RGBFrame, &amp;FillVect[0], AV_PIX_FMT_RGB24, FrameWidth, FrameHeight);
  
  sws_scale(ConversionContext, VideoFrame-&gt;data, VideoFrame-&gt;linesize, 0, VideoFrame-&gt;height, RGBFrame-&gt;data, RGBFrame-&gt;linesize);
  </code></pre>
  
  <p>My program do SEGFAULT on the sws_scale function.</p>
  
  <p>VideoFrame is an AVFrame struct who hold my decoded frame.</p>
  
  <p>I think this is because the YUV frame come from avcodec_decode_video2, which return an array like this :</p>
  
  <pre><code>VideoFrame-&gt;data[0] // Y array, linesize = frame width
  VideoFrame-&gt;data[1] // U array, linesize = frame width/2
  VideoFrame-&gt;data[2] // V array, linesize = frame width/2
  </code></pre>
  
  <p>While YUV420P have theoretically only one plane (according to Wikipedia, YUV420P is a planar format, then Y, U, V data are grouped together).
  So, i don't know how to proceed to convert my array where Y, U, V data are separated into RGB24, using swscale.</p>
  
  <p>Please help me, thanks :)</p>