youtube 24小时无人直播

前言

       如果你不想将你服务器闲置下来,可以用来做一些有趣的事,比如做一个24小时的无人直播。顺带能挣点米,不废话,开整。

条件

  • youtube账号一个(需要开通直播功能)
  • 服务器一台(Liunx系统)
  • 视频素材一个(视频画面最好设置为16:9)

步骤

1。安装相关依赖程序。其中最主要的是ffmpeg,其他的装不装无所谓

apt update -y  && apt upgrade -y && apt install -y curl wget sudo socat htop ffmpeg iftop
sudo apt install supervisor

2。检查是否有可执行权限,如果没有可执行权限,就授予执行权限

cd /etc/init.d/
sudo chmod +x /etc/init.d/supervisor

3。需要启动 supervisor 守护进程。

sudo service supervisor start   #启动
sudo service supervisor stop    #停止
sudo service supervisor status    #查看状态

4。创建目录,将你准备好的视频素材放进去。注意视频名称需要和代码里的统一。

mkdir /ibeg
cd /ibeg
 #编辑配置文件。
vim /etc/supervisor/conf.d/ibeglive.conf

5。配置文件里面如果有内容,全部删除。然后将下面配置文件内容粘贴进去。

[program:ibeglive]
command=ffmpeg -stream_loop -1 -re -i /ibeg/live.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/sasd-dfgf-0011-1122-2233
autostart=true
autorestart=true
startretries=3    
stderr_logfile=/var/log/ffmpeg.err.log
stdout_logfile=/var/log/ffmpeg.out.log
注意:这里面只需要修改一个地方。

这个指令的意思是:将 /ibeg/live.mp4 文件作为源视频,以实时速率循环播放,并通过 RTMP 协议将其推流到指定的 YouTube 直播频道。

command=ffmpeg -stream_loop -1 -re -i /ibeg/live.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/sasd-dfgf-0011-1122-2233

这条参数最后的【sasd-dfgf-0011-1122-2233】修改成图片里的直播码。

6。加载配置文件

sudo supervisorctl reread
sudo supervisorctl update

7。启动服务,执行第一条启动指令后,你的直播就正式开始。

supervisorctl start ibeglive  #启动
supervisorctl stop ibeglive   #停止
supervisorctl status ibeglive #状态
supervisorctl restart ibeglive   #重启

8。如果想要停止,必须先停止守护进程supervisor,在停止直播推流进程ibeglive

sudo service supervisor stop    #停止
supervisorctl stop ibeglive   #停止
pkill -9 ffmpeg

总结

至此完成。

吃瓜频道:【葬花吟
资源频道:【万能资源搜索群