ffmpeg/libav에서 RGB 프레임을 YUV420P 포맷으로 변환하려고합니다. 다음은 변환 코드와 변환 전후의 이미지입니다. 변환 된 이미지는 모든 색상 정보를 잃고 스케일도 크게 변경됩니다. 아무도 이것을 어떻게 처리 할 생각이 있습니까? 나는 완전히 ffmpeg/libav에 익숙하다!ffmpeg : RGB에서 YUV로 변환시 색상과 스케일이 없어집니다.
// Did we get a video frame?
if(frameFinished)
{
i++;
sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame->data,
pFrame->linesize, 0, pCodecCtx->height,
pFrameRGB->data, pFrameRGB->linesize);
//==============================================================
AVFrame *pFrameYUV = avcodec_alloc_frame();
// Determine required buffer size and allocate buffer
int numBytes2 = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
pCodecCtx->height);
uint8_t *buffer = (uint8_t *)av_malloc(numBytes2*sizeof(uint8_t));
avpicture_fill((AVPicture *)pFrameYUV, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
rgb_to_yuv_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
PIX_FMT_RGB24,
pCodecCtx->width,pCodecCtx->height,
PIX_FMT_RGB24,
SWS_BICUBIC, NULL,NULL,NULL);
sws_scale(rgb_to_yuv_ctx, pFrameRGB->data, pFrameRGB->linesize, 0,
pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
sws_freeContext(rgb_to_yuv_ctx);
SaveFrame(pFrameYUV, pCodecCtx->width, pCodecCtx->height, i);
av_free(buffer);
av_free(pFrameYUV);
}
우선 잘
이 이미지는 광산과 비슷하지만 수동으로 rgb2yuv를하고 있습니다. 흑백 이미지는 김프에서 열 때 볼 수있는 것과 정확히 같지만 데이터가 정확하므로 카메라가 보내는 것과 동일합니다. 어쩌면 미리보기 문제일까요? 다른 방법으로 데이터를 테스트 할 수 있습니까? – tomasb