<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">I found that it was my mistake. I made the bitmap from the original YUV420P decoded frame. Maybe Bitmap constructor tiles the image when it sees that the data belongs to a bitmap with less width, because when I changed the bitmap size, I saw no distortion in the made bitmap. Anyway, now I changed the line:</div><div class="gmail_default"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><font face="monospace, monospace">var _frameBitmap = new Bitmap(1280, 720, _pDecodedFrame->linesize[0], PixelFormat.Format32bppPArgb, new IntPtr(_pDecodedFrame->data_0));</font></div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">to:</div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div><div><font face="monospace, monospace">var convertToPixFmt = AVPixelFormat.PIX_FMT_RGBA;</font></div><div><font face="monospace, monospace">SwsContext* _pConvertContext = FFmpegInvoke.sws_getContext(1280, 720, 0,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">        </span>1280, 720, convertToPixFmt,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">    </span>FFmpegInvoke.SWS_FAST_BILINEAR, null, null, null);</font></div><div><font face="monospace, monospace">AVFrame* _pConvertedFrame = FFmpegInvoke.av_frame_alloc();</font></div><div><font face="monospace, monospace">int convertedFrameAspectBufferSize = FFmpegInvoke.avpicture_get_size(convertToPixFmt, 1280, 720);</font></div><div><font face="monospace, monospace">byte* _pConvertedFrameBuffer = (byte*)FFmpegInvoke.av_malloc((uint)convertedFrameAspectBufferSize);</font></div><div><font face="monospace, monospace">FFmpegInvoke.avpicture_fill((AVPicture*)_pConvertedFrame, _pConvertedFrameBuffer, convertToPixFmt, 1280, 720);</font></div><div><font face="monospace, monospace">FFmpegInvoke.sws_scale(</font></div><div><font face="monospace, monospace"><span style="white-space:pre">    </span>_pConvertContext,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">      </span>&_pDecodedFrame->data_0,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">        </span>_pDecodedFrame->linesize,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">   </span>0,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">     </span>_pDecodedFrame->height,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">     </span>&_pConvertedFrame->data_0,</font></div><div><font face="monospace, monospace"><span style="white-space:pre">      </span>_pConvertedFrame->linesize);</font></div><div><font face="monospace, monospace">var _frameBitmap = new Bitmap(1280, 720, _pConvertedFrame->linesize[0], PixelFormat.Format32bppPArgb, new IntPtr(_pConvertedFrame->data_0));</font></div></div><div style="font-family:tahoma,sans-serif;font-size:small"><br></div><div style="font-family:tahoma,sans-serif;font-size:small">and now the Bitmap is made properly.</div><div style="font-family:tahoma,sans-serif;font-size:small">The next step is that how can I make all of these be done by the graphics card? I can decode the original H264 video by hardware based on what we may find in hw_decode.c, but the other problems like rendering the video on screen and omitting the decoded video move to physical memory for scaling and changing its format to RGB is my other problems.</div><div style="font-family:tahoma,sans-serif;font-size:small">Can you rewrite the above code so that no CPU gets involved and no move or copy in physical memory be necessary?</div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2019 at 3:11 PM hamidi <<a href="mailto:hamidi@gmail.com">hamidi@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small">With this <a href="https://pastebin.com/hpFUjRtG" target="_blank">code</a> I get this <a href="https://imgur.com/a/uWmBzQE" target="_blank">image</a>. What's wrong?</div></div>
</blockquote></div>