使用live555接受RTSP视频流并通过ffmpeg解码显示

这里直接使用官方的例子接收的视频流,并通过ffmpeg解码显示,如果直接把接受到的数据包,推给ffmpeg解码不成功,需要的接收到的数据进行处理再解码解码显示,具体做法如下:

	memset(decBuffer, 0, DUMMY_SINK_RECEIVE_BUFFER_SIZE);
	int nTotalLen = 0;
	unsigned char start_code[4] = { 0x00, 0x00, 0x00, 0x01 };
	if (strcmp(fSubsession.mediumName(), "video") == 0 && strcmp(fSubsession.codecName(), "H264") == 0)
	{

			if (firstFrame)
			{
				/*for (unsigned j = 0; j < 3; ++j)
				{*/
					unsigned numSPropRecords;
					//if (j == 0)
					//if (fReceiveBuffer[0] == 0x65 || fReceiveBuffer[0] == 0x25 || fReceiveBuffer[0] == 0x68 || fReceiveBuffer[0] == 0x67)
					{
						SPropRecord* sPropRecords = parseSPropParameterSets(fSubsession.fmtp_spropparametersets(), numSPropRecords);
						for (unsigned i = 0; i < numSPropRecords; ++i)
						{
							memcpy(decBuffer + nTotalLen, start_code, 4);
							nTotalLen += 4;
							memcpy(decBuffer + nTotalLen, sPropRecords[i].sPropBytes, sPropRecords[i].sPropLength);
							nTotalLen += sPropRecords[i].sPropLength;
							printf("mvp------XXXXXXXXXXXXXXXXXXXXXXXXXXX---------------%d\n", sPropRecords[i].sPropLength);
						}
						delete[] sPropRecords;
					}
			}
			memcpy(decBuffer + nTotalLen, start_code, 4);
			nTotalLen += 4;
			memcpy(decBuffer + nTotalLen, fReceiveBuffer, frameSize);
			nTotalLen += frameSize;
			printf("mvp=========================================%d\n", nTotalLen);
			H264_2_RGB(decBuffer, nTotalLen, RgbBuf, &RgbSize, &RgbWidth, &RgbHeight);
	}


完整源码路径:https://github.com/lcmftianci/live555_Rtsp_vs2015/tree/master/RtspClient

加QQ群一起交流学习音视频开发:476513431

你可能感兴趣的:(C++探究,OpenCV,图片合成)