树莓派上弄好了。树莓派4B,安装最新树莓派OS,自带python3和ffmpeg,代码基本拿过来就能用。
[Python] 纯文本查看 复制代码 import os
import subprocess
import time
import re
push_url = "rtmp://tx.direct.huya.com/huyalive/1299644932728-1299644932728-0-2399289286892-10057-A-1722472914-1?seq=1722472915126&type=simple"
video_dir = "/home/lee/Desktop/video"
def natural_sort_key(s):
numbers = [int(text) for text in re.findall(r'\d+', s)]
if not numbers:
return float('-inf')
return numbers[0]
while True:
video_list = sorted(os.listdir(video_dir), key=natural_sort_key)
for video_file in video_list:
video_path = os.path.join(video_dir, video_file)
print(f"Processing file: {video_path}")
cmd = f"ffmpeg -re -i \"{video_path}\" -c:v libx264 -preset fast -c:a aac -strict -2 -f flv \"{push_url}\""
print(f"Running command: {cmd}")
subprocess.call(cmd, shell=True)
time.sleep(0.1)
一起来练八段锦:珂珂酷酷其他直播直播_珂珂酷酷视频直播 - 虎牙直播 (huya.com)
另外树莓派上连接了带麦克风的USB摄像头,修改一下ffmpeg命令就可以实现摄像头直播。
摄像头视频直播,无音频:
[Asm] 纯文本查看 复制代码 ffmpeg -f v4l2 -i /dev/video0 -r 15 -s 1280x720 \
-vcodec libx264 -preset veryfast -maxrate 1500k -bufsize 3000k \
-g 30 -keyint_min 30 -sc_threshold 0 -profile:v main -level 3.1 \
-pix_fmt yuv420p -f flv '推流地址'
摄像头音视频直播:
[Asm] 纯文本查看 复制代码 ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default -r 15 -s 1280x720 \
-vcodec libx264 -preset veryfast -maxrate 1500k -bufsize 3000k \
-g 30 -keyint_min 30 -sc_threshold 0 -profile:v main -level 3.1 \
-pix_fmt yuv420p -acodec aac -strict -2 -ar 44100 \
-f flv '推流地址'
还是上面的连接,有缘就可以看到我上班摸鱼的画面。 |