0
C++에서 YUV420p 이미지를 RGB24로 변환하고 C#의 바이트 배열에서 비트 맵을 생성하려고합니다.ffmpeg YUV420 ~ RGB24는 하나의 행만 변환합니다.
내 이미지 크기는 1920 w * 1020 h이고 ffmpeg 디코더는 linesizes = {1920, 960, 960} 인 데이터에 대해 3 개의 평면을 제공합니다. 하지만 sws_scale 후에는 linesize = 5760 인 하나의 평면으로 RGB 사진을 얻게됩니다. 올바르게 보이지 않습니다. 단지 한 행의 데이터 만 가져 오는 것이 아니라 (5760 * h)를 가져와야합니다. 내가 뭘 잘못하고있어? AVFrame의 linesize
필드 데이터의 총량입니다
//c++ part
if (avcodec_receive_frame(m_decoderContext, pFrame) == 0)
{
//RGB
sws_ctx = sws_getContext(m_decoderContext->width,
m_decoderContext->height,
m_decoderContext->pix_fmt,
m_decoderContext->width,
m_decoderContext->height,
AV_PIX_FMT_RGB24,
SWS_BILINEAR,
NULL,
NULL,
NULL
);
sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data, pFrame->linesize,
0, pFrame->height,
pFrameRGB->data, pFrameRGB->linesize);
//c# part (im reading data from pipe and its equal to c++ part)------------------------------------------------------------------
byte[] rgbch = new byte[frameLen];
for (int i=0; i<frameLen; i++)
{
rgbch[i] = Convert.ToByte(pipe.ReadByte());
}
if (rgbch.Length > 0)
{
var arrayHandle = System.Runtime.InteropServices.GCHandle.Alloc(rgbch,
System.Runtime.InteropServices.GCHandleType.Pinned);
var bmp = new Bitmap(1920, 1080,
3,
System.Drawing.Imaging.PixelFormat.Format24bppRgb,
arrayHandle.AddrOfPinnedObject()
);
pictureBox1.Image = bmp;
}
왜 그것이 맞지 않다고 생각하십니까? 평면 픽셀 데이터를 입력하고 각 행의 크기가 3 * 1920이고 전체 메모리 영역이 3 * 1920 * 높이 인 인터리브 된 픽셀 데이터를 가져옵니다. –
글쎄, 나는 3 * 1920 * 높이의 메모리 영역이 어디인지 이해하지 못한다. 'pFrameRGB-> data'에 3 * 1920 행만 있습니다 ... 전체 이미지의 경우 다른 모든 행이 필요합니까? .. – Aleksey
'sws_scale'의 반환 값은 무엇입니까? 출력 버퍼의 행 수인'pFrameRGB-> data' 여야합니다. 그 1이 아니라면 당신의 가정은 틀립니다. 실제로 1이면 뭔가 잘못 될 것입니다. –