Project1
标题:
C++求优化。。
[打印本页]
作者:
yangff
时间:
2011-11-5 17:49
标题:
C++求优化。。
本帖最后由 yangff 于 2011-11-5 17:49 编辑
int __declspec(dllexport) NextFrame(int Bitmap,int playerHandle)
{
int * pBitmap=(int *)Bitmap;
if (GetNextFrame(pFormatCtx, pCodecCtx, videoStream, pFrame))
{
//struct SwsContext * img_convert_ctx;
//img_convert_ctx=sws_getContext( pCodecCtx->width/12, pCodecCtx->height/12,PIX_FMT_RGB32,pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P,2,NULL,NULL,NULL);
uint8_t *data = malloc (3*pCodecCtx->width*pCodecCtx->height);
uint8_t *src[3]= {data, data+pCodecCtx->width*pCodecCtx->height, data+pCodecCtx->width*pCodecCtx->height+pCodecCtx->width*pCodecCtx->height};
//int stride[3]={pCodecCtx->width, pCodecCtx->width, pCodecCtx->width};
//sws_scale(img_convert_ctx,(const uint8_t* const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,src,stride);
int p=0;
int r,g,b=0;
double y,u,v;
int off=pCodecCtx->width*pCodecCtx->height;
int off1=pCodecCtx->width*pCodecCtx->height*1;
frame(pCodecCtx->height,pCodecCtx->width,data,pFrame);
//pBitmap[pCodecCtx->width*pCodecCtx->height-1]=0xffffaaff;
for (int i=pCodecCtx->height-1;i>=0;i--){
for (int j=0;j<pCodecCtx->width;j++)
{ //if (i*pCodecCtx->width+j<pCodecCtx->height*pCodecCtx->width)
pBitmap[p]=0xff000000 ;
y=(double)src[0][i*pCodecCtx->width+j];//pFrame->pp;//data[0][p+off];
u=(double)src[1][(i/2*pCodecCtx->width+j)/2];//pFrame->pp;//data[0][p+off1];
v=(double)src[2][(i/2*pCodecCtx->width+j)/2];//pFrame->pp//data[0][p+off1+off];
r=(int)(1.164f*(y-16)+1.596f*(v-128));
g=(int)(1.164f*(y-16)-0.813f*(v - 128) - 0.391f*(u - 128));
b=(int)(1.164f*(y-16)+2.018f*(u - 128));
if (r>255) r=255; if (r<0) r=0;
if (g>255) g=255; if (g<0) g=0;
if (b>255) b=255; if (b<0) b=0;
pBitmap[p]|= b; //b
pBitmap[p]|= g << 8; // g
pBitmap[p]|= r << 16; // r
// | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height) << 8)];// | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height*2) << 16)] | (0xff << 24);
p++;
}}
free(data);
return 1; }
return -1;
}
复制代码
作者:
dengtao49
时间:
2012-3-20 14:19
坑爹啊,C++发这里
作者:
414447674
时间:
2012-3-20 14:22
就是啊, 这里不是让你发C++的地方
作者:
熊的选民
时间:
2012-3-20 19:53
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段代码吗?
作者:
yangff
时间:
2012-3-20 20:21
熊的选民 发表于 2012-3-20 19:53
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段 ...
ffmpeg的解码代码。。具体可以看sample,主要是yuv到rgba32效率蛋疼啊
作者:
link006007
时间:
2012-3-21 12:52
本帖最后由 link006007 于 2012-3-21 12:53 编辑
不知道该解码数学原理的,优化基本天方夜谭。。。。。。。。。
如果只是从语言语法上来优化,推荐intel或者其他编译器厂商自带的优化工具,优化库和优化选项,编译器知道的比大部分“可能是高手”程序员知道的要多的多。。。
intel有一个ipp库,以前写一个g729解码,效率很淡疼,后来找了个ipp版本的,立马感觉就不一样了。。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1