Hey everybody!<div><br></div><div>I've fixed my issue already :) </div><div>Yes, i needed to convert frames from BGR24 to YUV420p </div><div>and here how i do it:</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px">
<font face="arial, helvetica, sans-serif"><span style="color:#800080">AVFrame</span><span style="color:#c0c0c0"> </span>*</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#800080">Videocut</span>::convertFrameToYUV420(</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">AVCodecContext</span><span style="color:#c0c0c0"> </span>*aCtx,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">AVFrame</span><span style="color:#c0c0c0"> </span>*aFrame</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif">)</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif">{</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">if</span><span style="color:#c0c0c0"> </span>(NULL<span style="color:#c0c0c0"> </span>==<span style="color:#c0c0c0"> </span>aFrame<span style="color:#c0c0c0"> </span>||<span style="color:#c0c0c0"> </span>NULL<span style="color:#c0c0c0"> </span>==<span style="color:#c0c0c0"> </span>aCtx)<span style="color:#c0c0c0"> </span>{</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">return</span><span style="color:#c0c0c0"> </span>NULL;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#008000">/* NOTREACHED */</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>}</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">SwsContext</span><span style="color:#c0c0c0"> </span>*imgConvertCtx<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span>NULL;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">AVFrame</span><span style="color:#c0c0c0"> </span>*tempFrame<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial,helvetica,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,helvetica,sans-serif">imgConvertCtx</span><span style="font-family:arial,helvetica,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,helvetica,sans-serif">=</span><span style="font-family:arial,helvetica,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,helvetica,sans-serif">sws_getContext</span><span style="font-family:arial,helvetica,sans-serif">(</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">width</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">height</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">pix_fmt</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">width</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">height</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">PIX_FMT_YUV420P</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>SWS_BICUBIC,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>NULL,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>NULL,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>NULL</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">if</span><span style="color:#c0c0c0"> </span>(NULL<span style="color:#c0c0c0"> </span>==<span style="color:#c0c0c0"> </span>imgConvertCtx)<span style="color:#c0c0c0"> </span>{</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>cout<span style="color:#c0c0c0"> </span><<<span style="color:#c0c0c0"> </span><span style="color:#008000">"\nCan not initialize the conversion context\n"</span>;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">return</span><span style="color:#c0c0c0"> </span>NULL;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#008000">/* NOTREACHED */</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>}</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>tempFrame<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span>avcodec_alloc_frame();</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">if</span><span style="color:#c0c0c0"> </span>(NULL<span style="color:#c0c0c0"> </span>==<span style="color:#c0c0c0"> </span>tempFrame)<span style="color:#c0c0c0"> </span>{</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>sws_freeContext(imgConvertCtx);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">return</span><span style="color:#c0c0c0"> </span>NULL;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#008000">/* NOTREACHED */</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>}</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">int</span><span style="color:#c0c0c0"> </span>numBytes<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span>avpicture_get_size(<span style="color:#800080">PIX_FMT_YUV420P</span>,<span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">width</span>,<span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">height</span>);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>uint8_t<span style="color:#c0c0c0"> </span>*buffer<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#808000">new</span><span style="color:#c0c0c0"> </span>uint8_t[numBytes];</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>avpicture_fill(</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>(<span style="color:#800080">AVPicture</span><span style="color:#c0c0c0"> </span>*)tempFrame,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>buffer,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#800080">PIX_FMT_YUV420P</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">width</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">height</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>sws_scale(imgConvertCtx,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aFrame-><span style="color:#800000">data</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aFrame-><span style="color:#800000">linesize</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>aCtx-><span style="color:#800000">height</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>tempFrame-><span style="color:#800000">data</span>,</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>tempFrame-><span style="color:#800000">linesize</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>av_free(aFrame);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span>sws_freeContext(imgConvertCtx);</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><span style="color:#c0c0c0"> </span><span style="color:#808000">return</span><span style="color:#c0c0c0"> </span>tempFrame;</font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif">}</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre><pre style="margin-top:0px;margin-bottom:0px">
<font face="arial, helvetica, sans-serif">Cheers!</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif">gavlig</font></pre></div>