There's not a better type, it depends on the whole system. <div><br></div><div>For instance, that's a part of a video capture utility. I recieve the "ptBuffer", or the source image, in YUV422 (which is a very common pixel format in capture cards and video cameras). I do the rescale as well as the pixel format conversion (using pixel shaders) in the GPU, this was a quick test I made...<div>
<br></div><div>You have to identify your pixel format and your data structure and convert it to the desired one.</div><div><br></div><div>A part from the pixel format (RGB, BGR, RGBA, ...) you need to know whether it's planar (RRR....GGGG....BBBB) or linear (RGBRGBRGB....). The pixel format descriptors also include this information (represented as a "P" at the end), you should check the documentation.</div>
<div><br></div><div>In your case:</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">AV_PIX_FMT_RGB24 ---> RGBRGBRGB...</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">AV_PIX_FMT_YUV420P ----> YYYYYY.....UUUUUUUU........VVVVVVVVV.......</span></div>
<div><font color="#222222" face="arial, sans-serif">If you use my function to make the conversion it allocates the structure for you. Check the linesizes of the resulting picture for a better understanding of what's going on.</font></div>
<div><br></div><div><br><div class="gmail_quote">On Fri, Feb 15, 2013 at 12:16 AM, Chris Share <span dir="ltr"><<a href="mailto:cpsmusic@yahoo.com" target="_blank">cpsmusic@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for the sample code.<br>
<br>
I have a couple of further questions:<br>
<br>
1. If the input data is in a vector of unsigned chars (RGBRGB...), what is the best pixel format to use?<br>
<br>
2. The input data is represented by the following method parameter: void* ptInData - I'm not clear as to how the vector is converted to an appropriate type - should it be an array of chars (RGBRGB...) or does the data need to be arranged differently (RRR...GGG...BBB...)?<br>

<br>
Cheers,<br>
<br>
Chris<br>
<br>
________________________________<br>
From: Hector Alonso <<a href="mailto:halonso@vpod.tv">halonso@vpod.tv</a>><br>
To: "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <<a href="mailto:libav-user@ffmpeg.org">libav-user@ffmpeg.org</a>><br>
Sent: Thursday, 14 February 2013 8:38 PM<br>
Subject: Re: [Libav-user] How to Convert AV_PIX_FMT_RGB24 to AV_PIX_FMT_YUV420P<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Hi Chris,<br>
<br>
You can implement some kind of function like:<br>
<br>
// dependencies into C++ <br>
extern"C"{<br>
#include<libavformat/avformat.h><br>
#include<libswscale/swscale.h><br>
#include<libavutil/pixdesc.h><br>
#include<libavutil/samplefmt.h><br>
#include<libavutil/intreadwrite.h><br>
}<br>
<br>
/**<br>
*Thisfunctionconvertsanimage(uncompressedbuffer)fromaninput<br>
*specifiedpixelformattoanoutputspecifiedpixelformatandbuffer.<br>
*dependenciesLibAV.<br>
*@param[in]eInFormatinputimagePixelformat@seeLibaAVPixelFormatenumtype.<br>
*@param[in]iInWidthinputimagewidth<br>
*@param[in]iInHeightinputimageheight<br>
*@param[in]ptInDatainputimagebuffer<br>
*@param[in]eOutFormatoutputimagePixelformat@seeLibaAVPixelFormatenumtype.<br>
*@param[in]iOutWidthoutputimagewidth<br>
*@param[in]iOutHeightoutputimageheight<br>
*@param[out]srcoutputimagebuffer<br>
*@returntrueifeverythingwascorrect,falseotherwise)<br>
**/<br>
boolConvertImage1(PixelFormateInFormat,intiInWidth,intiInHeight,void*ptInData,PixelFormateOutFormat,intiOutWidth,intiOutHeight,AVPicture*src)<br>
{<br>
SwsContext*ptImgConvertCtx;// Frame conversion context<br>
<br>
AVPictureptPictureIn;<br>
uint8_t*ptBufferIn;<br>
<br>
//Initialize convert context<br>
//------------------<br>
ptImgConvertCtx=sws_getContext(iInWidth,iInHeight,eInFormat,// (source format)<br>
iOutWidth,iOutHeight,eOutFormat,// (dest format)<br>
SWS_BICUBIC,NULL,NULL,NULL);<br>
<br>
// Init input frame:<br>
//------------------<br>
// Allocate an AVFrame structure<br>
<br>
<br>
// Determine required buffer size and allocate buffer<br>
// int iNumBytesIn=avpicture_get_size(eInFormat, iInWidth,iInHeight);<br>
<br>
ptBufferIn=(uint8_t*)(ptInData);<br>
<br>
// Assign appropriate parts of buffer to image planes in pFrameOut<br>
avpicture_fill(&ptPictureIn,ptBufferIn,eInFormat,iInWidth,iInHeight);<br>
<br>
// Do conversion:<br>
//------------------<br>
intiRes=sws_scale(ptImgConvertCtx,<br>
ptPictureIn.data,//src<br>
ptPictureIn.linesize,<br>
0,<br>
iInHeight,<br>
src->data,//dst<br>
src->linesize);<br>
<br>
<br>
//Free memory<br>
sws_freeContext(ptImgConvertCtx);<br>
<br>
//Check result:<br>
if(iRes==iOutHeight)<br>
returntrue;<br>
<br>
returnfalse;<br>
}<br>
<br>
And use it like this (in this example is used to downscale, but you can use it for rescaling and or pixel format conversions)<br>
<br>
// Downscale<br>
AVPicturesrc;<br>
intiWidth=m_ptCurrentVideoMode->getWidth()/DL_LOW_DEFINITION_DEN;<br>
intiHeight=(m_ptCurrentVideoMode->getHeight()*iWidth)/m_ptCurrentVideoMode->getWidth();<br>
iWidth=(floor(iWidth/2))*2;<br>
iHeight=(floor(iHeight/2))*2;<br>
<br>
avpicture_alloc(&src,AV_PIX_FMT_UYVY422,iWidth,iHeight);<br>
<br>
if(!ConvertImage1(AV_PIX_FMT_UYVY422,<br>
m_ptCurrentVideoMode->getWidth(),<br>
m_ptCurrentVideoMode->getHeight(),<br>
(void*)ptBuffer,<br>
AV_PIX_FMT_UYVY422,<br>
iWidth,iHeight,<br>
&src))<br>
{<br>
avpicture_free(&src);<br>
return;<br>
}<br>
<br>
// ... whatever ...<br>
<br>
// Free aux frame<br>
avpicture_free(&src);<br>
I hope it helps!<br>
<br>
<br>
On Thu, Feb 14, 2013 at 10:00 AM, Chris Share <<a href="mailto:cpsmusic@yahoo.com">cpsmusic@yahoo.com</a>> wrote:<br>
<br>
Hi,<br>
><br>
>I'm currently trying to implement file export for the open source animation program Pencil2D. This involves converting RGB (0 - 255) image data to a suitable movie format.<br>
><br>
>The examples in the source tree have been very helpful however I still have some questions:<br>
><br>
>The scaling_video.c is close to what I need however the conversion is the opposite of what I want. What I'm not clear about is how to change the "fill_yuv_image" function to something like "fill_rgb_image". How does the RGB data get written into the "uint8_t *data[4]"? Is it written consecutively (all R values get written to data[0], all G values to data[1], etc.)?<br>

><br>
>Cheers,<br>
><br>
>Chris<br>
>_______________________________________________<br>
>Libav-user mailing list<br>
><a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
><a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
><br>
<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</div></div></blockquote></div><br></div></div>