国嵌h264应用程序出错
本人基于v4l2+天嵌的usb摄像头测试程序改了国嵌的H264项目,zc301摄像头,把jpeg流先解码再RGB24转YUV420,在T264编码,但是应用程序如下: 全是黑的,下面是编码:encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 377 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 12 bytes.
encoded:38016, 137 bytes.
encoded:38016, 74 bytes.
encoded:38016, 26 bytes.
encoded:38016, 37 bytes.
encoded:38016, 45 bytes.
encoded:38016, 19 bytes.
encoded:38016, 16 bytes.
encoded:38016, 32 bytes.
encoded:38016, 24 bytes.
encoded:38016, 12 bytes.
encoded:38016, 179 bytes. 摄像头不动,摄像头的监控区域没有异常,编码后的大小就一直是12bytes,收手在摄像头前面晃一下,就变了 这个是远程传输的吗?
你先在本地显示rgb的数据,看采集的数据是否能够正常显示,再做编码转换 while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, &buffer, 1);
printf("buffer is %d\n",strlen(buffer));
InitLookupTable();
ConvertRGB2YUV(w,h,buffer,cam_yuv);//将RGB彩色空间转换为YUV
//printf("output_scanline is %d\n",cinfo.output_scanline);
//printf("output_height is %d\n",cinfo.output_height);
//关闭Jpeg输入文件
//InitLookupTable();
// ConvertRGB2YUV(w,h,buffer,cam_yuv);//将RGB彩色空间转换为YUV
//printf("cam_yuv is %d\n",strlen(buffer));
//*cam_yuv=*p;
iActualLen = T264_encode(m_t264, cam_yuv, m_pDst, row_stride);//H.264编码
printf("encoded:%d, %d bytes.\n",row_stride,iActualLen);
memcpy(m_pPoolData,&m_t264->frame_num,1);
memcpy(m_pPoolData+1, m_pDst, iActualLen);
iActualLen++;
sendto(sockfd,m_pPoolData,iActualLen,0,(struct sockaddr*)&addrdst,sizeof(struct sockaddr_in));
}
上面是相关的代码,RGB转换到YUV并压缩,socket发送
RGB2YUV如下:
void InitLookupTable()
{
int i;
for (i = 0; i < 256; i++) RGB2YUV_YR = (float)65.481 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_YG = (float)128.553 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_YB = (float)24.966 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UR = (float)37.797 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UG = (float)74.203 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_VG = (float)93.786 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_VB = (float)18.214 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UBVR = (float)112 * (i<<8);
}
int ConvertRGB2YUV(int w,int h,unsigned char *bmp,unsigned char *yuv)
{
unsigned char *u,*v,*y;
unsigned char *pu1,*pu2,*pu3,*pu4;
unsigned char *pv1,*pv2,*pv3,*pv4;
unsigned char *r,*g,*b;
int i,j;
if(convert_uu==NULL || convert_vv==NULL)
return 0;
y=yuv;
// u=convert_uu;
// v=convert_vv;
v=convert_uu;
u=convert_vv;
// Get r,g,b pointers from bmp image data....
r=bmp;
g=bmp+1;
b=bmp+2;
//Get YUV values for rgb values...
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
*y++=( RGB2YUV_YR[*r]+RGB2YUV_YG[*g]+RGB2YUV_YB[*b]+1048576)>>16;
*u++=(-RGB2YUV_UR[*r]-RGB2YUV_UG[*g]+RGB2YUV_UBVR[*b]+8388608)>>16;
*v++=( RGB2YUV_UBVR[*r]-RGB2YUV_VG[*g]-RGB2YUV_VB[*b]+8388608)>>16;
r+=3;
g+=3;
b+=3;
}
}
// Now sample the U & V to obtain YUV 4:2:0 format
// Sampling mechanism...
/* @->Y
#->U or V
@ @ @ @
# #
@ @ @ @
@ @ @ @
# #
@ @ @ @
*/
// Get the right pointers...
u=yuv+w*h;
v=u+(w*h)/4;
// For U
pu1=convert_uu;
pu2=pu1+1;
pu3=pu1+w;
pu4=pu3+1;
// For V
pv1=convert_vv;
pv2=pv1+1;
pv3=pv1+w;
pv4=pv3+1;
// Do sampling....
for(i=0;i<h;i+=2)
{
for(j=0;j<w;j+=2)
{
*u++=(*pu1+*pu2+*pu3+*pu4)>>2;
*v++=(*pv1+*pv2+*pv3+*pv4)>>2;
pu1+=2;
pu2+=2;
pu3+=2;
pu4+=2;
pv1+=2;
pv2+=2;
pv3+=2;
pv4+=2;
}
pu1+=w;
pu2+=w;
pu3+=w;
pu4+=w;
pv1+=w;
pv2+=w;
pv3+=w;
pv4+=w;
}
return 1;
}
求高手指导,马上回家了,希望在年前解决,不然过年都没心思 楼主解决了吗?我也用的ZC301,也得转码,求指导 没解决,,不搞了
页:
[1]