Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
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 !
Posted
Comments
Ajesh Kumar.T.T 19-Nov-13 8:10am    
I am not familiar with this library. But I found similar issue while creating mp4 video files from raw image data. I used Media Foundation APIs for this purpose. In that case encoding gets failed while given RGB24 format. I solved it by converting RGB24 to RGB32 by using the manual looping.
Is this conversion is needed for image data or it for video?

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900