C libx264 x264_nal_编码溢出

C libx264 x264_nal_编码溢出,c,h.264,libx264,C,H.264,Libx264,我的libH264应用程序正在对输入的相机数据进行编码,但它会不断累积数据,并降低它执行的更多编码操作的速度。知道为什么会这样吗 变量在程序开始时分配。我的顺序不对吗?我想我必须重新初始化一些结构,但我不知道怎么做 以下是我在照相机线程中的部分代码: int nWidth = 640; int nHeight = 480; 填写YUV数据 memcpy(p264Pic->img.plane[0],pic.buffer,nWidth*nHeight);

我的libH264应用程序正在对输入的相机数据进行编码,但它会不断累积数据,并降低它执行的更多编码操作的速度。知道为什么会这样吗

变量在程序开始时分配。我的顺序不对吗?我想我必须重新初始化一些结构,但我不知道怎么做

以下是我在照相机线程中的部分代码:

    int nWidth = 640;
    int nHeight = 480;    
填写YUV数据

    memcpy(p264Pic->img.plane[0],pic.buffer,nWidth*nHeight);  
    memcpy(p264Pic->img.plane[1],pic.buffer+nWidth*nHeight,nWidth*nHeight/4);  
    memcpy(p264Pic->img.plane[2],pic.buffer+nWidth*nHeight*5/4,nWidth*nHeight/4); 
填充PTS

    p264Pic->i_pts = high_resolution_timer_tick_count();

//          if( nFramsInPack % 8 == 0){
//           p264Pic->i_type = X264_TYPE_I;
//          }else{
             p264Pic->i_type = X264_TYPE_AUTO;
//      }

    if( x264_encoder_encode( p264Handle, &p264Nal, &i264Nal, p264Pic ,&pic_out) < 0 ) {  
                fprintf( stderr, "x264_encoder_encode failed/n" );  
    }  
    printf("i264Nal %d\n", i264Nal );

    for( int i = 0; i < i264Nal; i++ )  
    {
     printf( "nal pass %d\n", i );
     int i_data = 1024*32;  

     printf( "nal encode\n" );

     x264_nal_encode( p264Handle, pNal, &p264Nal[i] );

     printf( "after nal encode\n" );

     int i_size = p264Nal[i].i_payload;     

     printf("i_size %d\n", i_size );

     if( i_size > 0 ) {  

       if ((pNal[4]&0x60)==0) {  
           continue;  
       }  
       if (pNal[4]==0x67) {  
           continue;  
       }  
       if (pNal[4]==0x68) {  
           continue;  
       }  
       memmove(pNal,pNal+4,i_size-4);  
       pNal+=i_size-4;  
     }  
     else if( i_size < 0 ) {  
       fprintf( stderr,"need to increase buffer size (size=%d)/n", -i_size );  
     }  
    }  
以下是我的应用程序的输出:

i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 4
nal pass 0
nal encode
after nal encode
i_size 36
nal pass 1
nal encode
after nal encode
i_size 15
nal pass 2
nal encode
after nal encode
i_size 632
nal pass 3
nal encode
after nal encode
i_size 7151
rtmp send packet
i264Nal 1
nal pass 0
nal encode
after nal encode
i_size 8136
rtmp send packet
i264Nal 1
nal pass 0
nal encode
after nal encode
i_size 28955
rtmp send packet
^CThe pthread schedule_do end
^Cthread is end
i264Nal 1
nal pass 0
nal encode
after nal encode
x264\u encoder\u encode(…)
返回帧大小,您似乎没有考虑到这一点。您正在使用i_有效负载,但取决于NAL类型,这将不是正确的值


x264\u nal\u encode
看起来它已被删除,
x264\u encode\u encode
现在返回编码为nal单位的帧<返回code>int frame\u size。

您的CPU使用情况如何?你跟上需求了吗?@jeremy不,它的速度很快就慢下来了-在queuex264\u nal\u编码上建立的东西返回void,这就是我使用有效负载的原因-API中发生了一些变化,所有的示例现在都乱七八糟了…抱歉,我拉了代码,正在查看,以为我抓住了最新的,看起来像是2005年:(另外,一个帧可能是1个或多个nal单元,这可能是您的问题的一部分。i_有效负载几乎肯定不是您想要的nal大小。我将仔细研究一下。x264_encoder_encode的参数相同,但它以nal单元返回位流。多个nal单元不应该是一个问题,您必须隐藏一点不同。)ent方法通过ffmpeg来包装rtmp数据,稍后将返回此问题…,感谢您的帮助
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 0
rtmp send packet
i264Nal 4
nal pass 0
nal encode
after nal encode
i_size 36
nal pass 1
nal encode
after nal encode
i_size 15
nal pass 2
nal encode
after nal encode
i_size 632
nal pass 3
nal encode
after nal encode
i_size 7151
rtmp send packet
i264Nal 1
nal pass 0
nal encode
after nal encode
i_size 8136
rtmp send packet
i264Nal 1
nal pass 0
nal encode
after nal encode
i_size 28955
rtmp send packet
^CThe pthread schedule_do end
^Cthread is end
i264Nal 1
nal pass 0
nal encode
after nal encode