RTMP Agreement is Real Time Message Protocol( Real time information transfer protocol ) Abbreviation , It is from Adobe An application layer protocol proposed by the company , It is used to solve the multiplexing of multimedia data transmission stream (Multiplexing) And subcontracting (packetizing) The problem of . With VR Technological development , Live video and other fields are becoming more and more active ,RTMP As a widely used protocol in the industry, it has been valued by relevant developers again . I have been engaged in this field recently , Record your opinion on RTMP The understanding of the , Most of the articles are translated from English version RTMP file , Rearrange according to my understanding , Hope to help you want to know RTMP Friends of the agreement , I'll look it up in the future .


1. General introduction :
RTMP Protocol is the application layer protocol , It depends on the underlying reliable transport layer protocol ( Usually TCP) To ensure the reliability of information transmission . After the link based on transport layer protocol is established ,RTMP The protocol also requires the client and server to pass through “ handshake ” To build a transport layer based link RTMP Connection link , stay Connection Some control information will be transmitted on the link , Such as SetChunkSize,SetACKWindowSize. among CreateStream The command creates a Stream link , The command information used to transmit specific audio and video data and control the transmission of these information .RTMP Protocol transmission will do its own format for the data , This format of information we call RTMP Message, In the actual transmission, in order to achieve better multiplexing 、 The fairness of subcontracting and information , The sender will send Message Divided into with Message ID Of Chunk, Every Chunk It could be a separate Message, It could be Message Part of , At the receiving end, it will be based on chunk It contains data The length of ,message id and message The length of chunk Restore to complete Message, So as to realize the sending and receiving of information .
2. handshake
To build an effective RTMP Connection link , First of all “ handshake ”: The client will send to the server C0,C1,C2( In order ) Three chunk, The server sends... To the client S0,S1,S2( In order ) Three chunk, Then we can have effective information transmission .RTMP The agreement itself does not provide for this 6 individual Message The specific transmission sequence of , but RTMP The implementer of the protocol needs to guarantee these points :
- The client has to wait for it to be received S1 And then you can send C2
- The client has to wait for it to be received S2 Then you can send other messages ( Control information and real audio and video data )
- The server has to wait until it's received C0 After sending S1
- The server must wait until it is received C1 And then you can send S2
- The server must wait until it is received C2 Then you can send other messages ( Control information and real audio and video data )
If you send one handshake at a time chunk The order of handshakes is like this :

Theoretically, as long as the above conditions are met , How to arrange 6 individual Message It's possible to do everything in the same order , But in practice, in order to ensure the authentication function of handshake and reduce the number of communication as much as possible , The general sending order is like this , This can be done through wireshark Catch ffmpeg Push streaming package to verify :
|client|Server |
|---C0+C1—->|
|<--S0+S1+S2– |
|---C2----> |

3. RTMP Chunk Stream

Chunk Stream It's about transmission RTMP Chunk The logical abstraction of the flow of , The relationship between the client and the server RTMP All of the information is communicated on this stream . The operation on this stream is also our concern RTMP The point of the agreement .

3.1 Message( news )

there Message Means to satisfy the format of the agreement 、 It can be divided into Chunk Message sent , The message contains the following fields :

  • Timestamp( Time stamp ): The time stamp of the message ( But it's not necessarily the current time , Later on ),4 Bytes
  • Length( length ): Refer to Message Payload( Message payload ) That is, the data length of audio and video information ,3 Bytes
  • TypeId( type Id): The type of message Id,1 Bytes
  • Message Stream ID( The flow of messages ID): A unique identifier for each message , Divide into Chunk And reduction Chunk by Message It's all based on this ID To identify whether it's the same message Chunk Of ,4 Bytes , And stored in small end format

    3.2 Chunking(Message Block )

    RTMP Not when sending and receiving data Message Unit , But the Message Split into Chunk send out , And it has to be in one Chunk The next one can't be sent until the sending is finished Chunk. Every Chunk With medium MessageID Which does it belong to Message, The receiver will also follow this id to chunk Assemble into Message.
    Why? RTMP To put Message Split into different Chunk Well ? By splitting , A large amount of data Message Can be split into smaller “Message”, In this way, messages with low priority can be avoided to send messages with high priority , For example, in the process of video transmission , It will include video frames , Audio frames and RTMP Control information , If you continue to send audio data or control data, it may cause video frame blocking , And then it's going to cause the most annoying Caton phenomenon when watching videos . At the same time, for the small amount of data Message, It can be done by Chunk Header To compress information , So as to reduce the amount of information transmission .( The specific compression method will be introduced later )
    Chunk The default size is 128 byte , During transmission , Through a program called Set Chunk Size The control information of can be set Chunk The maximum amount of data , At the sending end and receiving end, each maintains a Chunk Size, You can set this value to change the message sent by your own party Chunk Maximum size of . A bigger one Chunk Reduced the calculation of each chunk So it reduces CPU The occupancy rate of , But it takes more time to send , Especially in the case of low bandwidth networks , It's likely to block the transmission of more important information . Smaller Chunk It can reduce this blocking problem , But the small ones Chunk Too much extra information will be introduced (Chunk Medium Header), A small number of multiple transmissions may also cause transmission discontinuities, which may lead to the failure to make full use of the advantages of high bandwidth , Therefore, it is not suitable for transmission in high bit rate streams . In the actual transmission, different Chunk Size To try , Through the analysis of packet capture and other means to get the appropriate Chunk size , And in the process of transmission, it can be dynamically adjusted according to the current bandwidth information and the size of the actual information Chunk Size , So as to improve as much as possible CPU And reduce the blocking probability of information .
    3.3 Chunk Format( Block format )

    3.3.1 Basic Header( Basic header information ):
    Contains chunk stream ID( Flow channel Id) and chunk type(chunk The type of ),chunk stream id It is generally abbreviated as CSID, Used to uniquely identify a specific flow channel ,chunk type Decided the back Message Header The format of .Basic Header The length of may be 1,2, or 3 Bytes , among chunk type The length is fixed ( Occupy 2 position , Note that the unit is bit ,bit),Basic Header And the length of that depends on CSID Size , On the premise of enough storage of these two fields, it is better to use as few bytes as possible, so as to reduce the number of Header The increased amount of data .
    RTMP The protocol supports user-defined [3,65599] Between CSID,0,1,2 Special information reserved by agreement .0 representative Basic Header It takes up a total of 2 Bytes ,CSID stay [64,319] Between ,1 For occupation 3 Bytes ,CSID stay [64,65599] Between ,2 On behalf of chunk It's control information and some command information , There will be a detailed introduction later .
    chunk type The length of is fixed as 2 position , therefore CSID Is the length of the (6=8-2)、(14=16-2)、(22=24-2) One of them .
    When Basic Header by 1 Bytes ,CSID Occupy 6 position ,6 At most bits can represent 64 Number , So in this case CSID stay [0,63] Between , The user-defined range is [3,63].

    When Basic Header by 2 Bytes ,CSID Occupy 14 position , At this point the agreement will be with chunk type All other bits in the byte are set to 0, The remaining byte represents CSID-64, So a total of 8 Two binary bits to store CSID,8 Bits can represent [0,255] common 256 Number , So in this case CSID stay [64,319], among 319=255+64.

    When Basic Header by 3 Bytes ,CSID Occupy 22 position , At this point, the agreement will [2,8] Byte set to 1, The rest of the 16 Byte representation CSID-64, So a total of 16 One bit to store CSID,16 Bits can represent [0,65535] common 65536 Number , So in this case CSID stay [64,65599], among 65599=65535+64, It should be noted that ,Basic Header It's small end storage , The further the byte, the higher the order of magnitude , So through this 3 The value of each byte is calculated CSID when , Should be :< The value of the third byte >x256+< The value of the second byte >+64

    You can see 2 Bytes and 3 Bytes of Basic Header What can be expressed CSID There are intersections [64,319], But the actual implementation should still adhere to the principle of the least number of bytes 2 A byte representation of [64,319] Of CSID.

    3.3.2 Message Header( The header of the message )
    Contains the actual information to be sent ( It could be complete , It could also be part of ) Description information of .Message Header The format and length of depends on Basic Header Of chunk type, share 4 Different formats , From the above mentioned Basic Header Medium fmt Field control . The first format can represent all the data of the other three representations , But because the other three formats are based on the previous chunk A differential representation of , So the same data can be represented more concisely , In practice, we should use as few bytes as possible to represent data with the same meaning . The following is an introduction to this in the order of the number of bytes 4 Species format Message Header.
    Type=0:

    type=0 when Message Header Occupy 11 Bytes , It can represent all the other three kinds of data , But in chunk stream The first one at the beginning of chunk And the timestamp in the header ( That is, the value is the same as the previous one chunk Compared to reducing , This usually happens when playing back ) You have to use this format when you do .

    • timestamp( Time stamp ): Occupy 3 Bytes , So it can express at most 16777215=0xFFFFFF=2^24 -1 ,  When its value exceeds this maximum , All three bytes are set to 1, So practical timestamp Will be transferred to Extended Timestamp Field , The receiver is judging timestamp Field 24 All the seats are 1 It will
      Go to Extended timestamp Parse the actual timestamp in .
    • message length( Length of message data ): Occupy 3 Bytes , Data representing the message actually sent, such as audio frames 、 The length of data such as video frames , Unit is byte . Notice that this is Message The length of , That is to say chunk Belonging to Message The total data length of , instead of chunk In itself Data The length of the data .
    • message type id( The type of message id): Occupy 1 Bytes , Represents the type of data actually sent , Such as 8 For audio data 、9 For video data .
    • msg stream id( The flow of messages id): Occupy 4 Bytes , It means that we should chunk In the stream of ID, and Basic Header Of CSID equally , It uses small end storage ,
      Type = 1:

      type=1 when Message Header Occupy 7 Bytes , Omit the expression msg stream id Of 4 Bytes , It means this chunk And the last one chunk In the same stream , If there is only one stream link between the sender and the opposite end, this format can be adopted as far as possible .
      timestamp delta: Occupy 3 Bytes , Notice here and type=0 Time is different , It's stored with the last chunk The time difference . Similar to the above mentioned timestamp, When its value exceeds 3 The maximum value that a byte can represent , All three bytes are set to 1, The actual timestamp difference will be transferred to Extended Timestamp Field , The receiver is judging timestamp delta Field 24 All the seats are 1 I'll go when I get there Extended timestamp The difference between the resolution time and the last timestamp in .
      Type = 2:

      type=2 when Message Header Occupy 3 Bytes , be relative to type=1 The format eliminates the need to represent the length of the message 3 Bytes and... Representing the message type 1 Bytes , It means this chunk And the last one sent chunk The stream in which it is located 、 The length and type of the message are the same . The remaining three bytes represent timestamp delta, Use the same as type=1
      Type = 3
      0 byte !!! ok , It represents this chunk Of Message Header It's exactly the same as the last one , Naturally, there's no need to transmit it again . When it follows Type=0 Of chunk In the back , It's the same as the previous one chunk All the timestamps are the same . When even the time stamp is the same ? It's just one. Message Split into multiple chunk, This chunk And the last one chunk Belong to the same Message. And when it follows Type=1 perhaps Type=2 Of chunk In the back , It's the same as the previous one chunk The difference between the timestamps of is the same . Like the first one chunk Of Type=0,timestamp=100, the second chunk Of Type=2,timestamp delta=20, Indicates that the timestamp is 100+20=120, Third chunk Of Type=3, Express timestamp delta=20, Timestamp 120+20=140
      3.3.3 Extended Timestamp( Extended timestamp )
      We mentioned above that in chunk There will be timestamps in timestamp It's different from the timestamp timestamp delta, And they don't exist at the same time , Only one of the two is greater than 3 The maximum number that a byte can represent 0xFFFFFF=16777215 when , This field is used to represent the real time stamp , Otherwise, this field is 0. Extended timestamps account for 4 Bytes , The maximum value that can be expressed is 0xFFFFFFFF=4294967295. When extended timestamps are enabled ,timestamp Field or timestamp delta Set it all to 1, Indicates that the timestamp field should be expanded to extract the real timestamp or timestamp difference . Note that the extended timestamp stores the full value , Instead of subtracting the value of the timestamp or the difference between the timestamps .
      3.3.4 Chunk Data( Piece of data )
      Protocol independent data that users really want to send , The length is in (0,chunkSize] Between .
      3.3.5 chunk Example 1

      The first includes the first Message Of chunk Of Chunk Type by 0, Because it has nothing to refer to chunk,timestamp by 1000, Time stamp .type by 0 Of header Occupy 11 Bytes , Assume chunkstreamId by 3<127, therefore Basic Header Occupy 1 Bytes , Plus Data Of 32 Bytes , So the first one chunk common 44=11+1+32 Bytes .
      the second chunk And the first chunk Of CSID,TypeId,Data They're all the same length , So we use Chunk Type=2,timestamp delta=1020-1000=20, So the second chunk Occupy 36=3+1+32 Bytes .
      Third chunk And the second chunk Of CSID,TypeId,Data The length and timestamp difference of are the same , So we use Chunk Type=3 Save all Message Header Information about , Occupy 33=1+32 Bytes .
      The fourth one chunk And the third chunk The same thing , It also takes up 33=1+32 Bytes .
      The last one actually sent chunk as follows :

      3.3.6 chunk Example 2

      be aware Data Of Length=307>128, So the Message Cut it into several chunk send out , first chunk Of Type=0,Timestamp=1000, To undertake 128 Bytes of Data, So it takes up 140=11+1+128 Bytes .
      the second chunk Send it, too 128 Bytes , The other fields are the same as the first chunk, So we use Chunk Type=3, In this case, the timestamp is also 1000, Co occupation 129=1+128 Bytes .
      Third chunk To send Data The length of is 307-128-128=51 Bytes , Or adopt Type=3, Co occupation 1+51=52 Bytes .
      The last one actually sent chunk as follows :

      3.4 Protocol control messages (Protocol Control Message)
      stay RTMP Of chunk The flow will use some special values to represent the control message of the protocol , Their Message Stream ID It has to be for 0( Represents control flow information ),CSID It has to be for 2,Message Type ID It can be for 1,2,3,5,6, The information of the specific representatives will be explained in the following order . The receiver of the control message will ignore chunk Timestamp in , Effective immediately upon receipt .

      • Set Chunk Size(Message Type ID=1): Set up chunk in Data The maximum number of bytes that a field can hold , The default is 128B, In the process of communication, you can set... By sending this message chunk Size Size ( Not less than 128B), And both sides of the communication will maintain one chunkSize, At both ends chunkSize It's independent . For example, when A Would like to B Send a 200B Of Message, But by default chunkSize yes 128B, So split the message into Data Respectively 128B and 72B Of the two chunk send out , If you send a setting first chunkSize by 256B The news of , Send again Data by 200B Of chunk, There's no local division Message,B Accept to Set Chunk Size The protocol control message will be adjusted when received chunk Of Data Size , You don't have to put two more chunk Make up a Message.
        The following are representatives of Set Chunk Size News chunk Of Data:

        The first one must be 0,chunk Size Occupy 31 bits , The largest representative of 2147483647=0x7FFFFFFF=2^31 -1, But actually all of them are bigger than 16777215=0xFFFFFF=2^24 -1 You can't use it , because chunk size Not greater than Message The length of , Express Message The length field of is used 3 In bytes , Maximum can only be 0xFFFFFF.
      • Abort Message(Message Type ID=2): When one Message Divided into multiple chunk, The receiver only received part of chunk when , Sending the control message means that the sender no longer transmits the same message Message Of chunk, After receiving this message, the receiver should discard the incomplete chunk.Data Only one is needed in the data CSID, It means to discard the CSID All received chunk.
      • Acknowledgement(Message Type ID=3): When the size of the received message is equal to the size of the window (Window Size) The receiver should give back a ACK Tell the sender that it can continue to send data . The size of the window refers to the size of the window returned by the receiving end ACK The maximum number of bytes that can be sent before , Back to ACK Will be sent from the previous ACK The number of bytes received after .
      • Window Acknowledgement Size(Message Type ID=5): The sender returns two ACK The maximum number of bytes that can be sent between .
      • Set Peer Bandwidth(Message Type ID=6): Limit the output bandwidth of the opposite end . After receiving the message, the receiver will set the Window ACK Size To limit the size of messages that have been sent but have not received feedback, to limit the sending bandwidth of the sender . If the message Window ACK Size Same as last sent to sender size If it's different, give back one Window Acknowledgement Size Control message for .
        • Hard(Limit Type=0): The receiver should put Window Ack Size Set to the value in the message
        • Soft(Limit Type=1): The receiver can send Window Ack Size Set to the value in the message , You can also save the original value ( The premise is the original Size Less than... In the control message Window Ack Size)
        • Dynamic(Limit Type=2): If last time Set Peer Bandwidth In the news Limit Type by 0, This time also press Hard Handle , Otherwise ignore this message , Do not set up Window Ack Size.

4. Different types of RTMP Message

  • Command Message( Command message ,Message Type ID=17 or 20): Represents a command message that is passed between a client and a server to perform certain operations on the opposite end , Such as connect Represents the opposite end of the connection , If the peer agrees to connect, it will record the sender's information and return the successful connection message ,publish Start to push the stream to the other side , After receiving the command, the receiving end is ready to receive the stream information sent by the opposite end , We'll talk about the more common Command Message Specific introduction . When information is used AMF0 When coding ,Message Type ID=20,AMF3 When coding Message Type ID=17.
  • Data Message( Data messages ,Message Type ID=15 or 18): Passing some metadata (MetaData, Like the name of the video , Resolution and so on ) Or some user-defined messages . When information is used AMF0 When coding ,Message Type ID=18,AMF3 When coding Message Type ID=15.
  • Shared Object Message( Sharing messages ,Message Type ID=16 or 19): It means a Flash Object of type , It consists of a set of key value pairs , For multi client , When multiple instances are used . When information is used AMF0 When coding ,Message Type ID=19,AMF3 When coding Message Type ID=16.
  • Audio Message( Audio information ,Message Type ID=8): Audio data .
  • Video Message( Video information ,Message Type ID=9): Video data .
  • Aggregate Message ( Gather information ,Message Type ID=22): Multiple RTMP A collection of sub messages
  • User Control Message Events( User control messages ,Message Type ID=4): Tell the other party to execute the user control event contained in the information , such as Stream Begin The event tells the other party that the flow information begins to transmit . And the protocol control information mentioned above (Protocol Control Message) Different , This is RTMP Protocol layer , Not in RTMP chunk Streaming protocol layer , It's easy to confuse . This information is available at chunk When sending in the stream ,Message Stream ID=0,Chunk Stream Id=2,Message Type Id=4.
    ——— The following is about the above 7 There are two kinds of information ———-
    4.1 Command Message( Command message ,Message Type ID=17 or 20)
    The sender will send it with the name of the command , Such as connect,TransactionID Indicates the identity of this command ,Command Object Represents the relevant parameters . After receiving the command , Will return one of the following three messages :_result The message indicates acceptance of the command , The opposite end can continue to execute the process ,_error The message represents a rejection of the operation to be performed by the command ,method name The message represents the name of the function to be executed at the sender of the previous command . All three types of response messages should be accompanied by the... In the received command message TransactionId To indicate which command this response is applied to .
    It can be considered that there are two kinds of objects to send command messages , One is NetConnection, Represents the upper connection of two terminals , One is NetStream, Represents the transport channel of stream information , State of control flow information , Such as Play Play stream ,Pause Pause .
    4.1.1 NetConnection Commands( Connect layer commands )
    It is used to manage the connection state between two terminals , It also provides asynchronous remote method calls (RPC) Execute a method on the opposite end , Here are some common connection layer commands :
    4.1.1.1 connect: It is used to send connection request from client to server , The structure of the message is as follows :
Field type explain
Command Name( Command name ) String The name of the order , Such as ”connect”
Transaction ID( Business ID) Number Constant for the 1
Command Object( The parameter object contained in the command ) Object The command parameter represented by the key value pair set
Optional User Arguments( Additional user parameters ) Object User defined extra information

In the third field Command Object There are a lot of key value pairs involved in , There is no longer a list of , You can refer to the official document of the agreement when using it .
There are two kinds of responses to messages ,_result Indicates that the connection is accepted ,_error Indicates that the connection failed

4.1.1.2 Call: Used to execute a function on the opposite end , That is to say RPC: Remote process call , The structure of the message is as follows :

Field type explain
Procedure Name( Process name ) String The name of the process to call
Transaction ID Number| If you want to respond to the end, set it to not 0 value , Otherwise, set to 0
Command Object Object Command parameter
Optional Arguents Object User defined parameters

If the message TransactionID Not for 0 Words , The peer needs to respond to the command , The message structure of the response is as follows :

Field type explain
Command Name( Command name ) String Name of the command
TransactionID Number In the command message received above TransactionID
Command Object Object Command parameter
Optional Arguments Object User defined parameters

4.1.1.3 Create Stream: Create channels for delivering specific information , So that specific information can be passed in the stream , The transmission information unit is Chunk.

Field type explain
Command Name( Command name ) String “createStream”
TransactionID Number In the command message received above TransactionID
Command Object Object Command parameter
Optional Arguments Object User defined parameters

4.1.2 NetStream Commands( Commands on stream connections )

Netstream Based on the NetConnection above , adopt NetConnection Of createStream Command to create , Used to transmit specific audio 、 Video and other information . Only one... Can be connected on top of the transport layer protocol NetConnection, But a NetConnection You can create multiple NetStream To set up different streaming channels to transmit data .
Here are some common NetStream Commands, After receiving the command, the server will pass onStatus In response to the client , At present NetStream The state of .
onStatus The message structure of the command is as follows :

Field type explain
Command Name String “onStatus”
TransactionID Number Constant for the 0
Command Object NULL Yes onSatus You don't need this field for the command
Info Object Object AMF Type of Object, There are at least three properties :1,“level”,String type , It can be for “warning”、”status”、”error” One of the ;2,”code”,String type , Keywords representing specific states , such as ”NetStream.Play.Start” Start streaming ;3,”description”,String type , Represents a description of the current state , Provides a better explanation for the readability of the current state , Besides these three kinds of necessary information , Users can also add their own custom key value pairs

4.1.2.1 play( Play ): The client initiates a request to the server and receives data from the server ( If the information transmitted is video, it is a request to start streaming ), Can be called multiple times , In this way, a set of receivers of data flow will be formed locally . Notice one of them reset Field , Represents the stream before the overlay ( Set to true) Or start all the way back ( Set to false).
play The command structure is as follows :

Field type explain
Command name String “play”
Business ID Number Constant for the 0
Command parameter object Null This field is not required , Set to null
Stream name String The name of the stream to play
Starting position Number Optional parameters , Indicates when to start streaming , In seconds . The default is -2, Represents to select the live stream corresponding to the stream name , That is, the stream currently being pushed starts to play , If the live stream with the corresponding name does not exist , Select the recorded version of the stream with that name , If it doesn't have , The current stream end has to wait until the opposite end starts the live broadcast of the stream with that name . If passing value -1, Then only the live stream will be selected for playback , Even if there's a recording stream, it won't play ; If you pass a value or a positive number , It means to start playing from the time point of the stream , If the stream doesn't exist, it will automatically play the next stream in the list
cycle Number Optional parameters , Represents the minimum interval unit for fallback , Count in seconds . The default value is -1, It means that you can't play back until the live stream is no longer available or the recording stream stops ; If the value is 0, Represents playing from the current frame
Reset Boolean Optional parameters ,true Represents the flow before clearing , Start all the way back ,false It means to keep the original flow , Add another stream to the local play list

4.1.2.2 play2( Play ): And the above play The difference is ,play2 The command can switch the currently playing stream to the stream with the same data but different bit rates , The server will maintain a variety of bit rate files for the client to use play2 Command to switch .

Field type explain
Command Name String “play2”
TransactionID Number Constant for the 0
Command Object NULL, Yes onSatus You don't need this field for the command
parameters Object AMF Coded Flash object , Includes a number of descriptions for flash.net.NetstreamPlayOptions ActionScript obejct Parameters of

4.1.2.3 deleteStream( Delete stream ): It is used for the client to inform the server that a local stream object has been deleted , There is no need to transmit this stream any more .

Field type explain
Command Name String “deleteStream”
TransactionID Number Constant for the 0
Command Object NULL, Yes onSatus You don't need this field for the command
Stream ID( flow ID) Number Local deleted , There is no need for the server to transport the stream ID

4.1.2.4 receiveAudio( Receive audio ): Inform the server whether the client wants to send audio
receiveAudio The command structure is as follows :

Field type explain
Command Name String “receiveAudio”
TransactionID Number Constant for the 0
Command Object NULL Yes onSatus You don't need this field for the command
Bool Flag Boolean true Means to send audio , If the value is false, The server does not respond , If true Words , The server will be ready to accept audio data , Will reply to the client NetStream.Seek.Notify and NetStream.Play.Start Of Onstatus Command tells the client the status of the current stream

4.1.2.5 receiveVideo( Receiving video ): Inform the server whether the client wants to send video
receiveVideo The command structure is as follows :

Field type explain
Command Name String “receiveVideo”
TransactionID Number Constant for the 0
Command Object NULL Yes onSatus You don't need this field for the command
Bool Flag Boolean true Send video , If the value is false, The server does not respond , If true Words , The server will be ready to accept video data , Will reply to the client NetStream.Seek.Notify and NetStream.Play.Start Of Onstatus Command tells the client the status of the current stream

4.1.2.6 publish( Push data ): The client initiates a request to the server and pushes the stream to the server .
publish The command structure is as follows :

Field type explain
Command Name String “publish”
TransactionID Number Constant for the 0
Command Object NULL, Yes onSatus You don't need this field for the command
Publishing Name( The name of the push stream ) String Stream name |
Publishing Type( Push stream type ) String “live”、”record”、”append” One of the .live Indicates that the streaming file will not be stored on the server ;record The file representing the push stream will be saved in the subdirectory of the server application for subsequent playback , If the file already exists, delete all the original content and write it again ;append It will also save the streaming data on the server side , If the file does not exist, a new file will be created , If the file corresponding to the stream already exists, save the original data , Write... At the end of the file

4.1.2.7 seek( Position the flow ): Navigate to a location in video or audio , In Milliseconds .
seek The command structure is as follows :

Field type explain
Command Name String “seek”
TransactionID Number Constant for the 0
Command Object NULL, Yes onSatus You don't need this field for the command
milliSeconds Number Navigate to the xx MS |

4.1.2.8 pause( Pause ): The client tells the server to stop or resume playing .
pause The command structure is as follows :

Field type explain
Command Name String “pause”
TransactionID Number Constant for the 0
Command Object NULL, Yes onSatus You don't need this field for the command
Pause/Unpause Flag Boolean true To suspend ,false It means recovery
milliSeconds Number Time to pause or resume , In Milliseconds |

If Pause by true It means that the client requests to pause , When the server pauses, the corresponding stream will return NetStream.Pause.Notify Of onStatus Command to tell the client that the current stream is suspended , When Pause by false when , The server will return NetStream.Unpause.Notify To inform the client of the current stream recovery . If the server fails to respond to the command , return _error Information .

5. It represents the process
5.1 Push flow process

5.2 Streaming process

6. New recommendations

If the reader has read the above carefully RTMP agreement , I think I'll feel RTMP The agreement is very cumbersome , It's true ,RTMP The protocol is full of redundant fields , For example, the proofreading of time stamp in three handshakes , There are also some special orders , Such as FCPublish、UnFCPublish etc. , But in the actual implementation, in order to ensure greater compatibility, we usually have to deal with these seemingly redundant commands . add Adobe Yes RTMP Some of the implementation details of the protocol are not in accordance with the protocol or are not clearly written in the protocol. I have made a set of implementation , Other applications need to be compatible Adobe Wrong implementation , So that RTMP It has been criticized by developers . But anyway ,RTMP It does provide a comprehensive and simple protocol to ensure the transmission of streaming information , In this regard, there is no more perfect and concise protocol to replace its position in video stream development .
New people come into contact at first RTMP I'm sure I'll feel big when I'm young , This is also RTMP The consequences of not being concise . It is suggested that readers go through the protocol first and understand the general concept and process , Then compare it with wireshark The bag I caught , Compare with the protocol , This combines theory with practice , I should understand it faster .

from:http://mingyangshang.github.io/2016/03/06/RTMP agreement /

Take you through RTMP More articles about

  1. 【 Reprint 】 Take you through RTMP

    RTMP Agreement is Real Time Message Protocol( Real time information transfer protocol ) Abbreviation , It is from Adobe An application layer protocol proposed by the company , It is used to solve the multiplexing of multimedia data transmission stream (Multiplexing) ...

  2. 23 There are two key and difficult points to break through , Take you through Service Knowledge point 「 Long 1W+ word 」

    Preface learn Android It's been a while , I think many people are the same as me , I often learn from the East and learn from the West , I feel that knowledge points are a little messy and difficult to form a system . So take advantage of these days , Sum up what you have learned , To smooth out one's thinking . This article is mainly about Service relevant ...

  3. 【 turn 】23 A breakthrough in Android's key and difficult points , Take you through Service Knowledge point 「 Long 1W+ word 」

    Preface learn Android It's been a while , I think many people are the same as me , I often learn from the East and learn from the West , I feel that knowledge points are a little messy and difficult to form a system . So take advantage of these days , Sum up what you have learned , To smooth out one's thinking . This article is mainly about Service relevant ...

  4. An article takes you through Docker principle

    The implementation principle of container In essence , Container is actually a sandbox technology . It's like isolating applications in a box , Make it work . Because of the box boundary , Applications don't interfere with each other . And like a container , Take it and go , Run anywhere . This is actually Paa ...

  5. Live streaming implementation RTMP Some considerations of the agreement

    —— 2017-2-12 to update RTMP The agreement has been sorted out , Include rtmp Message type ,rtmp How to block ,rtmp Block example . Sort it out with brain maps , Use Xmind open ,URL: https://github. ...

  6. from 0 To 1 Create a live broadcast App

    from http://dev.qq.com/topic/5811d42e7fd6ec467453bf58 Summary Share content : The evolution of Internet content carrier , written words —— picture / voice —— video ——VR/AR——…….. From the straight ...

  7. 【 tencent Bugly Dry cargo sharing 】 from 0 To 1 Create a live broadcast App

    This article is from Tencent bugly Developer community , Without the consent of the author , Do not reprint , Original address :http://dev.qq.com/topic/5811d42e7fd6ec467453bf58 author : Li Zhiwen Summary Share content : ...

  8. from 0 To 1 Create a live broadcast App( Introduction and arrangement of live broadcast process &lt;mark&gt;&lt; turn &gt;)

    Indicate the : original  2016-10-27  Li Zhiwen   tencent Bugly Summary Share content : The evolution of Internet content carrier , written words —— picture / voice —— video ——VR/AR——…….. From live 1.0 Show time (YY),2.0 Live broadcast of the game ( Bucket ...

  9. build RTMP The server

    Main steps Specific steps FAQ docker Build version Reference resources Main steps download nginx Of rtmp modular compile nginx, belt hls,rtmp To configure nginx.conf, Set up rtmp The path to the streaming file ...

Random recommendation

  1. by Neutron Prepare the physical infrastructure (II) - Every day 5 Minutes to play OpenStack(76)

    This section will install and configure the control node and computing node according to the plan in the previous section . The control node devstack-controller Steps are as follows install Ubuntu 14.04 Omit here 256 A word Configure network card edit /etc/net ...

  2. python The color shows

    We know that at the command line ,python The color of the output string of is the same as that of ordinary characters . If we want to emphasize certain characters , We can use the code to turn the highlighted part into a certain color . stay linux Terminal commands can display a certain color , stay windows Of cmd end ...

  3. flash2x、flax

    http://flax.so/ Cattle from LeetCode Online Judge

  4. Eclipse establish Maven Unable to create after project src/main/java Resource folder

    Right click on the project and select properties, And then click java build path, stay Librarys Next , edit JRE System Library, choice workspace default jre That's all right. .

  5. OSG Initialize to a non full screen window

    OSG The default window is full screen , It's not convenient to debug . See a piece of code on the Internet , It can be non full screen int _tmain(int argc, _TCHAR* argv[]){ osgViewer::Viewer vie ...

  6. hadoop Programming skills (3)--- Define your own zoning categories Partitioner

    Hadoop Code test environment :Hadoop2.4 principle : stay Hadoop Of MapReduce The process .Mapper After reading the data . It sends data to Partitioner. from Partitioner Every record should be taken ...

  7. Supermarket POJ - 1456

    A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold ...

  8. linux Next (fdisk,gdisk,parted) Comparison of three partition tools

    1 2 A brief introduction to the three kinds of partition structure MBR Partition Hard disk master boot record MBR from 4 Component composition Master bootstrap ( offset 0000H--0088H), It is responsible for loading... From the active partition , And run the system boot program . Error message data area , offset 0089H- ...

  9. JMeter Variable passing between different thread groups

    JMeter Components are scoped , Most variables use regular expression extractors , To use variable parameters without thread components , All variables need to be set JMeter The function assistant provides a function for setting global variable properties , The function implemented is similar to that in the user self ...

  10. zoj 2722 Head-to-Head Match( Mathematical thinking )

    Topic link : http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2722 Title Description : Our school is planning ...