ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

深入解析:SRS流媒体服务器二次开发-实现媒体流采集服务

深入解析:SRS流媒体服务器二次开发-实现媒体流采集服务

一 概述

        该文章是通过研究srs开源服务,在此基础上,实现一个简化的媒体流采集服务.媒体流可以是实时流,也可以是文件 .本质上该采集服务是使用ffmpeg命令将输入的媒体流,输出到rtmp服务器上。rtmp服务器可以是srs服务器或其它支持rtmp协议推流的媒体流服务器。

二 实现流程

        1. 定义一个配置文件 ;

采集实时流配置文件 :ingest.rtsp.conf   

vhost __defaultVhost__ {ingest {enabled      on;input {type    stream;url     rtsp://admin:admin12345@192.168.22.42:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif;}ffmpeg      /usr/local/ffmpeg/bin/ffmpeg;engine {enabled          on;perfile {rtsp_transport tcp;}vcodec copy;acodec copy;output          rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream;}}
}

    采集文件流配置文件 : ingest.conf

vhost __defaultVhost__ {ingest livestream {enabled      on;input {type    file;url     ./doc/source.200kbps.768x320.flv;}ffmpeg      /usr/local/ffmpeg/bin/ffmpeg;engine {enabled          off;output          rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream;}}
}

        2. 实现一个配置文件解析类;

        实现CustomConf.h CustomConf.cpp ,解析配置文件 ingest.conf和ingest.rtsp.conf ,实现对配置信息的获取,以便程序中使用.

        3. 实现一个采集服务类;

        实现IngestServer.cpp IngestServer.h ,该类实现的功能有:初始化,采集服务启动,采集服务停止 ,定时器功能.

        4. 参考srs中的采集流程实现服务.

三 自定义类实现

        1.配置文件解析类 CustomConf

CustomConf.h

#ifndef PARSECONF_CUSTOMCONF_H
#define PARSECONF_CUSTOMCONF_H
#include 
#include 
#include 
#include 
class CustomConf {
public:static CustomConf* getInstance();SrsCplxError *init(int argc, char *argv[]);
private:CustomConf();
private:static CustomConf* _instance;
};
#endif //PARSECONF_CUSTOMCONF_H

CustomConf.cpp

#include "CustomConf.h"
#include 
#inclu
返回列表