FMUSER Wirless Transmit Video And Audio More Easier !
es.fmuser.org
it.fmuser.org
fr.fmuser.org
de.fmuser.org
af.fmuser.org ->Afrikaans
sq.fmuser.org ->Albanian
ar.fmuser.org ->Arabic
hy.fmuser.org ->Armenian
az.fmuser.org ->Azerbaijani
eu.fmuser.org ->Basque
be.fmuser.org ->Belarusian
bg.fmuser.org ->Bulgarian
ca.fmuser.org ->Catalan
zh-CN.fmuser.org ->Chinese (Simplified)
zh-TW.fmuser.org ->Chinese (Traditional)
hr.fmuser.org ->Croatian
cs.fmuser.org ->Czech
da.fmuser.org ->Danish
nl.fmuser.org ->Dutch
et.fmuser.org ->Estonian
tl.fmuser.org ->Filipino
fi.fmuser.org ->Finnish
fr.fmuser.org ->French
gl.fmuser.org ->Galician
ka.fmuser.org ->Georgian
de.fmuser.org ->German
el.fmuser.org ->Greek
ht.fmuser.org ->Haitian Creole
iw.fmuser.org ->Hebrew
hi.fmuser.org ->Hindi
hu.fmuser.org ->Hungarian
is.fmuser.org ->Icelandic
id.fmuser.org ->Indonesian
ga.fmuser.org ->Irish
it.fmuser.org ->Italian
ja.fmuser.org ->Japanese
ko.fmuser.org ->Korean
lv.fmuser.org ->Latvian
lt.fmuser.org ->Lithuanian
mk.fmuser.org ->Macedonian
ms.fmuser.org ->Malay
mt.fmuser.org ->Maltese
no.fmuser.org ->Norwegian
fa.fmuser.org ->Persian
pl.fmuser.org ->Polish
pt.fmuser.org ->Portuguese
ro.fmuser.org ->Romanian
ru.fmuser.org ->Russian
sr.fmuser.org ->Serbian
sk.fmuser.org ->Slovak
sl.fmuser.org ->Slovenian
es.fmuser.org ->Spanish
sw.fmuser.org ->Swahili
sv.fmuser.org ->Swedish
th.fmuser.org ->Thai
tr.fmuser.org ->Turkish
uk.fmuser.org ->Ukrainian
ur.fmuser.org ->Urdu
vi.fmuser.org ->Vietnamese
cy.fmuser.org ->Welsh
yi.fmuser.org ->Yiddish
1. How to use RTMP streaming module in Demo
(1) For cross-platform, the latest version changes the rtmp streaming module to c++, and the RTMP streaming address can be modified in the doublesky_rtmp::p_start_rtmp() method of doublesky_rtmp.cpp
(2) In order to be lazy, the author did not parse sps and pps from the h264 file he wanted to push, but wrote sps and pps in the sps_pps parameter of the p_start_rtmp method. If you want to push your own h264 file, remember to modify it Here, otherwise the stream you pushed will be screened, I almost forgot here, and I am wondering how to change the file to launch the stream.
2. Realization of ideas
Still based on ffmpeg to encapsulate, the general process is
1. AVFormatContext及其中的AVIOContext、AVOutputFormat初始化,调用函数为avio_open与av_guess_format
2. 开启rtmp推流avformat_write_header
3. 写入音视频帧数据av_interleaved_write_frame
3. Protocol learning and packet capture analysis
The basic unit of the RTMP protocol is Message Body, and the message is divided into RTMP Chunk Header + RTMP Chunk Data during data transmission.
If a message is 300 bytes, the default size of RTMP Chunk Data is generally 128 bytes, so this 300-byte message is split into
The first package: RTMP Chunk Header + 128 byte payload
The second package: RTMP Chunk Header + 128 byte payload
The third package: RTMP Chunk Header + 44 byte payload
RTMP Chunk Header is composed of Basic Header + Message Header + Extended TimeStamp
Basic Header: 1-3 bytes Here I only saw 1 byte in the packet capture process, so I only analyze the format of 1 byte.
0 1 2 3 4 5 6 7 A total of 8 digits: 0-1 digits indicate Format, which is the length of Message Header, and digits 2-7 indicate Chunk Stream ID
When Format is 00, the Message Header length is 11 bytes: TimeStamp (3 bytes) + MessageLength (3 bytes) + MessageTypeID (1 byte) + MessageStreamID (4 bytes)
When Format is 01, the length of Message Header is 7 bytes: TimeStamp (3 bytes) + MessageLength (3 bytes) + MessageTypeID (1 byte)
When Format is 10, the Message Header length is 3 bytes: TimeStamp (3 bytes)
When Format is 11, the length of Message Header is 0 bytes: none
Here we find a screenshot of Wireshark's packet capture to analyze the corresponding protocol:
As you can see in Figure 1, the first byte is 03, the upper two bits represent the Format of Basic Header as 00, which means that the Message Header length is a complete 11 bytes, the Chunk Stream ID of the Basic Header is 3, and the Body Size is also It is MessageLength, which means that the payload data of the following RTMP Body is 141 bytes, and the MessageTypeID is 0x14. Here, let’s talk about the Message Type field. When it is 1-7, it is a protocol control message. 8 and 9 indicate that the RTMP body is audio and video data. -20 is data in AMF encoding format. AMF encoding is an encoding format developed by Adobe. A link to related information will be given later, and interested students can take a look.
4. Split audio and video frames into multiple RTMP packages
As mentioned earlier, the default size of RTMP Chunk Data in the protocol is 128 bytes, but everyone knows that even the compressed video frame is very large. Imagine if a video frame of 100,000 bytes is 128 bytes. If you split it by the unit, you need to split it into more than 780 packages, and you need more than 780 RTMP Chunk Headers. Not only does this cause data redundancy, but the unpacking and grouping of the sender and receiver also consumes performance. Therefore, we can see that in the process of pushing the stream, there is a protocol package of Set Chunk Size to set the size of the Chunk Data as shown in Figure 2. Here you can see that there will be a Type ID of 01 before the push, which sets the size of the RTMP Chunk Size. Package, here we see the set value is 4096.
The next step is to look at the splitting of the video packet. A large video frame is split into multiple chunk packets, but wireshark is not converted to RTMP packets but all recognized as TCP packets. Here I made myself doubt the understanding of RTMP. There is an error, the result of the packet capture is shown in Figure 3
Here you can see that the top number in Figure 3 is 3292 (the first row). The selected row of data has a total length of 78 bytes and the TCP payload is 12 bytes, which is actually a complete RTMP Chunk Header. According to the above protocol analysis, we can see RTMP Body Size is 00 6b c6 is 27590 bytes, which means that the total length of this frame of video is 27590 bytes, and then the number is 3293 (total length is 1514 bytes of data, its payload part 1448 bytes = 1514-14 (link layer frame header)-20 (ip header)-20 (tcp header)-12 (tcp option), the data analysis numbered 3294 is the same as that of 3293, the key to the data numbered 3295, Why its data load is only 1266 bytes (the load data is 1200 bytes, 1266 minus each protocol header data is 1200), this is why the Chunk Size has been set to 4096 in the protocol part before pushing the stream, so The load of an RTMP packet can only carry up to 4096 bytes of data. The load data of each part here is 1448+1448+1200, which is exactly equal to 4096. That is to say, an RTMP packet is sent, and the next data should be carried again. On the RTMP packet header, Figure 4 shows the next packet data.
In Figure 4, we take the first byte c6 as Basic Header. We can see that fmt is 11, which means there is no Message Header. It is estimated that this frame of video is too long and needs to be split into multiple 4096 packets, so the following packets can be used. Go to the Message Header of the first package to reduce redundancy.
Then I won’t analyze it further. I have to say that Wireshark didn’t help to convert TCP packets into RTMP packets, which wasted a lot of time here, but if you think about it carefully, it can be considered as a deepening of the understanding of the RTMP protocol.
|
Enter email to get a surprise
es.fmuser.org
it.fmuser.org
fr.fmuser.org
de.fmuser.org
af.fmuser.org ->Afrikaans
sq.fmuser.org ->Albanian
ar.fmuser.org ->Arabic
hy.fmuser.org ->Armenian
az.fmuser.org ->Azerbaijani
eu.fmuser.org ->Basque
be.fmuser.org ->Belarusian
bg.fmuser.org ->Bulgarian
ca.fmuser.org ->Catalan
zh-CN.fmuser.org ->Chinese (Simplified)
zh-TW.fmuser.org ->Chinese (Traditional)
hr.fmuser.org ->Croatian
cs.fmuser.org ->Czech
da.fmuser.org ->Danish
nl.fmuser.org ->Dutch
et.fmuser.org ->Estonian
tl.fmuser.org ->Filipino
fi.fmuser.org ->Finnish
fr.fmuser.org ->French
gl.fmuser.org ->Galician
ka.fmuser.org ->Georgian
de.fmuser.org ->German
el.fmuser.org ->Greek
ht.fmuser.org ->Haitian Creole
iw.fmuser.org ->Hebrew
hi.fmuser.org ->Hindi
hu.fmuser.org ->Hungarian
is.fmuser.org ->Icelandic
id.fmuser.org ->Indonesian
ga.fmuser.org ->Irish
it.fmuser.org ->Italian
ja.fmuser.org ->Japanese
ko.fmuser.org ->Korean
lv.fmuser.org ->Latvian
lt.fmuser.org ->Lithuanian
mk.fmuser.org ->Macedonian
ms.fmuser.org ->Malay
mt.fmuser.org ->Maltese
no.fmuser.org ->Norwegian
fa.fmuser.org ->Persian
pl.fmuser.org ->Polish
pt.fmuser.org ->Portuguese
ro.fmuser.org ->Romanian
ru.fmuser.org ->Russian
sr.fmuser.org ->Serbian
sk.fmuser.org ->Slovak
sl.fmuser.org ->Slovenian
es.fmuser.org ->Spanish
sw.fmuser.org ->Swahili
sv.fmuser.org ->Swedish
th.fmuser.org ->Thai
tr.fmuser.org ->Turkish
uk.fmuser.org ->Ukrainian
ur.fmuser.org ->Urdu
vi.fmuser.org ->Vietnamese
cy.fmuser.org ->Welsh
yi.fmuser.org ->Yiddish
FMUSER Wirless Transmit Video And Audio More Easier !
Contact
Address:
No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620
Categories
Newsletter