Wowza Community

Using librtmp library to publish a live stream to Wowza Media Server

Hi,

How to publish a stream using librtmp library?

I read the librtmp man page and for publishing , RTMP_Write() is used.

I am using C/C++ for my application.

//Code

//Init RTMP code

RTMP *r;

char uri[]=“rtmp://localhost:1935/live/desktop”;

r= RTMP_Alloc();

RTMP_Init®;

RTMP_SetupURL(r, (char*)uri);

RTMP_EnableWrite®; // To publish a stream, enable write support before connect

RTMP_Connect(r, NULL);

RTMP_ConnectStream(r,0);

Then to respond to ping/other messages from server, I am using a thread to respond like following:

//Thread

While (ThreadIsRunning && RTMP_IsConnected® && RTMP_ReadPacket(r, &packet))

{

if (RTMPPacket_IsReady(&packet))

{

if (!packet.m_nBodySize)

continue;

RTMP_ClientPacket(r, &packet); //This takes care of handling ping/other messages

RTMPPacket_Free(&packet);

}

}

After this I am stuck at how to use RTMP_Write() to publish a file to Wowza media server.

I searched in google and most applications are in Java or Python or C# which I don’t understand.

Please help me.

Thanks,

Dhruva

Have you tried opening up a FLV file and feeding it into this function? I see this in the function

if (buf[0] == ‘F’ && buf[1] == ‘L’ && buf[2] == ‘V’)

If you get really stuck I suggest you configure/compile FFmpeg with --enable-librtmp and see how it is using the library. It may also help to read the RTMP specification from Adobe.

For testing against FFmpeg: If you set av_log_set_level(AV_LOG_DEBUG) in ffmpeg.c and also enable RTMP_LOGALL in librtmp for your application then the debug outputs should look at least similar. At the very least it should help you narrow down what to do, and what you may be doing wrong.

Hi,

Did you get an answer or solve this issue?

I’m facing the same issue - stuck in he phase of writing RTMP packets using librtmp.

Can you/someone else assist?

Thanks,

Hey, guys,

Any update on this? I’d be interested in streaming to Wowza with librtmp also.

Thanks,

Sorin.

I don’t work directly with RTMP. About as far as I have gone is to patch it and fix a few bugs. Here is a dump from the library. You may get a better response to your message on the rtmpdump/librtmp dev list. Ignore the ‘test.sdp’. I am not sending a sdp. This is just left over from RTSP testing, and I am lazy.

Login dump

DEBUG: Parsing...
DEBUG: Parsed protocol: 0
DEBUG: Parsed host    : 192.168.1.50
DEBUG: Parsed app     : rtplive
DEBUG: RTMP_Connect1, ... connected, handshaking
DEBUG: HandShake: Type Answer   : 03
DEBUG: HandShake: Server Uptime : 96850052
DEBUG: HandShake: FMS Version   : 3.0.1.1
DEBUG: HandShake: Handshaking finished....
DEBUG: RTMP_Connect1, handshaked
DEBUG2: RTMP_SendPacket: fd=7, size=143
DEBUG2:   0000:  03 00 00 00 00 00 8f 14  00 00 00 00               ............      
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 07 72 74 70 6c   ......app...rtpl  
DEBUG2:   0020:  69 76 65 00 04 74 79 70  65 02 00 0a 6e 6f 6e 70   ive..type...nonp  
DEBUG2:   0030:  72 69 76 61 74 65 00 08  66 6c 61 73 68 56 65 72   rivate..flashVer  
DEBUG2:   0040:  02 00 1f 46 4d 4c 45 2f  33 2e 30 10 28 63 6f 6d   ...FMLE/3.0.(com  
DEBUG2:   0050:  70 61 74 69 62 6c 65 3b  10 46 4d 53 63 2f 31 2e   patible;.FMSc/1.  
DEBUG2:   0060:  30 29 00 05 74 63 55 72  6c 02 00 20 72 74 6d 70   0)..tcUrl.. rtmp  
DEBUG2:   0070:  3a 2f 2f 31 39 32 2e 31  36 38 2e 31 2e 35 30 3a   ://192.168.1.50:  
DEBUG2:   0000:  c3                                                 .                 
DEBUG2:   0000:  31 39 33 35 2f 72 74 70  6c 69 76 65 00 00 09      1935/rtplive...   
DEBUG: Invoking connect
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  02 00 00 00 00 00 04 05  00 00 00 00               ............      
DEBUG2:   0000:  00 26 25 a0                                        .&%.              
DEBUG: HandleServerBW: server BW = 2500000
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  02 00 00 00 00 00 05 06  00 00 00 00               ............      
DEBUG2:   0000:  00 26 25 a0 02                                     .&%..             
DEBUG: HandleClientBW: client BW = 2500000 2
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  02 00 00 00 00 00 06 04  00 00 00 00               ............      
DEBUG2:   0000:  00 00 00 00 00 00                                  ......            
DEBUG: HandleCtrl, received ctrl. type: 0, len: 6
DEBUG: HandleCtrl, Stream Begin 0
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  02 00 00 00 00 00 04 01  00 00 00 00               ............      
DEBUG2:   0000:  00 00 02 00                                        ....              
DEBUG: HandleChangeChunkSize, received: chunk size change to 512
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  03 00 00 00 00 01 03 14  00 00 00 00               ............      
DEBUG2:   0000:  02 00 07 5f 72 65 73 75  6c 74 00 3f f0 00 00 00   ..._result.?....  
DEBUG2:   0010:  00 00 00 03 00 06 66 6d  73 56 65 72 02 00 0d 46   ......fmsVer...F  
DEBUG2:   0020:  4d 53 2f 33 2c 35 2c 32  2c 36 35 34 00 0c 63 61   MS/3,5,2,654..ca  
DEBUG2:   0030:  70 61 62 69 6c 69 74 69  65 73 00 40 3f 00 00 00   pabilities.@?...  
DEBUG2:   0040:  00 00 00 00 04 6d 6f 64  65 00 3f f0 00 00 00 00   .....mode.?.....  
DEBUG2:   0050:  00 00 00 00 09 03 00 05  6c 65 76 65 6c 02 00 06   ........level...  
DEBUG2:   0060:  73 74 61 74 75 73 00 04  63 6f 64 65 02 00 1d 4e   status..code...N  
DEBUG2:   0070:  65 74 43 6f 6e 6e 65 63  74 69 6f 6e 2e 43 6f 6e   etConnection.Con  
DEBUG2:   0080:  6e 65 63 74 2e 53 75 63  63 65 73 73 00 0b 64 65   nect.Success..de  
DEBUG2:   0090:  73 63 72 69 70 74 69 6f  6e 02 00 15 43 6f 6e 6e   scription...Conn  
DEBUG2:   00a0:  65 63 74 69 6f 6e 20 73  75 63 63 65 65 64 65 64   ection succeeded  
DEBUG2:   00b0:  2e 00 04 64 61 74 61 08  00 00 00 00 00 07 76 65   ...data.......ve  
DEBUG2:   00c0:  72 73 69 6f 6e 02 00 09  33 2c 35 2c 32 2c 36 35   rsion...3,5,2,65  
DEBUG2:   00d0:  34 00 00 09 00 08 63 6c  69 65 6e 74 69 64 00 41   4.....clientid.A  
DEBUG2:   00e0:  a0 ac 26 9a 00 00 00 00  0e 6f 62 6a 65 63 74 45   ..&......objectE  
DEBUG2:   00f0:  6e 63 6f 64 69 6e 67 00  00 00 00 00 00 00 00 00   ncoding.........  
DEBUG2:   0100:  00 00 09                                           ...               
DEBUG: RTMP_ClientPacket, received: invoke 259 bytes
DEBUG: (object begin)
DEBUG: (object begin)
DEBUG: Property: <Name:             fmsVer, STRING:	FMS/3,5,2,654>
DEBUG: Property: <Name:       capabilities, NUMBER:	31.00>
DEBUG: Property: <Name:               mode, NUMBER:	1.00>
DEBUG: (object end)
DEBUG: (object begin)
DEBUG: Property: <Name:              level, STRING:	status>
DEBUG: Property: <Name:               code, STRING:	NetConnection.Connect.Success>
DEBUG: Property: <Name:        description, STRING:	Connection succeeded.>
DEBUG: Property: <Name:               data, OBJECT>
DEBUG: (object begin)
DEBUG: Property: <Name:            version, STRING:	3,5,2,654>
DEBUG: (object end)
DEBUG: Property: <Name:           clientid, NUMBER:	139858765.00>
DEBUG: Property: <Name:     objectEncoding, NUMBER:	0.00>
DEBUG: (object end)
DEBUG: (object end)
DEBUG: HandleInvoke, server invoking <_result>
DEBUG: HandleInvoke, received result for method call <connect>
DEBUG2: RTMP_SendPacket: fd=7, size=37
DEBUG2:   0000:  43 00 00 00 00 00 25 14                            C.....%.          
DEBUG2:   0000:  02 00 0d 72 65 6c 65 61  73 65 53 74 72 65 61 6d   ...releaseStream  
DEBUG2:   0010:  00 40 00 00 00 00 00 00  00 05 02 00 08 74 65 73   .@...........tes  
DEBUG2:   0020:  74 2e 73 64 70                                     t.sdp             
DEBUG: Invoking releaseStream
DEBUG2: RTMP_SendPacket: fd=7, size=33
DEBUG2:   0000:  43 00 00 00 00 00 21 14                            C.....!.          
DEBUG2:   0000:  02 00 09 46 43 50 75 62  6c 69 73 68 00 40 08 00   ...FCPublish.@..  
DEBUG2:   0010:  00 00 00 00 00 05 02 00  08 74 65 73 74 2e 73 64   .........test.sd  
DEBUG2:   0020:  70                                                 p                 
DEBUG: Invoking FCPublish
DEBUG2: RTMP_SendPacket: fd=7, size=25
DEBUG2:   0000:  43 00 00 00 00 00 19 14                            C.......          
DEBUG2:   0000:  02 00 0c 63 72 65 61 74  65 53 74 72 65 61 6d 00   ...createStream.  
DEBUG2:   0010:  40 10 00 00 00 00 00 00  05                        @........         
DEBUG: Invoking createStream
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  03 00 00 00 00 00 1d 14  00 00 00 00               ............      
DEBUG2:   0000:  02 00 07 5f 72 65 73 75  6c 74 00 40 10 00 00 00   ..._result.@....  
DEBUG2:   0010:  00 00 00 05 00 3f f0 00  00 00 00 00 00            .....?.......     
DEBUG: RTMP_ClientPacket, received: invoke 29 bytes
DEBUG: (object begin)
DEBUG: Property: NULL
DEBUG: (object end)
DEBUG: HandleInvoke, server invoking <_result>
DEBUG: HandleInvoke, received result for method call <createStream>
DEBUG2: RTMP_SendPacket: fd=7, size=38
DEBUG2:   0000:  04 00 00 00 00 00 26 14  01 00 00 00               ......&.....      
DEBUG2:   0000:  02 00 07 70 75 62 6c 69  73 68 00 40 14 00 00 00   ...publish.@....  
DEBUG2:   0010:  00 00 00 05 02 00 08 74  65 73 74 2e 73 64 70 02   .......test.sdp.  
DEBUG2:   0020:  00 04 6c 69 76 65                                  ..live            
DEBUG: Invoking publish
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  02 00 00 00 00 00 06 04  00 00 00 00               ............      
DEBUG2:   0000:  00 00 00 00 00 01                                  ......            
DEBUG: HandleCtrl, received ctrl. type: 0, len: 6
DEBUG: HandleCtrl, Stream Begin 1
DEBUG2: RTMP_ReadPacket: fd=7
DEBUG2:   0000:  03 00 00 00 00 00 80 14  01 00 00 00               ............      
DEBUG2:   0000:  02 00 08 6f 6e 53 74 61  74 75 73 00 00 00 00 00   ...onStatus.....  
DEBUG2:   0010:  00 00 00 00 05 03 00 05  6c 65 76 65 6c 02 00 06   ........level...  
DEBUG2:   0020:  73 74 61 74 75 73 00 04  63 6f 64 65 02 00 17 4e   status..code...N  
DEBUG2:   0030:  65 74 53 74 72 65 61 6d  2e 50 75 62 6c 69 73 68   etStream.Publish  
DEBUG2:   0040:  2e 53 74 61 72 74 00 0b  64 65 73 63 72 69 70 74   .Start..descript  
DEBUG2:   0050:  69 6f 6e 02 00 14 50 75  62 6c 69 73 68 69 6e 67   ion...Publishing  
DEBUG2:   0060:  20 74 65 73 74 2e 73 64  70 2e 00 08 63 6c 69 65    test.sdp...clie  
DEBUG2:   0070:  6e 74 69 64 00 41 a0 ac  26 9a 00 00 00 00 00 09   ntid.A..&.......  
DEBUG: RTMP_ClientPacket, received: invoke 128 bytes
DEBUG: (object begin)
DEBUG: Property: NULL
DEBUG: (object begin)
DEBUG: Property: <Name:              level, STRING:	status>
DEBUG: Property: <Name:               code, STRING:	NetStream.Publish.Start>
DEBUG: Property: <Name:        description, STRING:	Publishing test.sdp.>
DEBUG: Property: <Name:           clientid, NUMBER:	139858765.00>
DEBUG: (object end)
DEBUG: (object end)
DEBUG: HandleInvoke, server invoking <onStatus>
DEBUG: HandleInvoke, onStatus: NetStream.Publish.Start

Data Packets

DEBUG2: RTMP_SendPacket: fd=7, size=327
DEBUG2:   0000:  04 00 00 00 00 01 47 12  01 00 00 00               ......G.....      
DEBUG2:   0000:  02 00 0d 40 73 65 74 44  61 74 61 46 72 61 6d 65   ...@setDataFrame  
DEBUG2:   0010:  02 00 0a 6f 6e 4d 65 74  61 44 61 74 61 08 00 00   ...onMetaData...  
DEBUG2:   0020:  00 0c 00 08 64 75 72 61  74 69 6f 6e 00 00 00 00   ....duration....  
DEBUG2:   0030:  00 00 00 00 00 00 05 77  69 64 74 68 00 40 68 00   .......width.@h.  
DEBUG2:   0040:  00 00 00 00 00 00 06 68  65 69 67 68 74 00 40 62   .......height.@b  
DEBUG2:   0050:  00 00 00 00 00 00 00 0d  76 69 64 65 6f 64 61 74   ........videodat  
DEBUG2:   0060:  61 72 61 74 65 00 40 60  c5 a0 00 00 00 00 00 09   arate.@`........  
DEBUG2:   0070:  66 72 61 6d 65 72 61 74  65 00 40 82 c0 00 00 00   framerate.@.....  
DEBUG2:   0000:  c4                                                 .                 
DEBUG2:   0000:  00 00 00 0c 76 69 64 65  6f 63 6f 64 65 63 69 64   ....videocodecid  
DEBUG2:   0010:  00 40 1c 00 00 00 00 00  00 00 0d 61 75 64 69 6f   .@.........audio  
DEBUG2:   0020:  64 61 74 61 72 61 74 65  00 40 3f 16 00 00 00 00   datarate.@?.....  
DEBUG2:   0030:  00 00 0f 61 75 64 69 6f  73 61 6d 70 6c 65 72 61   ...audiosamplera  
DEBUG2:   0040:  74 65 00 40 e5 88 80 00  00 00 00 00 0f 61 75 64   te.@.........aud  
DEBUG2:   0050:  69 6f 73 61 6d 70 6c 65  73 69 7a 65 00 40 30 00   iosamplesize.@0.  
DEBUG2:   0060:  00 00 00 00 00 00 06 73  74 65 72 65 6f 01 00 00   .......stereo...  
DEBUG2:   0070:  0c 61 75 64 69 6f 63 6f  64 65 63 69 64 00 40 24   .audiocodecid.@$  
DEBUG2:   0000:  c4                                                 .                 
DEBUG2:   0000:  00 00 00 00 00 00 00 0b  6d 61 6a 6f 72 5f 62 72   ........major_br  
DEBUG2:   0010:  61 6e 64 02 00 04 71 74  20 20 00 07 65 6e 63 6f   and...qt  ..enco  
DEBUG2:   0020:  64 65 72 02 00 0b 4c 61  76 66 35 32 2e 38 37 2e   der...Lavf52.87.  
DEBUG2:   0030:  31 00 08 66 69 6c 65 73  69 7a 65 00 00 00 00 00   1..filesize.....  
DEBUG2:   0040:  00 00 00 00 00 00 09                               .......           
DEBUG2: RTMP_SendPacket: fd=7, size=29
DEBUG2:   0000:  04 00 00 00 00 00 1d 09  01 00 00 00               ............      
DEBUG2:   0000:  17 00 00 00 00 01 42 00  1e ff e1 00 09 67 42 00   ......B......gB.  
DEBUG2:   0010:  1e 8d 68 30 4e 40 01 00  04 68 ce 09 c8            ..h0N@...h...     
DEBUG2: RTMP_SendPacket: fd=7, size=4
DEBUG2:   0000:  04 00 00 00 00 00 04 08  01 00 00 00               ............      
DEBUG2:   0000:  af 00 12 08                                        ....              
DEBUG2: RTMP_SendPacket: fd=7, size=6
DEBUG2:   0000:  04 00 00 00 00 00 06 08  01 00 00 00               ............      
DEBUG2:   0000:  af 01 00 88 40 07                                  ....@.            
DEBUG2: RTMP_SendPacket: fd=7, size=175
DEBUG2:   0000:  44 00 00 17 00 00 af 08                            D.......          
DEBUG2:   0000:  af 01 00 f4 93 fe cc f2  00 00 00 00 00 07 13 f7   ................  
DEBUG2:   0010:  8e 06 1a 90 1b 56 44 f4  d0 0f 48 ee bf 2a fb 97   .....VD...H..*..  
DEBUG2:   0020:  9f fd 4b bc ee e0 1d cf  c3 f9 af 27 fa 77 4f f0   ..K........'.wO.  
DEBUG2:   0030:  bf 0c 01 f1 be cf d7 3e  3b 9e 87 ac 7f 76 00 f5   .......>;....v..  
DEBUG2:   0040:  bd 5f 5d f0 9d 86 cf 2d  ec 80 00 3d 6f a4 f7 be   ._]....-...=o...  
DEBUG2:   0050:  ab b8 68 f7 1f 5b e3 fa  cf 2b d6 bf 8b ec be a7   ..h..[...+......  
DEBUG2:   0060:  ce 00 00 e0 e9 d7 8c f8  c7 49 dd 74 bb 5f 3f ec   .........I.t._?.  
DEBUG2:   0070:  3c cf 69 e3 be 7d e3 40  00 38 19 e9 f4 11 af fa   <.i..}.@.8......  
DEBUG2:   0000:  c4                                                 .                 
DEBUG2:   0000:  76 b7 03 a2 af 0b d1 fa  57 96 ec 40 00 00 39 3c   v.......W..@..9<  
DEBUG2:   0010:  3e 26 87 2f b9 fd 77 a5  f7 bf 0f fd df b8 6b f9   >&./..w.......k.  
DEBUG2:   0020:  ae e9 e1 be 1b c0 f4 fd  67 87 e2 f8 2e 93 07      ........g......   
DEBUG2: RTMP_SendPacket: fd=7, size=3764
DEBUG2:   0000:  44 00 00 13 00 0e b4 09                            D.......          
DEBUG2:   0000:  17 01 00 00 00 00 00 0e  ab 65 b8 00 04 17 ff ff   .........e......  
DEBUG2:   0010:  c6 08 82 22 80 00 86 ef  92 88 c4 3d c8 5f 01 d7   ...".......=._..  
DEBUG2:   0020:  89 4f ff db 1e ee 2e fe  ec b9 9d ef e6 53 c2 00   .O...........S..  
DEBUG2:   0030:  0e 3d 65 6d 44 7c df b7  62 3b 01 6f 83 8d 90 a3   .=emD|..b;.o....  
DEBUG2:   0040:  fe 98 f9 7e 66 31 d3 70  7e fa f6 e8 1b 73 29 1f   ...~f1.p~....s).  
DEBUG2:   0050:  48 c8 95 69 98 06 44 50  3c 66 84 2d f2 4f 92 75   H..i..DP<f.-.O.u  
DEBUG2:   0060:  a0 cb 92 3e 23 75 b5 d5  fc 00 67 32 0f 5c f3 ef   ...>#u....g2.\..  
DEBUG2:   0070:  46 df ef bb e6 a9 93 4f  6f 3e 67 64 5a 47 3d aa   F......Oo>gdZG=.  
DEBUG2:   0000:  c4                                                 .                 

From the look of this dump I would have to say yes to your question. It looks like the first packet contains this information.

I started to work directly with librtmp, but I have sense stopped and moved to using RTSP. Take a look at FFmpeg avformat/flvenc.c . This is what all AV data gets piped through before sending to librtmp. There is also avformat/librtmp.c.

Thanks for replying.

From Adobe specification, it is required to send the DataMessage containing the metadata(width,height,bit rate…) before sending the Video packets. This is after connect,createStream and publish.

Does RTMP_Write() takes care of sending the DataMesage before sending video packets?

Thanks,

Dhruva

Ok, I will post my queries to rtmpdump mailing list.

Thanks for replying,

Dhruva