开发者

Problem with publishing rtmp stream to FMS with librtmp

开发者 https://www.devze.com 2023-03-22 09:49 出处:网络
I\'m trying to get video from the webcam and get it encoded and then publish the stream to FMS. and now I\'am having a problem when I try to publish RTMP stream to the FMS with librtmp.

I'm trying to get video from the webcam and get it encoded and then publish the stream to FMS. and now I'am having a problem when I try to publish RTMP stream to the FMS with librtmp.

My code:

char uri[]="rtmp://127.0.0.1/live/bolton";
r= RTMP_Alloc();
RTMP_Init(r);   
RTMP_SetupURL(r, (char*)uri);
r->Link.lFlags |= RTMP_LF_LIVE;
r->Link.lFlags |= RTMP_LF_BUFX;
RTMP_EnableWrite(r);
//RTMP_SetBufferMS(r, bufferTime);
RTMP_Connect(r, NULL);
RTMP_ConnectStream(r,0);

And log:

DEBUG: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG: HandShake: Handshaking finished....
DEBUG: RTMP_Connect1, handshaked
DEBUG2: RTMP_SendPacket: fd=768, size=85
DEBUG2:   0000:  03 00 00 00 00 00 开发者_开发技巧55 14  00 00 00 00               ......U.....      
DEBUG2:   0000:  02 00 07 63 6f 6e 6e 65  63 74 00 3f f0 00 00 00   ...connect.?....  
DEBUG2:   0010:  00 00 00 03 00 03 61 70  70 02 00 04 6c 69 76 65   ......app...live  
DEBUG2:   0020:  00 04 74 79 70 65 02 00  0a 6e 6f 6e 70 72 69 76   ..type...nonpriv  
DEBUG2:   0030:  61 74 65 00 05 74 63 55  72 6c 02 00 15 72 74 6d   ate..tcUrl...rtm  
DEBUG2:   0040:  70 3a 2f 2f 31 32 37 2e  30 2e 30 2e 31 2f 6c 69   p://127.0.0.1/li  
DEBUG2:   0050:  76 65 00 00 09                                     ve...             
DEBUG: Invoking connect
DEBUG2: RTMP_ReadPacket: fd=768
ERROR: RTMP_ReadPacket, failed to read RTMP packet header
DEBUG2: RTMP_SendPacket: fd=-1, size=307

It seems that RTMP_connect connected correctly, but failes in the function RTMP_ConnectStream, I'm not familiar with the rtmp connect sequence, and it's killing me.

What should I do to find the problems, Thanks very much!


I'm dealing with the same problem, but using librtmp with ffmpeg. If you look in the function RTMP_ReadPacket(), you'll see the error is thrown when trying to read the packet header with the method ReadN():

int
RTMP_ReadPacket(RTMP *r, RTMPPacket *packet)
{
    uint8_t hbuf[RTMP_MAX_HEADER_SIZE] = { 0 };
    char *header = (char *)hbuf;
    int nSize, hSize, nToRead, nChunk;
    int didAlloc = FALSE;

    RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d", __FUNCTION__, r->m_sb.sb_socket);

    if (ReadN(r, (char *)hbuf, 1) == 0)
    {
        RTMP_Log(RTMP_LOGERROR, "%s, failed to read RTMP packet header", __FUNCTION__);
        return FALSE;
    }

That error only throws if the ReadN returns a 0. I haven't figured out on my end why that's happening yet, though.


I got the same issue in the Visual studio. It turned out that in the debug mode,librtmp set some handshake value 0 instead of generating random data.

//handshake.h
  /* generate random data */
#ifdef _DEBUG
  memset(serversig+8, 0, RTMP_SIG_SIZE-8);
#else
  ip = (int32_t *)(serversig+8);
  for (i = 2; i < RTMP_SIG_SIZE/4; i++)
    *ip++ = rand();
#endif

Just make sure generating random data.

0

精彩评论

暂无评论...
验证码 换一张
取 消