FFmpeg推流脚本
闲置vps拿来推流直播,还是不错的。代码如下
一、安装screen
debian
apt update -y && apt install screen -y
二、写入脚本
nano tuiliu.sh
里面加入如下代码
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================================#
# System Required: CentOS7 X86_64 #
# Description: FFmpeg Stream Media Server #
# Author: LALA #
# Website: https://www.lala.im #
#=================================================================#
# 颜色选择
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/no):" Choose
if [ $Choose = "yes" ];then
yum -y install wget
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 = "no" ]
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,并且要绝对路径,例如/opt/video):" folder
# 判断是否需要添加水印
read -p "是否需要为视频添加水印?水印位置默认在右上方,需要较好CPU支持(yes/no):" watermark
if [ $watermark = "yes" ];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=W-w-5:5 -c:v libx264 -c:a aac -b:a 192k -strict -2 -f flv ${rtmp}
done
done
fi
if [ $watermark = "no" ]
then
echo -e "${yellow} 你选择不添加水印,程序将开始推流. ${font}"
# 循环
while true
do
cd $folder
for video in $(ls *.mp4)
do
ffmpeg -re -i "$video" -c:v copy -c:a aac -b:a 192k -strict -2 -f flv ${rtmp}
done
done
fi
}
# 停止推流
stream_stop(){
screen -S stream -X quit
killall ffmpeg
}
# 开始菜单设置
echo -e "${yellow} CentOS7 X86_64 FFmpeg无人值守循环推流 For LALA.IM ${font}"
echo -e "${red} 请确定此脚本目前是在screen窗口内运行的! ${font}"
echo -e "${green} 1.安装FFmpeg (机器要安装FFmpeg才能正常推流) ${font}"
echo -e "${green} 2.开始无人值守循环推流 ${font}"
echo -e "${green} 3.停止推流 ${font}"
start_menu(){
read -p "请输入数字(1-3),选择你要进行的操作:" num
case "$num" in
1)
ffmpeg_install
;;
2)
stream_start
;;
3)
stream_stop
;;
*)
echo -e "${red} 请输入正确的数字 (1-3) ${font}"
;;
esac
}
# 运行开始菜单
start_menu
三、上传mp4视频文件
建议默认root里面就行
四、开一个screen
screen -S stream
在窗口里面执行
./tuiliu.sh
先选1,安装ffmpeg,然后在执行
./tuiliu.sh
再选2
正确输入你的直播流地址和直播ID
格式一般是
推流地址是:直播网址/直播码
视频存放目录,这里写绝对路径,如 /root
推流正常后,后台运行
screen -ls
然后远程detach
screen -d id
This message is used to verify that this feed (feedId:72512850633222144) belongs to me (userId:72504563626603520). Join me in enjoying the next generation information browser https://follow.is.
70918248
References:
legal body building steroids; Guardian.ge,
70918248
References:
definition of anabolic Steroid (yourbookrecommendation.in)
Hey There. I diiscovered yor blog the usage of msn. That
iss a really well written article. I’ll bbe sure tto bookmark it and come
baack to read extra of your hellpful info.
Thanks for thhe post. I’ll dsfinitely comeback. https://glassi-Greyhounds.mystrikingly.com/
You aree so interesting! I do not believe I have read through anything like this before.
So good to find someone with some unique thoughts on this issue.
Seriously.. thanks for starting this up. This web site is one thing that is neded on the internet,
someone with some originality! https://hot-fruits-glassi.Blogspot.com/2025/08/hot-fruitsslot.html