I want to use ffmpeg to convert image from RGB48 into YUV422, then generate
mp4 file finally.
But I found that conversion result shows the color of YUV422 image is not
same as RGB48. I also tried to convert image from RGB24 (just convert from
RGB48) into YUV422, no issue found.
Do anyone know is this the bug in ffmpeg for such conversion or some
mistake in my code?
Thanks so much in advance!!
The following code is from my project and used to conversion:
void conversion()
{
//xxxxxxxx;
rgb_pixel_format = AV_PIX_FMT_RGB48BE;
pCodecCtx->pix_fmt = yuv_pixel_format = AV_PIX_FMT_YUV422P;
scale_flag = SWS_POINT;
//xxxxxxxx;
size = avpicture_get_size(pCodecCtx->pix_fmt, pCodecCtx->width,
pCodecCtx->height);
yuv_buff = (unsigned char*)av_malloc(size);
pSwsCtx=
sws_getContext(pCodecCtx->width,pCodecCtx->height,rgb_pixel_format,
pCodecCtx->width,pCodecCtx->height,yuv_pixel_format,scale_flag,NULL,NULL,NULL);
for (file_index = 0; file_index < image_num; file_index ++)
{
rgb_buff = (unsigned char*)av_malloc(image_data->length);
memcpy(rgb_buff, image_data->data, image_data->length);
avpicture_fill((AVPicture*)pRGBFrame, (unsigned char*)rgb_buff,
rgb_pixel_format, nWidth, nHeight);
avpicture_fill((AVPicture*)pFrame, (unsigned char*)yuv_buff,
yuv_pixel_format, nWidth, nHeight);
//rotate RGB image
pRGBFrame->data[0] += pRGBFrame->linesize[0] * (nHeight - 1);
pRGBFrame->linesize[0] *= -1;
pRGBFrame->data[1] += pRGBFrame->linesize[1] * (nHeight / 2 - 1);
pRGBFrame->linesize[1] *= -1;
pRGBFrame->data[2] += pRGBFrame->linesize[2] * (nHeight / 2 - 1);
pRGBFrame->linesize[2] *= -1;
//covert RGB into YUV
sws_scale(pSwsCtx,pRGBFrame->data,pRGBFrame->linesize,0,pCodecCtx->height,pFrame->data,pFrame->linesize);
yuv_file = fopen(yuv_rst_file[file_index], "wb");
fseek(yuv_file, 0L, SEEK_END);
rewind(yuv_file);
fwrite(pFrame->data[0],(pCodecCtx->width)*(pCodecCtx->height),1,yuv_file);
fwrite(pFrame->data[1],(pCodecCtx->width)*(pCodecCtx->height)/2,1,yuv_file);
fwrite(pFrame->data[2],(pCodecCtx->width)*(pCodecCtx->height)/2,1,yuv_file);
fclose(yuv_file);
}
}
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user