[rtsp]摄像头采集并进行264编码,用live555实现直播
[rtsp]摄像头采集并进行264编码,用live555实现直播
[rtsp]摄像头采集并进行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指示实际发送的内容是多少字节。这里暂时还是从文件读作为测试。
应用实例,本实例为基于web来播放监控摄像头画面的效果:
详细介绍参见:http://live.cuplayer.com/RtspCameraLive.html
web端无须装插件(支持PC,安卓,IOS苹果系统)效果1
web端无须装插件(支持PC,安卓,IOS苹果系统)效果2
web端无须装插件(支持PC,安卓,IOS苹果系统)效果3
热门文章推荐
- [rtsp]设置海康配置DDNS远程访问的用户手册(组图说明)
- [FFmpeg]FFmpeg实现监控摄像头的RTSP协议转RTMP协议直播
- [海康]海康网络摄像机激活功能图文教程
- [Rtsp]RTSP对实时摄像头视频流进行转换(FFmpeg+FFserver)
- [RTSP]海康家用摄像头wifi设置指南(组图说明)
- [Rtsp]海康网络摄像头基于RTSP协议的windows平台监控
- 海康客户端软件安装与使用教程ivms 4200(ivms 4200 客户端)图文
- [rtsp]IPC网络摄像头常见传输协议(rtsp协议,udp协议)介绍
请稍候...