Utilize Synology 7×24 hours uninterrupted live streaming

Original link: https://www.boyhu.cn/notes/utilizing-qunhuis-7×24-hour-uninterrupted-live-streaming-push.html

favicon.ico

I mentioned a live streaming tool in my blog before, that is Kplayer . This solution supports Docker container deployment and is more friendly to novices. However, due to the large number of supported functions, many people will not understand the Kplayer configuration file. Recently, I found a simple script based on the SSH command line to achieve live streaming. I will share it with you.

The script currently only supports MP4 format video, others are not supported for now, please know!

Friends with VPS can also use this method. First, download the video files that need to be streamed, and then open your live broadcast room through real-name authentication, and obtain the streaming address and streaming code of the live broadcast room.

For example, Bilibili: rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_384574173_87384919&key=0f65b17e11a61f9

The next step is to copy the following script and save it to the corresponding location , such as: /volume2/docker

 #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH #=================================================================# # System Required: CentOS/Debian/Ubuntu/Fedora (32bit/64bit) # # Description: FFmpeg Stream Media Server # # #=================================================================# # 颜色选择red='\033[0;31m' green='\033[0;32m' yellow='\033[0;33m' font="\033[0m" ffmpeg_install(){ # 安装FFMPEG read -p "你的机器内是否已经安装过FFmpeg4.x?安装FFmpeg才能正常推流,是否现在安装FFmpeg?(yes[y]/no[n]):" Choose if [ $Choose = "y" ];then wget --no-check-certificate https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-4.0.3-64bit-static.tar.xz tar -xJf ffmpeg-4.0.3-64bit-static.tar.xz cd ffmpeg-4.0.3-64bit-static mv ffmpeg /usr/bin && mv ffprobe /usr/bin && mv qt-faststart /usr/bin && mv ffmpeg-10bit /usr/bin fi if [ $Choose = "n" ] then echo -e "${yellow} 你选择不安装FFmpeg,请确定你的机器内已经自行安装过FFmpeg,否则程序无法正常工作! ${font}" sleep 2 fi } stream_start(){ # 定义推流地址和推流码read -p "输入你的推流地址和推流码(rtmp协议):" rtmp # 判断用户输入的地址是否合法if [[ $rtmp =~ "rtmp://" ]];then echo -e "${green} 推流地址输入正确,程序将进行下一步操作. ${font}" sleep 2 else echo -e "${red} 你输入的地址不合法,请重新运行程序并输入! ${font}" exit 1 fi # 定义视频存放目录read -p "输入你的视频存放目录(格式仅支持mp4,并且要绝对路径,例如/volume2/docker/live):" folder # 判断是否需要添加水印read -p "是否需要为视频添加水印?水印位置默认在右上方,需要较好CPU支持(yes[y]/no[n]):" watermark if [ $watermark = "y" ];then read -p "输入你的水印图片存放绝对路径,例如/opt/image/watermark.jpg (格式支持jpg/png/bmp):" image echo -e "${yellow} 添加水印完成,程序将开始推流. ${font}" # 循环while true do cd $folder for video in $(ls *.mp4) do ffmpeg -re -i "$video" -i "$image" -filter_complex overlay=Ww-5:5 -c:v libx264 -c:a aac -b:a 128k -strict -2 -f flv ${rtmp} done done fi if [ $watermark = "n" ] then echo -e "${yellow} 你选择不添加水印,程序将开始推流. ${font}" # 循环while true do cd $folder video=$(find ./ -type f | shuf -n 1) ffmpeg -re -i "$video" -preset ultrafast -vcodec libx264 -g 60 -b:v 1500k -c:a aac -b:a 128k -strict -2 -f flv ${rtmp} done fi } #查看推流进程stream_ls(){ screen -ls } # 停止推流stream_stop(){ screen -S live -X quit killall ffmpeg } # 开始菜单设置echo -e "${yellow} 7×24 全天候不间断无人值守循环直播推流${font}" echo -e "${yellow} 适用于CentOS/Debian/Ubuntu/Fedora (32bit/64bit) ${font}" echo -e "${yellow} LALA 编写KuwiNet 修改${font}" echo -e "${red} 请确定此脚本目前是在screen/TERM=xterm screen窗口内运行的! ${font}" echo -e "${green} 1.安装FFmpeg (机器要安装FFmpeg才能正常推流) ${font}" echo -e "${green} 2.开始无人值守循环推流${font}" echo -e "${green} 3.查看推流进程${font}" echo -e "${green} 4.停止推流${font}" start_menu(){ read -p "请输入数字(1-4),选择你要进行的操作:" num case "$num" in 1) ffmpeg_install ;; 2) stream_start ;; 3) stream_ls ;; 4) stream_stop ;; *) echo -e "${red} 请输入正确的数字(1-3) ${font}" ;; esac } # 运行开始菜单start_menu

Use the SSH connection tool you are used to, for example, the kid likes the OpenSSH tool that comes with Windows, open the SSH function of the Synology control panel, connect to the Synology and log in with the root account, and then execute the commands one by one.

 cd /volume2/docker ./live.sh

Install FFmpeg according to the menu prompts, or if Synology has installed the FFmpeg suite, you don’t need to perform this step. You can directly skip option 2 and start unattended circular streaming. Fill in rtmp://推流地址/推流码obtained on the live broadcast platform rtmp://推流地址/推流码, enter the address where you save the video file, such as here, fill in /volume2/docker/live , if there is no video watermark, select n, and the normal push stream will start!

Of course, after the above method closes the SSH window, the streaming will stop, so how to achieve 7×24 hours of uninterrupted live streaming? It is also very simple to implement, just use the screen new window to execute the live.sh script before returning to execute the script.

Synology does not install ipkg package management and screen by default, just execute the following command:

 wget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/syno-i686-bootstrap_1.2-7_i686.xsh chmod +x syno-i686-bootstrap_1.2-7_i686.xsh sh syno-i686-bootstrap_1.2-7_i686.xsh ipkg update ipkg install screen

if an error occurs

 Cannot find termcap entry for 'xterm-256color'

Run TERM=xterm screen instead of screen.

Then, when executing the script, the command should be executed like this:

 cd /volume2/docker xterm screen -S live ./live.sh

After normal streaming, you can close the SSH window and the streaming process will not be affected, so how to close the streaming? The first one is very simple, select 4 in the menu, and the streaming process will end, and I recommend using the following methods:

查看推流窗口screen -ls脱离窗口,2843.live表示要脱离的窗口screen -d 2843.live关闭推流进程命令screen -X -S 2843.live quit

Well, after trying to push the 720P video of J1900’s black skirt, it is just fully loaded without freezing. 1500k and 128k in the script represent the video bit rate and audio bit rate respectively. Please modify it according to the device performance and upload bandwidth.

If you don’t know how to use Docker to install Kplayer to achieve live streaming, then this script is believed to be more suitable for you.

This article is reproduced from: https://www.boyhu.cn/notes/utilizing-qunhuis-7×24-hour-uninterrupted-live-streaming-push.html
This site is only for collection, and the copyright belongs to the original author.