怎么在 Linux 下运行 smart_rtmpd

怎么在 Linux 下运行 smart_rtmpd

操作系统的准备

我们知道比较流行的 Linux 操作系统基本上分为两类,一类是以 Redhat 为基线的 Redhat, CentOS;另一类是 Debian 为基线的 Debian,Ubuntu。当然现在还有一些新兴势力 Arch Linux,但大家都是基于 Linux 内核进行封装运作的。主要表现是包管理器不同,面向的用户场景不同,有的往桌面方面发展,有的往嵌入式方向发展。这些系统大家可以根据自己的喜好进行选择,本文不做过多阐述,差异不大。建议大家采用操作系统最新版本,这样系统性能更好,功能更强大,兼容性更好,性能也是最佳。

smart_rtmpd 服务器软件的准备

  1. 软件的下载
    访问 https://github.com/superconvert/smart_rtmpd , 下载 https://github.com/superconvert/smart_rtmpd/blob/master/rtmpd.ziphttps://github.com/superconvert/smart_rtmpd/releases
    访问 https://gitee.com/superconvert/smart_rtmpd , 下载 https://gitee.com/superconvert/smart_rtmpd/blob/master/rtmpd.zip

  2. 软件包的介绍
    下载的软件包 rtmpd.zip 里面包含不同平台的安装运行包

    smart_rtmpd.coroutines.centos7.7.1908.x64.tar.gz        CentOS 系统的协程版本 (x64)
    smart_rtmpd.multithread.centos7.7.1908.x64.tar.gz       CentOS 系统的多线程版本 (x64) --- 推荐
    smart_rtmpd.coroutines.ubuntu16.04LTS.x64.tar.gz        Ubuntu 系统的协程版本 (x64)
    smart_rtmpd.multithread.ubuntu16.04LTS.x64.tar.gz       Ubuntu 系统的多线程版本 (x64)
    smart_rtmpd.multithread.generic.aarch64.tar.gz          ARM-v8 架构的多线程版本 (arm)
    
  3. 软件包的准备
    我们下载 rtmpd.zip 后进行解压,把 smart_rtmpd.multithread.centos7.7.1908.x64.tar.gz 上传到我们的 Linux 操作系统内,进行解压

    [root@localhost ~]# mkdir smart_rtmpd
    [root@localhost ~]# tar zxvf smart_rtmpd.multithread.centos7.7.1908.x64.tar.gz -C smart_rtmpd
    [root@localhost ~]# cd smart_rtmpd
    [root@localhost smart_rtmpd]# ls -alh
    total 8.0M
    drwxr-xr-x. 3 root root  167 Aug 15 05:34 .
    drwxr-xr-x. 4 root root   28 Aug 15 05:34 ..
    -rw-r--r--. 1 root root 9.7K Aug 14 18:12 config.xml
    -rw-r--r--. 1 root root  378 Jul 23 12:24 gb28181.xml
    drwxr-xr-x. 4 root root  100 Aug 15 03:43 html
    -rw-r--r--. 1 root root  234 Aug 17  2021 ice_server.json
    -rw-r--r--. 1 root root  173 Feb 17  2023 mime.xml
    -rw-r--r--. 1 root root 2.8K Jul  4  2021 policy.xml
    -rw-r--r--. 1 root root 1.6K Aug  9  2021 server.crt
    -rw-r--r--. 1 root root 1.7K Aug  9  2021 server.key
    -rwxr-xr-x. 1 root root 8.0M Aug 15 04:08 smart_rtmpd    // 确保 smart_rtmpd 是可执行的
    

    为什么选用 smart_rtmpd.multithread.centos7.7.1908.x64.tar.gz 版本,这个应该是通用版本,应该适用用大部分 Linux 系统,无论是 CentOS, Ubuntun, Arch Linux

  4. 运行 smart_rtmpd
    我们准备运行 smart_rtmpd 流媒体服务器

    问题1 :smart_rtmpd 没有可执行权限,通过 chmod 赋权
    [root@localhost smart_rtmpd]# ./smart_rtmpd
    -bash: ./smart_rtmpd: Permission denied                 // 大部分这种情况是 smart_rtmpd 拷贝复制过程中丢失了可执行权限
    [root@localhost smart_rtmpd]# chmod +x ./smart_rtmpd
    
    问题2 :端口被其它程序占用,需要通过 config.xml 更改端口,或者停止其它的程序
    [root@localhost bin]# ./smart_rtmpd 
    EAB7D740 [24-12-31 14:15:02.161] I: smart_rtmpd --- build time : 2024-08-15 04:06:58
    EAB7D740 [24-12-31 14:15:02.161] I: website url : http://www.qiyicc.com/download/rtmpd.zip
    EAB7D740 [24-12-31 14:15:02.161] I: gitee url : https://gitee.com/mirrors/smart-rtmpd
    EAB7D740 [24-12-31 14:15:02.161] I: github url : https://github.com/superconvert/smart_rtmpd
    EAB7D740 [24-12-31 14:15:02.161] I: liveshow url : https://github.com/superconvert/smart_rtmpd/blob/master/liveshow.md
    EAB7D740 [24-12-31 14:15:02.161] I: development url : https://github.com/superconvert/smart_rtmpd/blob/master/web_dev.md
    EAB7D740 [24-12-31 14:15:02.161] I: examples url : https://github.com/superconvert/smart_rtmpd/tree/master/example
    EAB7D740 [24-12-31 14:15:02.161] I: email : cwf12345@sina.com
    EAB7D740 [24-12-31 14:15:02.161] I: webchat : 99766553, qq : 99766553
    EAB7D740 [24-12-31 14:15:02.161] I: 192.168.161.136 ens33
    EAB7D740 [24-12-31 14:15:02.221] I: ssl client no config.
    EAB7D740 [24-12-31 14:15:02.221] I: ssl server no config.
    EAB7D740 [24-12-31 14:15:02.306] I: the rtmp server ip: 0.0.0.0, port is: 1935
    EAB7D740 [24-12-31 14:15:04.101] I: the http server ip: 0.0.0.0, port is: 8080
    generating new self-signed cert for smart_rtmpd@qiyicc.com
    EAB7D740 [24-12-31 14:15:04.125] I: rtc-manager build self-signed certificate.
    EAB7D740 [24-12-31 14:15:04.125] I: the rtsp server ip: 0.0.0.0, port is: 8554
    EAB7D740 [24-12-31 14:15:04.345] I: the srt server ip: 0.0.0.0, port is: 9000
    EAB7D740 [24-12-31 14:15:04.346] I: srt bind socket failed(Connection setup failure: unable to create/configure SRT socket)  // 端口被别的程序占用了
    EAB7D740 [24-12-31 14:15:04.346] I: srt bind socket failed.
    EAB7D740 [24-12-31 14:15:04.449] I: the rtmp server stop
    EAB7D740 [24-12-31 14:15:04.597] I: the http server stop
    EAB7D740 [24-12-31 14:15:04.597] I: the rtsp server stop
    
    正常运行日志打印
    [root@localhost bin]# ./smart_rtmpd 
    48AEE740 [24-12-31 13:40:10.361] I: smart_rtmpd --- build time : 2024-08-15 04:06:58
    48AEE740 [24-12-31 13:40:10.361] I: website url : http://www.qiyicc.com/download/rtmpd.zip
    48AEE740 [24-12-31 13:40:10.361] I: gitee url : https://gitee.com/mirrors/smart-rtmpd
    48AEE740 [24-12-31 13:40:10.361] I: github url : https://github.com/superconvert/smart_rtmpd
    48AEE740 [24-12-31 13:40:10.361] I: liveshow url : https://github.com/superconvert/smart_rtmpd/blob/master/liveshow.md
    48AEE740 [24-12-31 13:40:10.361] I: development url : https://github.com/superconvert/smart_rtmpd/blob/master/web_dev.md
    48AEE740 [24-12-31 13:40:10.361] I: examples url : https://github.com/superconvert/smart_rtmpd/tree/master/example
    48AEE740 [24-12-31 13:40:10.361] I: email : cwf12345@sina.com
    48AEE740 [24-12-31 13:40:10.361] I: webchat : 99766553, qq : 99766553
    48AEE740 [24-12-31 13:40:10.361] I: 192.168.1.102 ens33                               // 我们的服务器地址
    48AEE740 [24-12-31 13:40:10.404] I: ssl client no config.
    48AEE740 [24-12-31 13:40:10.404] I: ssl server no config.
    48AEE740 [24-12-31 13:40:10.528] I: the rtmp server ip: 0.0.0.0, port is: 1935
    48AEE740 [24-12-31 13:40:11.097] I: the http server ip: 0.0.0.0, port is: 8080
    generating new self-signed cert for smart_rtmpd@qiyicc.com
    48AEE740 [24-12-31 13:40:11.366] I: rtc-manager build self-signed certificate.
    48AEE740 [24-12-31 13:40:11.594] I: the rtsp server ip: 0.0.0.0, port is: 8554
    48AEE740 [24-12-31 13:40:11.972] I: the srt server ip: 0.0.0.0, port is: 9000
    48AEE740 [24-12-31 13:40:12.004] I: the sip server ip: 0.0.0.0, port is: 5060
    48AEE740 [24-12-31 13:40:12.244] I: the ims server ip: 0.0.0.0, port is: 6666
    

    这样 smart_rtmpd 就表示正确运行起来了!!!

推流拉流的验证

  1. 推流例子
    RTMP 推流

    ffmpeg -re -stream_loop -1 -i 33.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.1.102:1935/rec/stream
    

    RTMP 推流 ( HEVC )

    ffmpeg -re -i 1.mp4 -c:a copy -c:v libx265 -f flv rtmp://192.168.1.102:1935/live/hevc
    

    怎么让 ffmpeg 支持 hevc 推流 怎么编译 ffmpeg 让其支持 hevc(h265) - superconvert的个人空间 - OSCHINA - 中文开源技术交流社区

    RTSP 推流

    ffmpeg -re -stream_loop -1 -i 1.mp4 -vcodec libx264 -acodec aac -f rtsp rtsp://192.168.1.102:8554/live/stream
    

    RTSP 推流 ( HEVC )

    ffmpeg -re -stream_loop -1 -i video-h265.mkv -vcodec libx265 -acodec aac -f rtsp rtsp://192.168.1.102:8554/live/stream
    

    SRT 推流

    ffmpeg -re -i 22.mp4 -vcodec libx264 -acodec aac -f mpegts srt://192.168.1.102:9000?streamid=192.168.1.102:9000/live/stream,role=publisher
    

    SRT 推流 ( HEVC )

    ffmpeg -stream_loop -1 -re -i video-h265.mkv -vcodec libx265 -acodec aac -f mpegts srt://192.168.1.102:9000?streamid=192.168.1.102:9000/live/stream,role=publisher
    
  2. 拉流例子
    RTMP 拉流

    ffplay rtmp://192.168.1.102:1935/live/stream
    

    HTTP-HLS 拉流

    ffplay http://192.168.1.102:8080/live/stream.m3u8
    

    HTTP-DASH 拉流

    ffplay http://192.168.1.102:8080/live/stream.mpd
    

    RTSP 拉流

    ffplay rtsp://192.168.1.102:8554/live/stream
    

    SRT 拉流 ( ffplay )

    ffplay srt://192.168.1.102:9000?streamid=192.168.1.102:9000/live/stream,role=player
    

更多的推拉流例子请参阅博客 https://blog.csdn.net/freeabc/article/details/117403471?spm=1001.2014.3001.5501
对于支持 Enhanced-rtmp 的 HEVC 推流,需要使用 smart_rtmpd 的收费版本,目前 ffmpeg 从版本 6.1 开始就支持 Enhanced-rtmp 的 HEVC 推流和拉流!!!

  1. smart_rtmpd 的日志查看
    [root@localhost smart_rtmpd]# ./smart_rtmpd 
    4F136740 [24-12-31 13:58:36.864] I: smart_rtmpd --- build time : 2024-08-15 04:06:58
    4F136740 [24-12-31 13:58:36.864] I: website url : http://www.qiyicc.com/download/rtmpd.zip
    4F136740 [24-12-31 13:58:36.864] I: gitee url : https://gitee.com/mirrors/smart-rtmpd
    4F136740 [24-12-31 13:58:36.864] I: github url : https://github.com/superconvert/smart_rtmpd
    4F136740 [24-12-31 13:58:36.864] I: liveshow url : https://github.com/superconvert/smart_rtmpd/blob/master/liveshow.md
    4F136740 [24-12-31 13:58:36.864] I: development url : https://github.com/superconvert/smart_rtmpd/blob/master/web_dev.md
    4F136740 [24-12-31 13:58:36.864] I: examples url : https://github.com/superconvert/smart_rtmpd/tree/master/example
    4F136740 [24-12-31 13:58:36.864] I: email : cwf12345@sina.com
    4F136740 [24-12-31 13:58:36.864] I: webchat : 99766553, qq : 99766553
    4F136740 [24-12-31 13:58:36.864] I: 192.168.161.136 ens33
    4F136740 [24-12-31 13:58:36.892] I: ssl client no config.
    4F136740 [24-12-31 13:58:36.893] I: ssl server no config.
    4F136740 [24-12-31 13:58:37.027] I: the rtmp server ip: 0.0.0.0, port is: 1935
    4F136740 [24-12-31 13:58:37.589] I: the http server ip: 0.0.0.0, port is: 8080
    generating new self-signed cert for smart_rtmpd@qiyicc.com
    4F136740 [24-12-31 13:58:37.601] I: rtc-manager build self-signed certificate.
    4F136740 [24-12-31 13:58:37.601] I: the rtsp server ip: 0.0.0.0, port is: 8554
    4F136740 [24-12-31 13:58:37.852] I: the srt server ip: 0.0.0.0, port is: 9000
    4F136740 [24-12-31 13:58:37.882] I: the sip server ip: 0.0.0.0, port is: 5060
    4F136740 [24-12-31 13:58:38.169] I: the ims server ip: 0.0.0.0, port is: 6666
    1FFFF700 [24-12-31 13:59:34.490] I: rtmp-none(obj: 0x7f8534000900, ip: 192.168.161.1:60252) set in_chunk_size to 60000
    1FFFF700 [24-12-31 13:59:34.491] I: rtmp-publisher(obj: 0x7f8534000900, ip: 192.168.161.1:60252) stream connected.
    1FFFF700 [24-12-31 13:59:34.491] I: rtmp-manager add application(obj: 0x7f8518001e40, url: rtmp://192.168.161.136/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) add http-hls(0x7f8518004de0)
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) add http-dash(0x7f8518005f30)
    1FFFF700 [24-12-31 13:59:34.507] I: rtsp-manager add application(obj: 0x7f851800bd60, url: rtsp://192.168.161.136:8554/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: rtsp-manager add publisher(obj: 0x7f851800b480, url: rtsp://192.168.161.136:8554/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) add rtsp(0x7f851800b480)
    1FFFF700 [24-12-31 13:59:34.507] I: srt-manager add application(obj: 0x7f851800f950, url: srt://192.168.161.136:9000/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: srt-manager add publisher(obj: 0x7f851800e610, url: srt://192.168.161.136:9000/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) add srt(0x7f851800e610)
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-manager add publisher(obj: 0x7f8534000900, url: rtmp://192.168.161.136/live/stream)!
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-publisher(obj: 0x7f8534000900, ip: 192.168.161.1:60252) build elapse 142 ms.
    1FFFF700 [24-12-31 13:59:34.507] I: rtmp-publisher(obj: 0x7f8534000900, ip: 192.168.161.1:60252) amf_cmd unsupport _checkbw
    1FFFF700 [24-12-31 13:59:34.548] I: rtmp-publisher(obj: 0x7f8534000900, ip: 192.168.161.1:60252) publish stream
    4D4F8700 [24-12-31 13:59:34.616] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) inital video(h264 size:1000x562 fps:15)
    4D4F8700 [24-12-31 13:59:34.673] I: rtmp-app(obj:0x7f8518001e40, url: rtmp://192.168.161.136/live/stream) inital audio(aac sample:44100 channel:2 bit:16)     // 推流成功
    3D7FA700 [24-12-31 13:59:51.374] I: rtmp-none(obj: 0x7f85340211d0, ip: 192.168.161.1:60259) amf_cmd unsupport _checkbw
    3D7FA700 [24-12-31 13:59:51.414] I: rtmp-manager add player(obj: 0x7f85340211d0, url: rtmp://192.168.161.136/live/stream)!
    3D7FA700 [24-12-31 13:59:51.414] I: rtmp-player(obj: 0x7f85340211d0, ip: 192.168.161.1:60259) build elapse 84 ms
    3D7FA700 [24-12-31 13:59:51.414] I: rtmp-player(obj: 0x7f85340211d0, ip: 192.168.161.1:60259) play stream
    4D4F8700 [24-12-31 13:59:52.158] I: rtmp-player(obj: 0x7f85340211d0, ip: 192.168.161.1:60259) inital video meta(sps)                                          // 拉流成功
    

收尾工作

通过上述工作,我们的 smart_rtmpd 流媒体服务器能正常工作了,让我们来真正运行它吧,是不是操作特别简单,下载,解压,运行即可!

[root@localhost smart_rtmpd]# ./smart_rtmpd -d                                     // 参数 -d 表示以后台模式运行
[root@localhost smart_rtmpd]# tail -f log/20241231.log                             // 可以查看日志

Good luck!

posted @ 2024-12-31 14:24  superconvert  阅读(251)  评论(0编辑  收藏  举报