Streaming live H264 video from DM368

来源:互联网 发布:央视网络春晚策划方案 编辑:程序博客网 时间:2024/06/05 10:54

Appro already got a reference design on how to stream livevideo, but it's based on Appro's own framework. For people like mewho want to use DVSDK4, it's not very helpful. The Appro designalso used WIS-Streamer, which is not really necessary.

 

To build a simple live h264 streaming RTSP server, this is allyou need:

1. Download latest live555 source code. Modify config.armlinux,so that its CC options point to the compiler you use, run"./genMakefiles armlinux"

2. Modify testH264VideoStreamer.cpp

#include <liveMedia.hh>#include<BasicUsageEnvironment.hh>#include <GroupsockHelper.hh>#include<H264VideoFileServerMediaSubsession.hh>H264VideoStreamFramer* videoSource;int main(int argc, char** argv) {RTPSink* videoSink;char *inputFileName = argc>1?argv[1]: (char*)"live.264";// Begin by setting up our usageenvironment:TaskScheduler* scheduler =BasicTaskScheduler::createNew();UsageEnvironment*env =BasicUsageEnvironment::createNew(*scheduler);// Create 'groupsocks' for RTP andRTCP:struct in_addr destinationAddress;destinationAddress.s_addr =chooseRandomIPv4SSMAddress(*env);const unsigned short rtpPortNum =18888;const unsigned short rtcpPortNum =rtpPortNum+1;const unsigned char ttl = 255;const Port rtpPort(rtpPortNum);const Port rtcpPort(rtcpPortNum);Groupsock rtpGroupsock(*env,destinationAddress, rtpPort, ttl);rtpGroupsock.multicastSendOnly();Groupsock rtcpGroupsock(*env,destinationAddress, rtcpPort, ttl);rtcpGroupsock.multicastSendOnly();// Create a 'H264 Video RTP' sink from theRTP 'groupsock':OutPacketBuffer::maxSize =1<<17;videoSink = H264VideoRTPSink::createNew(*env,&rtpGroupsock, 96);RTSPServer* rtspServer =RTSPServer::createNew(*env, 8554);if (rtspServer == NULL) {*env<< "Failed to create RTSP server: "<< env->getResultMsg()<< "\n";exit(1);}ServerMediaSession* sms =ServerMediaSession::createNew(*env, "live", "live stream","Session streamed by "live264Streamer"", True );sms->addSubsession(H264VideoFileServerMediaSubsession::createNew(*env,inputFileName,True));rtspServer->addServerMediaSession(sms);char* url =rtspServer->rtspURL(sms);*env << "Play thisstream using the URL "" << url<< ""\n";delete[] url;env->taskScheduler().doEventLoop(); // does notreturnreturn 0; // only to prevent compilerwarning}void afterPlaying(void* ) {Medium::close(videoSource);}
3. create a named pipe: mkfifo live.264

4. Redirect your output stream to live.264, if your code isbased on the encode demo, change writer.c


转自:http://blog.sina.com.cn/s/blog_5e330a280100r88v.html