天嵌 ARM开发社区

 找回密码
 注册
查看: 3069|回复: 6

国嵌h264应用程序出错

[复制链接]
安仔 发表于 2011-12-28 20:25:48 | 显示全部楼层 |阅读模式
本人基于v4l2+天嵌的usb摄像头测试程序改了国嵌的H264项目,zc301摄像头,把jpeg流先解码再RGB24转YUV420,在T264编码,但是应用程序如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 安仔 发表于 2011-12-28 20:26:41 | 显示全部楼层
全是黑的,下面是编码:
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.
 楼主| 安仔 发表于 2011-12-28 20:28:12 | 显示全部楼层
摄像头不动,摄像头的监控区域没有异常,编码后的大小就一直是12bytes,收手在摄像头前面晃一下,就变了
TQ-lkp 发表于 2011-12-29 08:57:59 | 显示全部楼层
这个是远程传输的吗?
你先在本地显示rgb的数据,看采集的数据是否能够正常显示,再做编码转换
 楼主| 安仔 发表于 2011-12-29 14:11:51 | 显示全部楼层
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[i] = (float)65.481 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_YG[i] = (float)128.553 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_YB[i] = (float)24.966 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_UR[i] = (float)37.797 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_UG[i] = (float)74.203 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_VG[i] = (float)93.786 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_VB[i] = (float)18.214 * (i<<8);
        for (i = 0; i < 256; i++) RGB2YUV_UBVR[i] = (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;
}
求高手指导,马上回家了,希望在年前解决,不然过年都没心思
-_-!_井 发表于 2013-1-15 19:24:19 | 显示全部楼层
楼主解决了吗?我也用的ZC301,也得转码,求指导
 楼主| 安仔 发表于 2013-1-16 14:17:32 | 显示全部楼层
没解决,,不搞了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-2 07:48 , Processed in 1.046875 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表