码迷,mamicode.com
首页 > 其他好文 > 详细

流媒体平台搭建

时间:2016-08-11 23:17:29      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:rtsp   流媒体平台   

1       目标

希望建设一个流媒体平台(类似音乐平台),通过流媒体平台维护相关流媒体资源。

2       主要功能要求

         主要功能可以包括:流媒体内容维护(信息维护、流媒体文件上传等)、支持RTSP(Real-Time Streaming Protocol,实时流媒体协议)和RTP/RTCP(Real-Time TranCPort Protocol/RTP Control Protocol,实时传输协议/RTP控制协议)进行流媒体播放。DSS给出的性能参数为:默认1000用户同时在线,可以修改为最高9999,前提是带宽足够大。

3       设计实现方案

         由于部门没有类似的项目建设案例,项目组人员不能掌握流媒体技术。要想在工期内完成项目的建设工作。通过互联网搜索。找到一款开源流媒体平台项目Darwin Streaming Server。通过对DSS相关功能的二次开发,利用其串流播放能力。根据DSS项目给出的性能指标满足需求文档中的要求(未通过LR验证)。

3.1     DSS开源产品介绍

         Darwin Streaming Server简称DSS。DSS是Apple公司提供的开源实时流媒体播放服务器程序。整个程序使用C++编写,在设计上遵循高性能,简单,模块化等程序设计原则,务求做到程序高效,可扩充性好。并且DSS是一个开放源代码的,基于标准的流媒体服务器,可以运行在Windows NT和Windows 2000,以及几个UNIX实现上,包括Mac OS X,Linux,FreeBSD,和Solaris操作系统上的。Darwin Streaming Server,提供音乐 (mp3) 与影音 (3gp、mp4、mov) 串流播放功能。

         较为详细的功能介绍参见:

    http://hi.baidu.com/dmkj2008/item/a2085a30e0738e80c3cf2956

         转发功能:如果服务器压力较大或功能扩展,可以使用DSS Relay功能,视压力测试结果而定。

         参考资源:

http://www.jsjyedu.cn/zxlw/48254_2.html

http://www.jtben.com/document/1120414

3.2     DSS搭建

2.1  安装命令

tar zxf DarwinStreamingSrvr5.5.5-Linux.tar.gz

cd DarwinStreamingSrvrlinux-Linux

./Install

Please enter a new administrator user name: admin

Please enter a new administrator Password: your_password

2.2  查看是否安装成功

id qtss

uid=501(qtss)  gid=502(qtss)  groups=502(qtss)

ps aux | grep Darwin

root ... ... ... /usr/local/sbin/DarwinStreamingServer

qtss ... ... ... /usr/local/sbin/DarwinStreamingServer

netstat -ntulp | grep Darwin

tcp 0.0.0.0:8001

tcp 0.0.0.0:554

tcp 0.0.0.0:7070

udp 127.0.0.1:6970

udp 192.168.0.1:6970

udp 127.0.0.1:6971

udp 192.168.0.1:6971

udp 127.0.0.1:6976

udp 127.0.0.1:6977

udp 127.0.0.1:6978

udp 127.0.0.1:6979

2.3  启动命令

启动服务(安装已经启动,不需要再启动)

启动 Darwin Streaming Server

/usr/local/sbin/DarwinStreamingServer

启动 Web 管理接口 (tcp port 1220) (安装已经启动,不需要再启动)

/usr/local/sbin/streamingadminserver.pl

2.4  关闭命令

Kill -9 Darwin Streaming Server进程

2.5 error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

 

建议:在/etc/ld.so.conf.d/上新建动态库相应的文件配置文件*.conf, 

在该文件中填上该动态库的绝对路径 

此例: 

vim /etc/ld.so.conf.d/ld.Darwin.so.conf 

/usr/local/lib

同时copy libstdc++.so.6 到/usr/local/lib

 

运行:ldconfig /etc/ld.so.cache

3          管理界面配置3.1  连入管理接口进行设定

开启浏览器, 连入 http://darwin.streaming.server:1220/

第一次进入管理接口, 需进行以下设置:

MP3 Broadcast Password: 设定 MP3 广播密码

Secure Administration: Web 管理接口是否启用 SSL 安全联机 (视需求,本次设置为否)

Media Folder: 设定多媒体文件存放路径 (默认 /usr/local/movies,本次设置为默认,如若修改路径不会对目标目录产生影响)

Streaming on Port 80: 是否以 80 port 传送串流数据 (视需求,本次设置为否)

 

以上,DSS搭建完成。

3.3     音频编码

3.3.1  软件安装

3.3.1.1 Acc声音编码

tar xvfz faac-1.28.tar.gz

cd faac-1.28

./configure --prefix=/usr/local --enable-shared  --without-mp4v2

Make

FAQ:

make 时报错

if g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include   -Wall -g -O2 -MT 3gp.o -MD -MP -MF ".deps/3gp.Tpo" -c -o 3gp.o 3gp.cpp; \

 then mv -f ".deps/3gp.Tpo" ".deps/3gp.Po"; else rm -f ".deps/3gp.Tpo"; exit 1; fi

mpeg4ip.h:126: error: new declaration ?.onst char* strcasestr(const char*, const char*)?

vim +126 common/mp4v2/mpeg4ip.h

将此行删除,保存退出

char *strcasestr(const char *haystack, const char *needle); 

make clean

 

 

make install

 

3.3.1.2 amr_nb声音编码

tar xvf amrnb-7.0.0.2.tar.bz2

cd amrnb-7.0.0.2

./configure --prefix=/usr/local --enable-shared

make

make install

由于网络问题安装不上,请跳过此步骤。

3.3.1.3 ffmpeg

    1、tar xvfj ffmpeg-0.4.9-p20051120.tar.bz2

  得到解压后的目录是ffmpeg-0.4.9-p20051120,名字太长,利用mv命令改为ffmpeg

mv ffmpeg-0.4.9-p20051120 ffmpeg

cd ffmpeg/libavcodec

mkdir amr_float   同时将解压26104-700.zip的叶子文件cp到 amr_float中

执行:

     declare -x    LD_LIBRARY_PATH="/usr/local/lib:/u01/software/stream/faac-1.28:/u01/software/stream/amr  nb-7.0.0.2"    

 

  2、配置

./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-faac --enable-amr_nb --disable-ffplay

  其中:--enable-shared 是允许其编译产生动态库,在以后的编程中要用到这个几个动态库。--prefix设置的安装目录。

 

  3、编译并安装

  make

  make install

  4、安装之后在/usr/local/ffmpeg会看到有三个目录

  lib 动态链接库位置

  include 编程要用到头文件

  bin 执行文件所在的目录

  5、为了以后方便编程,我们把lib中的三个链接库libavcodec.so libavformat.so libavutil.so复制到/usr/lib下。把include目录下的ffmpeg目录复制到/usr/include下。

    6、ln -s  /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg

    7、 vi /etc/ld.so.conf  添加/usr/local/lib

        保存后,执行 ldconfig

3.3.1.4 安装音频流化软件

音频流化作用如下:

Hint tracks are a series of instructions in a mp4 container file that
tell a server how to transmit packets. Hint tracks always refer
to another track, most likely an audio or video media track.  

This series of instructions tells the server when to send the packet, 
what type of RTP header to add, if there is any extra data in the
packet, and how much data to send in the packet.  To save on space, 
a hint can contain a pointer to the media track, instead of duplicating
that data.

安装流程:

 

tar  xvfz mpeg4ip-1.6.1.tar.gz

cd mpeg4ip-1.6.1

 

./bootstrap --prefix=/usr/local/mpeg4ip --enable-ffmpeg=/usr/local/ffmpeg --disable-player --disable-server

如果报错如下:util/testnasm.sh: line 8: test: =: unary operator expected

Please:

Check for the following text in the "configure" file:

BILLSNASM_arg=`nasm -r | tr ‘.‘ ‘ ‘`

and replace the -r with -v

Save and run bootstrap again.

make

 

报错如:t char* strcasestr(const char*, const char*

操作:

vim +126  include /mpeg4ip.h

 

make install

添加默认命令

[root@localhost ~]# cd /usr/bin/

[root@localhost bin]# ln -s /usr/local/mp

 [root@localhost bin]# ln -s /usr/local/mpeg4ip/bin/mp4info /usr/bin//mp4info

 

 

tar zxvf gpac-0.5.0.tar.gz

tar zxvf gpac_extra_libs-0.4.5.tar.gz

cd gpac

cp -r ../gpac_extra_libs/* extra_lib/

chmod +x configure

./configure

make

make lib

make apps

make install

whereis MP4Box

添加默认命令

[root@localhost bin]# cd /usr/bin

[root@localhost bin]# ln -s /usr/local/bin/MP4Box MP4Box

[root@localhost bin]# ll M*

Mail    MP4Box 

[root@localhost bin]# ll MP4Box

lrwxrwxrwx. 1 root root 26  3月 27 17:04 MP4Box -> /usr/local/gpac/bin/MP4Box

[root@localhost bin]# cd /home/tapapp/DarwinStreamingSrvrlinux-Linux/

[root@localhost DarwinStreamingSrvrlinux-Linux]# MP4Box -hint outfile.mp4

Hinting file with Path-MTU 1450 Bytes

Hinting track ID 1 - Type "mp4a:mp4a" (mpeg4-generic) - BW 56 kbps

Saving outfile.mp4: 0.500 secs Interleaving   

[root@localhost DarwinStreamingSrvrlinux-Linux]# mp4info outfile.mp4

./mp4info version 2.0.0

/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4:

ReadAtom: "/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4": atom type 〆nc is suspect

Track   Type    Info

1       audio   MPEG-4 AAC LC, 88.960 secs, 0 kbps, 8000 Hz

65536   hint    Payload (null) for track 1

ReadAtom: "/home/tapapp/DarwinStreamingSrvrlinux-Linux/outfile.mp4": atom type 〆nc is suspect

 

 

说明:对于一些特殊的文件,先ffmpeg -i xxx.mp4 -vcodec copy -acodec copy xxx_new.mp4然后在执行MP4Box -hint xxx_new.mp4

3.3.2   Mp3格式音频转码

转成音频编码为aac的mp4格式文件

ffmpeg -i sample.mp3 -acodec aac -ac 2 -ar 8000 -ab 96 -vol 200 outfile.mp4

转成音频编码为amr_nb的mp4格式文件

ffmpeg -i sample.mp3 -ac 1 -acodec amr_nb -ar 8000 -ab 96 -vol 200 test_amr.mp4

 

具体操作流程:

 技术分享

 

3.3.3   VLC生成sdp文件

vlc -vvv sample_100kbit.mp4 --sout ‘#rtp{dst=10.4.121.194, msx=ts, port=1234, sdp=rtsp://10.4.121.194:554/test.sdp}‘

3.4     音频文件存储

按照linux文件目录存储:

$DSS_HOME/音频编码格式(amr,acc)/音频分类编码1(文史、搞笑等)/音频分类二级编码(诗词散文、国外名著等)/书籍名称编码/产品包(可选)/音频文件.mp4

样例:$DSS_HOME /acc/1001/1001001/01/01.mp4

缺点:不支持中文

3.5      RTSP服务控制

         存在问题!

  已经通过socket转发方式处理

3.6     性能测试

3.6.1  StreamingLoadTool

命令:./ StreamingLoadTool –n203

自带测试工具,用户达到203后,测试命令报错。

PS:-u 命令不好用,必须修改streamingloadtool.conf  的url

 

 

3.6.2  Live555

安装live555 使用其工具rstpCLIENT 测试性能。

  ./genMakefiles           linux

    make

   make install

调用压力工具脚本./test2.sh 1000    test2为无提示成功脚本  较快。可以通过DSS平台查看

                ./test1.sh 1000   test1 每2秒执行一次,较慢,有提示成功失败。

3.6.3  LR测试

未测试。

可用的播放地址:

rtsp://10.4.121.56/sample_300kbit.mp4

 

本文出自 “呼吸雨后泥土的味” 博客,请务必保留此出处http://tongl.blog.51cto.com/4470985/1836864

流媒体平台搭建

标签:rtsp   流媒体平台   

原文地址:http://tongl.blog.51cto.com/4470985/1836864

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!