简体   繁体   English

libx264 x264_nal_encode溢出

[英]libx264 x264_nal_encode overflowing

My libH264 app is performing encoding of incomming camera data, but it keeps accumulating data and slows down the more encode operations it performs. 我的libH264应用程序正在对传入的相机数据执行编码,但它会不断累积数据并减慢其执行的更多编码操作的速度。 Any idea's why is this happening? 知道为什么会这样吗?

Variables are allocated at the start of a program. 变量在程序开始时分配。 Is my sequence incorrect? 我的顺序不正确吗? I suspect I have to reinitilize some structure, but I cant find out how to do it... 我怀疑我必须重新初始化某些结构,但是我找不到解决方法...

Here is part of my code in camera thread: 这是我在相机线程中的代码的一部分:

    int nWidth = 640;
    int nHeight = 480;    

fill YUV data 填写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); 

fill PTS 填写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 );  
     }  
    }  

Pack data to RTMP 将数据打包到RTMP

    unsigned int nSize=pNal-szNalBuffer;  
    packet.m_nBodySize=nSize+9;  
    if (i264Nal>1) {  
     szBodyBuffer[ 0]=0x17;  
    }  
    else {  
     szBodyBuffer[ 0]=0x27;  
    }  
    put_be32((char *)szBodyBuffer+5,nSize);  
    memcpy(szBodyBuffer+9,szNalBuffer,pNal-szNalBuffer);  

    printf( "rtmp send packet\n" );

    RTMP_SendPacket(rtmp,&packet,0);  
    newTick=high_resolution_timer_tick_count();  
    packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;  
    packet.m_nTimeStamp+=newTick-oldTick;  
    oldTick=newTick;  

Here is the output of my app: 这是我的应用程序的输出:

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_encoder_encode(...) returns the frame size, you don't seem to be taking this into consideration . x264_encoder_encode(...)返回帧大小,您似乎没有考虑到这一点。 Your using i_payload but depending on the NAL type, this will not be the correct value. 您使用的是i_payload,但取决于NAL类型,这将不是正确的值。

x264_nal_encode looks like it was removed and x264_encoder_encode now returns the frame encoded into nal units. x264_nal_encode看起来已被删除,并且x264_encoder_encode现在返回编码为nal单位的帧。 int frame_size is returned. 返回int frame_size

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM