[Live555]监控摄像头采集264编码用live555做直播
[Live555]监控摄像头采集264编码用live555做直播
- H264FramedLiveSource.hh
- /*
- * Filename: H264FramedLiveSource.hh
- * Auther: chenbin
- * Create date: 2013/ 1/22
- */
- #ifndef _H264FRAMEDLIVESOURCE_HH
- #define _H264FRAMEDLIVESOURCE_HH
- #include <FramedSource.hh>
- class H264FramedLiveSource : public FramedSource
- {
- public:
- static H264FramedLiveSource* createNew(UsageEnvironment& env,
- char const* fileName,
- unsigned preferredFrameSize = 0,
- unsigned playTimePerFrame = 0);
- protected:
- H264FramedLiveSource(UsageEnvironment& env,
- char const* fileName,
- unsigned preferredFrameSize,
- unsigned playTimePerFrame);
- // called only by createNew()
- ~H264FramedLiveSource();
- private:
- // redefined virtual functions:
- virtual void doGetNextFrame();
- int TransportData( unsigned char* to, unsigned maxSize );
- protected:
- FILE *fp;
- };
- #endif
- H264FramedLiveSource.cpp
- /*
- * Filename: H264FramedLiveSource.cpp
- * Auther: mlj
- * Create date: 2013/ 1/22
- */
- #include "H264FramedLiveSource.hh"
- H264FramedLiveSource::H264FramedLiveSource( UsageEnvironment& env,
- char const* fileName,
- unsigned preferredFrameSize,
- unsigned playTimePerFrame )
- : FramedSource(env)
- {
- fp = fopen( fileName, "rb" );
- }
- H264FramedLiveSource* H264FramedLiveSource::createNew( UsageEnvironment& env,
- char const* fileName,
- unsigned preferredFrameSize /*= 0*/,
- unsigned playTimePerFrame /*= 0*/ )
- {
- H264FramedLiveSource* newnewSource = new H264FramedLiveSource(env, fileName, preferredFrameSize, playTimePerFrame);
- return newSource;
- }
- H264FramedLiveSource::~H264FramedLiveSource()
- {
- fclose(fp);
- }
- long filesize(FILE *stream)
- {
- long curpos, length;
- curpos = ftell(stream);
- fseek(stream, 0L, SEEK_END);
- length = ftell(stream);
- fseek(stream, curpos, SEEK_SET);
- return length;
- }
- void H264FramedLiveSource::doGetNextFrame()
- {
- if( filesize(fp) > fMaxSize)
- fFrameSize = fread(fTo,1,fMaxSize,fp);
- else
- {
- fFrameSize = fread(fTo,1,filesize(fp),fp);
- fseek(fp, 0, SEEK_SET);
- }
- //fFrameSize = fMaxSize;
- nextTask() = envir().taskScheduler().scheduleDelayedTask( 0,
- (TaskFunc*)FramedSource::afterGetting, this);//表示延迟0秒后再执行 afterGetting 函数
- return;
- }
在 H264FramedLiveSource::doGetNextFrame() 中,将要发送的内容复制到 fTo,最大为fMaxSize,fFrameSize指示实际发送的内容是多少字节。这里暂时还是从文件读作为测试。
- H264LiveVideoServerMediaSubssion.hh
- /*
- * Filename: H264LiveVideoServerMediaSubssion.hh
- * Auther: mlj
- * Create date: 2013/ 1/22
- */
- #ifndef _H264_LIVE_VIDEO_SERVER_MEDIA_SUBSESSION_HH
- #define _H264_LIVE_VIDEO_SERVER_MEDIA_SUBSESSION_HH
- #include "H264VideoFileServerMediaSubsession.hh"
- class H264LiveVideoServerMediaSubssion: public H264VideoFileServerMediaSubsession {
- public:
- static H264LiveVideoServerMediaSubssion*
- createNew( UsageEnvironment& env,
- char const* fileName,
- Boolean reuseFirstSource );
- protected: // we're a virtual base class
- H264LiveVideoServerMediaSubssion( UsageEnvironment& env, char const* fileName, Boolean reuseFirstSource );
- ~H264LiveVideoServerMediaSubssion();
- protected: // redefined virtual functions
- FramedSource* createNewStreamSource(unsigned clientSessionId,
- unsigned& estBitrate);
- public:
- char fFileName[100];
- };
- #endif
使用 ffplay.exe rtsp://115.156.164.19:8554/h264ESVideoTest 可以播放test.264的视频.
相关配置:live555的四个库放在lib文件夹下。
库目录:G:\workspace\avs\live555test\live555test\lib
包含目录:G:\workspace\avs\live555test\live555test\BasicUsageEnvironment \include;G:\workspace\avs\live555test\live555test\UsageEnvironment\include;G:\workspace\avs\live555test\live555test\liveMedia\include;G:\workspace\avs\live555test\live555test\groupsock\include
源代码 :
热门文章推荐
- [live555]live555直播rtsp流
- [live555]Live555学习资料及下载
- [live555]rtsp直播基于live555的实现
- [rtsp]海康Hikvision Tools(SADP搜索摄像头工具)下载
- [Live555]live555中处理mpeg4
- [NVR]海康网络摄像机录像时间怎么自定义设置
- [RTSP]RTSP常用方法实例
- [udp]为什么视频数据一般都用UDP协议进行传输