linux live555编译以及rtsp服务器搭建

一、live555源码

下载:点击跳转

二、编译

1、往文件 config.linux 里的 COMPILE_OPTS 添加以下两个参数 -DNO_STD_LIB-DNO_OPENSSL=1,修改后如下:

COMPILE_OPTS =		$(INCLUDES) -I/usr/local/include -I.  -O2 -DNO_STD_LIB -DNO_OPENSSL=1 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
C =			c
C_COMPILER =		cc
C_FLAGS =		$(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS)
CPP =			cpp
CPLUSPLUS_COMPILER =	c++
CPLUSPLUS_FLAGS =	$(COMPILE_OPTS) -Wall -DBSD=1 $(CPPFLAGS) $(CXXFLAGS)
OBJ =			o
LINK =			c++ -o
LINK_OPTS =		-L. $(LDFLAGS)
CONSOLE_LINK_OPTS =	$(LINK_OPTS)
LIBRARY_LINK =		ar cr 
LIBRARY_LINK_OPTS =	
LIB_SUFFIX =			a
LIBS_FOR_CONSOLE_APPLICATION = -lssl -lcrypto
LIBS_FOR_GUI_APPLICATION =
EXE =

2、分别执行以下命令

./genMakefiles linux
make clean
make -j8
mkdir build
make install PREFIX=$PWD/build


/***************************
以下用于交叉编译的,若是交叉编译不用输入上面的命令
****************************/
//创建脚本文件,并输入以下信息
#!/bin/bash

LIVE555_DIR=`pwd`

cd $LIVE555_DIR

INSTALL_DIR=$LIVE555_DIR/build
mkdir -p $INSTALL_DIR

#编译成静态库
export LDFLAGS="-static"

#声明交叉编译器的路径
#export PATH=/opt/arm-gcc/bin/:$PATH

./genMakefiles armlinux
make -j$(nproc) CROSS_COMPILE=aarch64-linux-gnu-

make install PREFIX=$INSTALL_DIR CROSS_COMPILE=aarch64-linux-gnu-

三、搭建rtsp服务器

1、利用qt creator创建工程,在 *.pro 文件添加 live555 头文件的路径(注意库的顺序)

INCLUDEPATH *= /home/gui/live/build/include/liveMedia/
INCLUDEPATH *= /home/gui/live/build/include/BasicUsageEnvironment/
INCLUDEPATH *= /home/gui/live/build/include/groupsock
INCLUDEPATH *= /home/gui/live/build/include/UsageEnvironment/

LIBS += -L/home/gui/live/build/lib/ -lliveMedia \
         -lBasicUsageEnvironment -lgroupsock -lUsageEnvironment

2、服务器代码实现如下(参考源码的testOnDemandRTSPServer.cpp文件例程):

#include <QCoreApplication>

#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#include "InputFile.hh"
#include "BasicHashTable.hh"
#include <GroupsockHelper.hh>
#include <iostream>

static void announceURL(RTSPServer* rtspServer, ServerMediaSession* sms) {
  if (rtspServer == NULL || sms == NULL) return; // sanity check
  UsageEnvironment& env = rtspServer->envir();
  env << "Play this stream using the URL ";
  if (weHaveAnIPv4Address(env)) {
    char* url = rtspServer->ipv4rtspURL(sms);
    env << "\"" << url << "\"";
    delete[] url;
    if (weHaveAnIPv6Address(env)) env << " or ";
  }
  if (weHaveAnIPv6Address(env)) {
    char* url = rtspServer->ipv6rtspURL(sms);
    env << "\"" << url << "\"";
    delete[] url;
  }
  env << "\n";
}

static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
               char const* streamName, char const* inputFileName)
{
  UsageEnvironment& env = rtspServer->envir();

  env << "\n\"" << streamName << "\" stream, from the file \""
      << inputFileName << "\"\n";
  announceURL(rtspServer, sms);
}



int main(int argc, char *argv[])
{
    // Begin by setting up our usage environment:
    TaskScheduler* scheduler = BasicTaskScheduler::createNew();
    UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
    //设置RTP数据的最大传输大小
    OutPacketBuffer::maxSize = 1000000;
    //创建一个rtsp的服务
    RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554);
    if (rtspServer == NULL) {
    *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
    exit(1);
    }

    char const* descriptionString
    = "Session streamed by \"LiveRTSPServer\"";

    Boolean reuseFirstSource = true;
    // A H.264 video elementary stream:
    {
        char const* streamName = "h264ESVideoTest";
        char const* inputFileName = "test.264";//hevc

        //创建一个会话
        ServerMediaSession* sms
          = ServerMediaSession::createNew(*env, streamName, streamName,
                          descriptionString);
        //管理之前,需要先注册一个实例,实现里边所有的管理function,将来给rtsp服务调度。
        sms->addSubsession(H264VideoFileServerMediaSubsession
                   ::createNew(*env, inputFileName, reuseFirstSource));
        rtspServer->addServerMediaSession(sms);
        //将ServerMediaSession添加到rstp服务
        announceStream(rtspServer, sms, streamName, inputFileName);

    }

    // A MPEG-1 or 2 audio+video program stream:
      {
        char const* streamName = "mpeg1or2AudioVideoTest";
        char const* inputFileName = "test.mpg";
        // NOTE: This *must* be a Program Stream; not an Elementary Stream
        ServerMediaSession* sms
          = ServerMediaSession::createNew(*env, streamName, streamName,
                          descriptionString);
        MPEG1or2FileServerDemux* demux
          = MPEG1or2FileServerDemux::createNew(*env, inputFileName, reuseFirstSource);
        sms->addSubsession(demux->newVideoServerMediaSubsession(false));
        sms->addSubsession(demux->newAudioServerMediaSubsession());
        rtspServer->addServerMediaSession(sms);

        announceStream(rtspServer, sms, streamName, inputFileName);
      }

    //开始运行服务
    env->taskScheduler().doEventLoop(); // does not return

    return 0;

}

通过ffplay播放,测试效果如下:

demo下载:点击跳转

创作不易,打赏一下呗。。

相关推荐
freeabc16 天前
利用 OBS 推送 WEBRTC 流到 smart rtmpd
服务器·webrtc·rtmp·rtsp·sfu·whip/whep
从后端到QT25 天前
RTSP 音视频play同步分析
网络·rtp·rtsp
橘色的喵1 个月前
RtspServer:轻量级RTSP服务器和推流器
视频·推流·rtp·rtsp·rtspserver·xop
xiejiashu2 个月前
亲测有效,长期有效的RTSP流地址公网RTSP地址,各种类型的视频源
rtsp·live555·easyrtspserver·公网rtsp地址·rtsp公网地址
superconvert2 个月前
主流流媒体的综合性能大 PK ( smart_rtmpd, srs, zlm, nginx rtmp )
websocket·ffmpeg·webrtc·hevc·rtmp·h264·hls·dash·rtsp·srt·flv
DogDaoDao2 个月前
音视频开发常见的开源项目汇总
ffmpeg·开源·音视频·webrtc·x264·live555·obs
EasyCVR2 个月前
视频技术未来展望:EasyCVR如何引领汇聚融合平台新趋势
人工智能·tcp/ip·音视频·rtsp·gb28181
千里马学框架2 个月前
live555编译运行笔记
android·笔记·车载系统·rtsp·live555·系统工程师
EasyCVR2 个月前
安防视频汇聚平台EasyCVR启动后无法访问登录页面是什么原因?
人工智能·音视频·rtsp·gb28181
牙膏上的小苏打23332 个月前
Unity视频播放插件-VideoPro(Windows)
windows·unity·音视频·rtsp