使用coolpi 4b搭建rtmp服务器
-
准备环境
默认coolpi 4b安装ubuntu22镜像系统。
需要补充配置
root@coolpi:/home/coolpi# apt install libnginx-mod-rtmp Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: libnginx-mod-rtmp 0 upgraded, 1 newly installed, 0 to remove and 359 not upgraded. Need to get 133 kB of archives. After this operation, 388 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu-ports jammy-updates/universe arm64 libnginx-mod-rtmp arm64 1.18.0-6ubuntu14.4 [133 kB] Fetched 133 kB in 0s (322 kB/s) Selecting previously unselected package libnginx-mod-rtmp. (Reading database ... 353816 files and directories currently installed.) Preparing to unpack .../libnginx-mod-rtmp_1.18.0-6ubuntu14.4_arm64.deb ... Unpacking libnginx-mod-rtmp (1.18.0-6ubuntu14.4) ... Setting up libnginx-mod-rtmp (1.18.0-6ubuntu14.4) ... Processing triggers for nginx-core (1.18.0-6ubuntu14.4) ... root@coolpi:/home/coolpi
修改nginx默认配置文件,追加如下内容
root@coolpi:/home/coolpi# vim /etc/nginx/nginx.conf rtmp { server { listen 3588; application live { live on; } } }
重启nginx服务,查看端口
root@coolpi:/home/coolpi# systemctl restart nginx root@coolpi:/home/coolpi# netstat -nptl | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6309/nginx: master tcp 0 0 0.0.0.0:3588 0.0.0.0:* LISTEN 6309/nginx: master tcp6 0 0 :::80 :::* LISTEN 6309/nginx: master root@coolpi:/home/coolpi#
编辑测试文件rtmp_mp4.sh
coolpi@coolpi:~$ cat rtmp_mp4.sh #!/bin/bash ffmpeg -re -i $1 -c:v copy -f flv rtmp://localhost:3588/live/1 coolpi@coolpi:~$
运行启动服务器
coolpi@coolpi:~$ sh rtmp_mp4.sh /data/4kx30fpsbirds.mp4 ffmpeg version 4.4.2-0+rkmpp Copyright (c) 2000-2021 the FFmpeg developers built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04) configuration: --prefix=/usr --extra-version=0+rkmpp --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libdrm --enable-rkmpp --enable-version3 --disable-libopenh264 --disable-vaapi --disable-vdpau --disable-decoder=h264_v4l2m2m --disable-decoder=vp8_v4l2m2m --disable-decoder=mpeg2_v4l2m2m --disable-decoder=mpeg4_v4l2m2m --enable-shared libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/4kx30fpsbirds.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf54.63.104 Duration: 00:02:23.50, start: 0.000000, bitrate: 11490 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 11362 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: handler_name : SoundHandler vendor_id : [0][0][0][0] Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame)) Press [q] to stop, [?] for help Output #0, flv, to 'rtmp://localhost:3588/live/1': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.76.100 Stream #0:0(und): Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 11362 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 90k tbc (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:1(und): Audio: mp3 ([2][0][0][0] / 0x0002), 44100 Hz, stereo, fltp (default) Metadata: handler_name : SoundHandler vendor_id : [0][0][0][0] encoder : Lavc58.134.100 libmp3lame ...
本地ffplay或其他主机使用VLC打开网络流
coolpi@coolpi:~$ ffplay rtmp://localhost:3588/live/1