本文主要是介绍ffmpeg 推流到 crtmpserver 测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
直播
rtmp 分发
退流------>直播服务器CDN------>各个客户端(rtmp,http-flv,hls)
推流
RGB RGB
rtsp h264 1.图像采集----->美颜,水印—>转YUV H264编码
rtsp aac 2.音频采集----->去噪,变音—>音频重采样aac编码
PCM
(h264 + aac) ---->FLV封装–>FLV—>推流---->RTMP–>直播服务CDN
RTMP
(real time messaging protocol) 长连接TCP
每个时刻的数据收到立即转发 延时1-3秒
HLS
(HTTP Live Stream) 短连接HTTP
集合一段时间数据,生成ts切片文件,更新m3u8 延时>10s
HTTP-FLV
(RTMP over HTTP) 长连接HTTP
同RTMP,使用http协议 延时1-3秒
RTMP
(Real Time Messaging Protocol, 实时消息传送协议)RTMP是Adobe Systems公司为Flash播放器和
服务器之间音频、视频和数据传输开发的开放协
议。
RTMP优缺点
优点
- 主流CDN支持, 市面上绝大多数的直播产品采用,
- 协议简单易实现 基于TCP协议开销大
- Adobe 私有协议
RTMP协议类型
1 ) 、工作在TCP之上的明文协议,使用端口1935 ;
2 ) 、RTMPT封装在HTTP请求之中,可穿越防火墙 ;
3 ) 、RTMPs类似RTMP 但使用的是HTTPS连接 ;
安装流媒体服务器
- clone crtmpserver
https://github.com/j0sh/crtmpserver
2.Add openssl 1.1.0 compatibility #9
https://github.com/j0sh/crtmpserver/pull/9
修改对openssl 1.1.0 支持
xz@xiaqiu:~/study/csdn/rtmp$ ls
crtmpserver video
xz@xiaqiu:~/study/csdn/rtmp$ cd crtmpserver/builders/cmake
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ ls
androidapplestreaming common tests
applications crtmpserver thelib
build debianpackage.patch tinyxml
cleanup.sh ltib toolchain-sourcery_g++_lite.cmake
CMakeCache.txt lua trafficdissector
CMakeFiles Makefile vg.sh
cmake_find_modules package.sh vm
cmake_install.cmake precompiled.gch vmtests
CMakeLists.txt run
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ subl CMakeLists.txt
修改CMakeLists.txt
注释
#SET(GENERIC_FLAGS "-Wall -Werror")
编译
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ cmake .
-- OPENSSL_INCLUDE_PATH: /usr/include
-- OPENSSL_LIBRARY_PATH: /lib/x86_64-linux-gnu/libssl.so
-- CRYPTO_LIBRARY_PATH: /lib/x86_64-linux-gnu/libcrypto.so
-- Z_LIBRARY_PATH:
-- Looking for openssl headers - found
-- Looking for openssl library - found
-- Looking for crypto library - found
...
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ make
[ 9%] Built target lua
[ 11%] Built target tinyxml
[ 11%] Built target common_common_gch
Scanning dependencies of target common
...
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ cd crtmpserver/
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake/crtmpserver$ ls
CMakeFiles cmake_install.cmake CMakeLists.txt crtmpserver crtmpserver.lua Makefile
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake/crtmpserver$
xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake/crtmpserver$ cd ..xz@xiaqiu:~/study/csdn/rtmp/crtmpserver/builders/cmake$ ./crtmpserver/crtmpserver crtmpserver/crtmpserver.lua
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:215 C++ RTMP Media Server (www.rtmpd.com) build - 2021-11-14T15:47:46.000
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:217 Initialize I/O handlers manager: epoll with timerfd_XXXX support
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:220 Configure modules
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/appselector/libappselector.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/flvplayback/libflvplayback.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/samplefactory/libsamplefactory.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/vptests/libvptests.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/admin/libadmin.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/proxypublish/libproxypublish.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:84 Module /home/xz/study/csdn/rtmp/crtmpserver/builders/cmake/applications/stresstest/libstresstest.so loaded
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:226 Plug in the default protocol factory
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:233 Configure factories
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:97 Loaded factory from application samplefactory
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:239 Configure acceptors
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 0->1 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 1->2 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 2->3 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 3->4 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 4->5 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 5->6 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 6->7 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 7->8 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 8->9 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 9->10 IOHT_ACCEPTOR
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:245 Configure instances
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:251 Start I/O handlers manager: epoll with timerfd_XXXX support
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:254 Configure applications
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application admin instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application appselector instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application flvplayback instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application proxypublish instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:118 Handlers count changed: 10->11 IOHT_TIMER
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application samplefactory instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application stresstest instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/thelib/src/configuration/module.cpp:177 Application vptests instantiated
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:260 Install the quit signal
Run()
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:272
+-----------------------------------------------------------------------------+
| Services|
+---+---------------+-----+-------------------------+-------------------------+
| c | ip | port| protocol stack name | application name |
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1112| inboundJsonCli| admin|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1935| inboundRtmp| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8081| inboundRtmps| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8080| inboundRtmpt| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 6666| inboundLiveFlv| flvplayback|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 9999| inboundTcpTs| flvplayback|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 6665| inboundLiveFlv| proxypublish|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8989| httpEchoProtocol| samplefactory|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8988| echoProtocol| samplefactory|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1111| inboundHttpXmlVariant| vptests|
+---+---------------+-----+-------------------------+-------------------------+
/home/xz/study/csdn/rtmp/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:273 GO! GO! GO! (5495)
如果启动失败查看是否已经运行
记得在crtmpserver/builders/cmake$
目录下运行
ffmpeg查看设备
ffmpeg -fdshow -i video="USB2.0 Camera" -f flv rtmp://192.168.1.44/live/test1
ffmpeg -i test.mp4 -f flv rtmp://192.168.1.44/live/test1
ffmpeg -i rtsp://nj:nj@192.168.1.108 -an -f flv rtmp://192.168.1.44/live/test1
ffmpeg -i rtsp://admin:njzs2014@192.168.1.64:554/ -c copy -f flv rtmp://192.168.1.44/liveytest1
ffmpeg 推流
xz@xiaqiu:~/study/csdn/rtmp/video$ ls
test.mp4
xz@xiaqiu:~/study/csdn/rtmp/video$ ffmpeg -i test.mp4 -f flv rtmp://0.0.0.0/live/test1
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developersbuilt with gcc 9 (Ubuntu 9.3.0-10ubuntu2)configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-sharedlibavutil 56. 31.100 / 56. 31.100libavcodec 58. 54.100 / 58. 54.100libavformat 58. 29.100 / 58. 29.100libavdevice 58. 8.100 / 58. 8.100libavfilter 7. 57.100 / 7. 57.100libavresample 4. 0. 0 / 4. 0. 0libswscale 5. 5.100 / 5. 5.100libswresample 3. 5.100 / 3. 5.100libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':Metadata:major_brand : isomminor_version : 512compatible_brands: isomiso2avc1mp41encoder : Lavf58.29.100Duration: 00:00:26.06, start: 0.000000, bitrate: 7014 kb/sStream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1366x768 [SAR 1:1 DAR 683:384], 7022 kb/s, 30.04 fps, 30 tbr, 15360 tbn, 60 tbc (default)Metadata:handler_name : VideoHandlerStream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s (default)Metadata:handler_name : SoundHandler
[rtmp @ 0x5590097078c0] Server error: Specified stream not found in call to releaseStream
[rtmp @ 0x5590097078c0] Server error: call to function _checkbw failed
Stream mapping:Stream #0:0 -> #0:0 (h264 (native) -> flv1 (flv))Stream #0:1 -> #0:1 (vorbis (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, flv, to 'rtmp://0.0.0.0/live/test1':Metadata:major_brand : isomminor_version : 512compatible_brands: isomiso2avc1mp41encoder : Lavf58.29.100Stream #0:0(und): Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 1366x768 [SAR 1:1 DAR 683:384], q=2-31, 200 kb/s, 30 fps, 1k tbn, 30 tbc (default)Metadata:handler_name : VideoHandlerencoder : Lavc58.54.100 flvSide data:cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1Stream #0:1(und): Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 48000 Hz, stereo, fltp (default)Metadata:handler_name : SoundHandlerencoder : Lavc58.54.100 libmp3lame
frame= 23 fps=0.0 q=31.0 size= 1127kB time=00:00:00.76 bitrate=12003.6kbits/s speed=1.frame= 64 fps= 63 q=31.0 size= 1955kB time=00:00:02.16 bitrate=7409.4kbits/s speed=2.1frame= 105 fps= 69 q=31.0 size= 2688kB time=00:00:03.52 bitrate=6240.5kbits/s speed=2.3frame= 142 fps= 70 q=31.0 size= 3465kB time=00:00:04.75 bitrate=5971.5kbits/s speed=2.3frame= 179 fps= 71 q=31.0 size= 4317kB time=00:00:05.97 bitrate=5917.0kbits/s speed=2.3frame= 217 fps= 71 q=24.8 size= 5280kB time=00:00:07.27 bitrate=5946.8kbits/s speed=2.3frame= 254 fps= 71 q=31.0 size= 6175kB time=00:00:08.47 bitrate=5970.1kbits/s speed=2.3frame= 302 fps= 74 q=31.0 size= 6986kB time=00:00:10.08 bitrate=5677.0kbits/s speed=2.4frame= 348 fps= 76 q=31.0 size= 7605kB time=00:00:11.61 bitrate=5362.6kbits/s speed=2.5frame= 384 fps= 76 q=31.0 size= 8256kB time=00:00:12.84 bitrate=5267.2kbits/s speed=2.5frame= 427 fps= 77 q=31.0 size= 8634kB time=00:00:14.25 bitrate=4961.2kbits/s speed=2.5frame= 470 fps= 77 q=31.0 size= 9151kB time=00:00:15.69 bitrate=4776.0kbits/s speed=2.5frame= 507 fps= 77 q=31.0 size= 9914kB time=00:00:16.92 bitrate=4799.6kbits/s speed=2.5frame= 548 fps= 77 q=31.0 size= 10862kB time=00:00:18.28 bitrate=4865.4kbits/s speed=2.5frame= 588 fps= 77 q=31.0 size= 11774kB time=00:00:19.60 bitrate=4918.8kbits/s speed=2.5frame= 628 fps= 77 q=31.0 size= 12642kB time=00:00:20.95 bitrate=4942.7kbits/s speed=2.5frame= 671 fps= 78 q=31.0 size= 13545kB time=00:00:22.39 bitrate=4955.3kbits/s speed= 2.frame= 721 fps= 79 q=24.8 size= 14289kB time=00:00:24.04 bitrate=4867.4kbits/s speed=2.6frame= 779 fps= 81 q=31.0 size= 14656kB time=00:00:25.96 bitrate=4623.2kbits/s speed=2.6[flv @ 0x5590096e7b00] Failed to update header with correct duration.
[flv @ 0x5590096e7b00] Failed to update header with correct filesize.
frame= 780 fps= 81 q=31.0 Lsize= 14659kB time=00:00:26.08 bitrate=4602.8kbits/s speed= 2.7x
video:14221kB audio:408kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.202187%
VLC 播放器输入rtmp://0.0.0.0/live/test1 进行播放
这篇关于ffmpeg 推流到 crtmpserver 测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!