Dump h264 raw data from LIVE555 client

Maybe lots persons encounter the same circumstances : after the succession of building LIVE555, and execute the testRTSPClient to connect a rtsp server: the debug log seems be pettey good; But when we damp the h264 data to be played by VLC or ffplay, that is unplayable. Of cource, if we deliver the h264 data to a h264 decoderdirectly, there would occur error always. I found there is not article be concise with complete code in the website, So i fill it.The code base on LIVE555\testProgs\testRTSPClient.cpp.modify the constructor and destructor of DummySink as below, it is about line 479:

pH264 = NULL;DummySinkstreamId) : MediaSink(env),fSubsession(subsession) { fStreamId = strDup(streamId); fReceiveBuffer [DUMMY_SINK_RECEIVE_BUFFER_SIZE]; pH264 )malloc();}DummySink::~DummySink() { delete[] fReceiveBuffer; delete[] fStreamId; if(NULL != pH264) free(pH264);}

And modify afterGettingFrame (the one with debug log ) as

void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,struct timeval presentationTime, unsigned /*durationInMicroseconds*/) {(fStreamId fStreamId ; envir() fSubsession.codecName() frameSize << " bytes"; numTruncatedBytes << " bytes truncated)"; ]; // used to output the ‘microseconds’ part of the presentation time sprintf(uSecsStr, "%06u", (unsigned)presentationTime.tv_usec); envir() (uSecsStr; fSubsession.rtpSource()->hasBeenSynchronizedUsingRTCP()) {envir() << "!"; // mark the debugging output to indicate that this presentation time is not RTCP-synchronized }#ifdef DEBUG_PRINT_NPT envir() fSubsession.getNormalPlayTime(presentationTime);#endif envir() ;#endif#else printf(, __FUNCTION__ ); if(0 == strncmp(fSubsession.codecName(), "H264", 16)) { unsigned char nalu_header[4] = { 0, 0, 0, 1 };unsigned char extraData[256]; ;SPropRecord *pSPropRecord; pSPropRecord = parseSPropParameterSets(fSubsession.fmtp_spropparametersets(), num);unsigned int extraLen; extraLen = 0; (; i < num; i++){memcpy(&extraData[extraLen], &nalu_header[0], 4); extraLen += 4; memcpy(&extraData[extraLen], pSPropRecord[i].sPropBytes, pSPropRecord[i].sPropLength); extraLen += pSPropRecord[i].sPropLength; }/*for i*/ memcpy(&extraData[extraLen], &nalu_header[0], 4); extraLen += 4; delete[] pSPropRecord ;memcpy(pH264, &extraData[0], extraLen); memcpy(pH264 + extraLen, fReceiveBuffer, frameSize);int totalSize; totalSize = extraLen + frameSize; fp = fopen("saved.h264", "wb"); fwrite(pH264, 1, totalSize, fp); fflush(fp); printf(, totalSize); }continuePlaying();}

That is, LIVE555 would omit the SPS/PPS information of each h264 slice.We need to fill SPS and PPS in the front. SPS,PPSand original data should be aparted by "0x00, 0x00, 0x00, 0x01".

,放弃那些不愿放弃的,容忍那些不可容忍的。

Dump h264 raw data from LIVE555 client

相关文章:

你感兴趣的文章:

标签云: