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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CHNIM/article/details/80705386

这里直接使用官方的例子接收的视频流,并通过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

展开阅读全文

没有更多推荐了,返回首页