b站24小时不间断直播

安装ffmpeg

apt-get install ffmpeg -y

sh脚本

#!/bin/bash

# 视频文件夹路径
video_folder="/xxx"

# 获取视频文件列表
video_files=("$video_folder"/*.mp4)
num_videos=${#video_files[@]}
current_video_index=0

while true; do
    # 获取当前视频文件路径
    current_video="${video_files[$current_video_index]}"

    # 获取视频时长(单位:秒)
    video_duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$current_video")

    # 推流当前视频到Bilibili直播
    ffmpeg -re -i "$current_video" -c:v libx264 -preset veryfast -b:v 1000k -maxrate 1000k -bufsize 2000k -pix_fmt yuv420p -g 60 -c:a aac -b:a 96k -ac 2 -ar 44100 -f flv "rtmp://your_bilibili_push_url" &

    # 获取推流进程的PID
    ffmpeg_pid=$!

    # 等待视频推流结束
    sleep "$video_duration"

    # 终止推流进程
    kill $ffmpeg_pid

    # 自动播放下一个视频
    current_video_index=$(( (current_video_index + 1) % num_videos ))

    # 可选:在每次推流后等待一段时间,以便给服务器一些休息时间
    sleep 5
done

标签: none

添加新评论