问题
I'm trying to stream live video from my android phone to a desktop RTSP server on my PC. The streamed video can be played in another device. I'm using H.264 video encoder, so the SDP returned by the server (as the reply of DESCRIBE
request) should contain the profile-level-id
and sprop-parameter-sets
fields.
The Spydroid project shows how to extract these info from a dummy file recorded to SD card by parsing it (from the avcC
block). But I cannot do it like that. In Spydroid, the media recorder and the RTSP server are on the same device, so the server can always record a test file with the same configuration as the recorder before streaming. But I'm streaming the video directly from the phone to the remote server as an RTP stream.
So my question is:
- How can I provide these values to the server maintaining the protocols?
- Is there any way to find out these two fields from the RTP stream?
Edit:
I'm using android phones to generate the streams, but the server can receive RTP stream from any source. So, is there any generic way to get these values?
回答1:
You can extract the profile-level-id
from the Sequence Parameter Set NAL Unit (if, in fact, the parameter sets are even being sent in the stream), it's the first 3 bytes after the NAL header. i.e. the first four bytes of the SPS NAL unit from a Baseline Profile stream with level 3.0 would look like this:
67
42
00
1E
Disregard the first byte, this just indicates that it is an SPS NAL Unit (0x67 & 0x1F == 0x7
SPS is NAL Type 7, PPS is NAL Type 8). The other 3 bytes give you the profile, constraint flags, and level (in fact, it's simply level times 10 in the 3rd byte).
sprop-parameter-sets
is the Base64 encoded Sequence Parameter Sets and Picture Parameter Sets, separated by commas. So just Base64 encode the SPS and PPS NAL Units (Nal type 7 and NAL type 8) and separate by comma and you should be good to go.
来源:https://stackoverflow.com/questions/12338594/can-profile-level-id-and-sprop-parameter-sets-be-extracted-from-an-rtp-stream