颜色格式转换 [英] the color format convert

查看:103
本文介绍了颜色格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 nRet = av_image_alloc(pSrcBuff,nLines,nSrcWidth,nSrcHeight,AV_PIX_FMT_YUV420P, 16 ); 

nDstBuffLen = av_image_alloc(pDstBuff,nDstLines,nSrcWidth,nSrcHeight,AV_PIX_FMT_RGB24, 1 );
if (nDstBuffLen< = 0
{
return -1;
}

SwsContext * sws_ctx;
sws_ctx = sws_getContext(nSrcWidth,nSrcHeight,AV_PIX_FMT_YUV420P,
nSrcWidth,nSrcHeight,AV_PIX_FMT_RGB24,
SWS_BILINEAR,NULL,NULL,NULL);

HGFile srcFile,dstFile;
bFlag = srcFile.OpenFile( yuv800600.yuv,FALSE,& dError) ;
srcFile.ReadFile(pBuffer,nSrcHeight * nSrcWidth * 3/2,dRead,NULL);
if (dRead!=(nSrcWidth * nSrcHeight * 3/2))
{
返回 -1;
}

av_image_fill_arrays(pSrcBuff,nLines,pBuffer,AV_PIX_FMT_YUV420P,nSrcWidth,nSrcHeight, 16 );
int nTemp = sws_scale(sws_ctx,( const uint8_t * const *)pSrcBuff,
nLines, 0 ,nSrcHeight,pDstBuff,nDstLines);

BYTE * pTemp = NULL;

dstFile.OpenFile( yrgb0.rgb,TRUE,NULL) ;
dstFile.WriteFile(pDstBuff [ 0 ],nDstBuffLen,dRead,NULL);





i希望将颜色格式从yuv420p转换为rgb24

我用的是ffmpeg swscal.lib

结果有问题

图片显示蓝色

结果是对的



有人可以给我一些建议吗?

非常感谢你!

解决方案

您好b $ b尝试:


ffmpeg -s 352x288 -i foreman_cif_frame_0.yuv f.png

ffmpeg版本N-46810-g7750c48版权所有(c)2000-2012 FFmpeg开发人员

建于2013年4月21日11:12:24,gcc 4.6(Ubuntu / Linaro 4.6。 3-1ubuntu5)

配置: - enable-gpl --enable-libx264 --enable-libmp3lame

libavutil 52. 7.100 / 52. 7.100

libavcodec 54. 71.100 / 54. 71.100

libavformat 54. 36.100 / 54. 36.100

libavdevice 54. 3 .100 / 54. 3.100

libavfilter 3. 23.100 / 3. 23.100

libswscale 2. 1.102 / 2. 1.102

libswresample 0. 16.100 / 0. 16.100

libpostproc 52. 1.100 / 52. 1.100

[rawvideo @ 0x18a1320]从比特率估算持续时间,这可能不准确

输入#0,rawvideo,来自'foreman_cif_frame_0.yuv':

持续时间:N / A,开始:0.000000,比特率:N / A

流#0:0:视频:rawvideo(I420 / 0x30323449),yuv420p,352x288,25 tbr,25 tbn,25 tbc

输出#0,image2,到'f.png':

元数据:

编码器:Lavf54.36.100

流#0:0:视频:png,rgb24,352x288,q = 2-31,200 kb / s,90k tbn ,25 tbc

流映射:

流#0:0 - > #0:0(rawvideo - > png)

按[q]停止,[?]寻求帮助

frame = 1 fps = 0.0 q = 0.0 Lsize = 0kB时间= 00:00:00.04比特率= 0.0kbits / s

视频:201kB音频:0kB字幕:0全局标题:0kB多路复用开销-100.000000

Yours Farhad。

nRet = av_image_alloc(pSrcBuff,nLines,nSrcWidth,nSrcHeight,AV_PIX_FMT_YUV420P,16) ;

 nDstBuffLen = av_image_alloc(pDstBuff,nDstLines,nSrcWidth,nSrcHeight,AV_PIX_FMT_RGB24,1) ;
 if (nDstBuffLen<=0)
 {
     return -1 ;
 }

 SwsContext *sws_ctx;
 sws_ctx = sws_getContext(nSrcWidth, nSrcHeight, AV_PIX_FMT_YUV420P,
     nSrcWidth, nSrcHeight, AV_PIX_FMT_RGB24,
     SWS_BILINEAR, NULL, NULL, NULL);

 HGFile srcFile,dstFile;
 bFlag = srcFile.OpenFile("yuv800600.yuv",FALSE,&dError) ;
 srcFile.ReadFile(pBuffer,nSrcHeight*nSrcWidth*3/2,dRead,NULL) ;
 if (dRead!=(nSrcWidth*nSrcHeight*3/2))
 {
     return -1 ;
 }

  av_image_fill_arrays(pSrcBuff,nLines,pBuffer,AV_PIX_FMT_YUV420P,nSrcWidth,nSrcHeight,16) ;
 int nTemp = sws_scale(sws_ctx, (const uint8_t * const*)pSrcBuff,
     nLines, 0, nSrcHeight, pDstBuff,nDstLines);

 BYTE *pTemp = NULL ;

 dstFile.OpenFile("yrgb0.rgb",TRUE,NULL) ;
 dstFile.WriteFile(pDstBuff[0],nDstBuffLen,dRead,NULL) ;



i want to convert the color format frome yuv420p to rgb24
and i used the ffmpeg swscal.lib
something was wrong with the result
the picture shows blue
but if i set the dst format as rgb32
the result is right

is anybody who can give me some advice?
thank you very much !

解决方案

Hi Try it:


ffmpeg -s 352x288 -i foreman_cif_frame_0.yuv f.png
ffmpeg version N-46810-g7750c48 Copyright (c) 2000-2012 the FFmpeg developers
built on Apr 21 2013 11:12:24 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-gpl --enable-libx264 --enable-libmp3lame
libavutil 52. 7.100 / 52. 7.100
libavcodec 54. 71.100 / 54. 71.100
libavformat 54. 36.100 / 54. 36.100
libavdevice 54. 3.100 / 54. 3.100
libavfilter 3. 23.100 / 3. 23.100
libswscale 2. 1.102 / 2. 1.102
libswresample 0. 16.100 / 0. 16.100
libpostproc 52. 1.100 / 52. 1.100
[rawvideo @ 0x18a1320] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from 'foreman_cif_frame_0.yuv':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 352x288, 25 tbr, 25 tbn, 25 tbc
Output #0, image2, to 'f.png':
Metadata:
encoder : Lavf54.36.100
Stream #0:0: Video: png, rgb24, 352x288, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> png)
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=0.0 Lsize= 0kB time=00:00:00.04 bitrate= 0.0kbits/s
video:201kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000000
Yours Farhad.


这篇关于颜色格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆