How to decode sprop-parameter-sets in a H264 SDP?
What is the meaning of Base64 decoded bytes in sprop-parameter-sets in SDP for a h264 stream? How can I know the video size from this example?
SDP example:
sprop-parameter-sets=Z0IAKeNQFAe2AtwEBAaQeJEV,开发者_运维技巧aM48gA==
First part decoded from Base64 to Base16:
67 42 00 29 E3 50 14 07 B6 02 DC 04 04 06 90 78 91 15
Second part (comma separated):
68 CE 3C 80
ANSWER: Fetching the dimensions of a H264Video stream
The spec you require is available for free download from the ITU website here:- H.264 (03/10)
Select the freely downloadable PDF and you'll find the format detailed in section 7.3.2.1.1.
Sorry, wasn't being obtuse with my previous answer, just didn't know that the information was available in the public domain.
Of course the spec is always best, but the sprop-parameter-sets in the SDP generally consist of your sequence parameter and picture parameter sets, base-64 encoded and delimited by a comma. The sequence parameter and picture parameter sets basically tell the decoder how to properly decoding the incoming H264 stream; without it you cannot decode correctly.
Writing a parser for SPS/PPS isn't that hard, although to do this you will absolutely need the specification. You'll also need to have a good bit-reader class and knowledge of how exponential golomb encoding works for both signed and unsigned values. See here and here.
Lastly, the code found in this thread on Doom9 was invaluable to me--it's basically a full parser for an elementary H264 stream. It includes a bit reader class, routines to parse NALU, sps, pps, VUI parameters, sequence scaling matrices, etc. It's a pretty handy piece of code for any video engineer.
As it turns out, the answer to my question is written in this document: ISO/IEC 14496-10:2005, under section 7.3.2.1. And to get it I need to pay. So... =)
The video size is in the "framesize" line of SDP, isn't it ?
00028 int av_strstart(const char *str, const char *pfx, const char **ptr)
00029 {
00030 while (*pfx && *pfx == *str) {
00031 pfx++;
00032 str++;
00033 }
00034 if (!*pfx && ptr)
00035 *ptr = str;
00036 return !*pfx;
00037 }
00038
p is a pointer of your line SDP
if (av_strstart(p, "framesize:", &p)) {
00370 char buf1[50];
00371 char *dst = buf1;
00372
00373 // remove the protocol identifier..
00374 while (*p && *p == ' ') p++; // strip spaces.
00375 while (*p && *p != ' ') p++; // eat protocol identifier
00376 while (*p && *p == ' ') p++; // strip trailing spaces.
00377 while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1) {
00378 *dst++ = *p++;
00379 }
00380 *dst = '\0';
00381
00382 // a='framesize:96 320-240'
00383 // set our parameters..
00384 codec->width = atoi(buf1);
00385 codec->height = atoi(p + 1); // skip the -
00386 codec->pix_fmt = PIX_FMT_YUV420P;
}
reference : http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/rtpdec__h264_8c-source.html#l00360
精彩评论