level 1
LavenderSsBK
楼主
我打算利用ffmpeg的swscale接口将RGB48图像转换为YUV422(进而生成为MP4视频文件),但发现转换后的YUV422图像的颜色严重失真。另外,我尝试了将RGB24转换成YUV422或420就都没有问题。
下面是RGB48图像的样子:

下面是转换后的YUV422图像的样子:

请问有人知道这是咋回事吗?是ffmpeg的bug还是代码哪个地方设置的有问题?
附代码:
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); }}
2016年05月11日 06点05分
1
下面是RGB48图像的样子:

下面是转换后的YUV422图像的样子:
请问有人知道这是咋回事吗?是ffmpeg的bug还是代码哪个地方设置的有问题?附代码:
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); }}