's'
This commit is contained in:
49
main.py
49
main.py
@@ -258,17 +258,17 @@ def launch_ffmpeg(input_url: str, out_url: str, extra_headers: Optional[str] = N
|
||||
"""
|
||||
启动一个 ffmpeg 进程:输入 input_url,输出 RTMP 到 out_url。
|
||||
"""
|
||||
user_agent = ("Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 "
|
||||
"(KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36")
|
||||
user_agent = ("Mozilla/5.0 (Linux; Android 11; SM-G973U) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/87.0.4280.141 Mobile Safari/537.36")
|
||||
|
||||
rw_timeout = "15000000"
|
||||
analyzeduration = "20000000"
|
||||
probesize = "10000000"
|
||||
bufsize = "8000k"
|
||||
|
||||
base = [
|
||||
"ffmpeg", "-nostdin", "-hide_banner",
|
||||
# 超时 & 重连(必须在 -i 前面)
|
||||
# 超时和重连
|
||||
"-rw_timeout", rw_timeout,
|
||||
"-timeout", "10000000",
|
||||
"-reconnect", "1",
|
||||
@@ -280,33 +280,40 @@ def launch_ffmpeg(input_url: str, out_url: str, extra_headers: Optional[str] = N
|
||||
"-user_agent", user_agent,
|
||||
"-protocol_whitelist", "rtmp,crypto,file,http,https,tcp,tls,udp,rtp,httpproxy",
|
||||
|
||||
# 缓冲 & 分析
|
||||
# 缓冲和分析
|
||||
"-thread_queue_size", "1024",
|
||||
"-analyzeduration", analyzeduration,
|
||||
"-probesize", probesize,
|
||||
"-fflags", "+discardcorrupt",
|
||||
|
||||
# 输入流(放在重连参数之后)
|
||||
"-re", "-i", input_url,
|
||||
# 输入
|
||||
"-i", input_url,
|
||||
|
||||
# 视频/音频编解码
|
||||
"-c:v", "copy", # 直接拷贝视频,省 CPU,低延迟
|
||||
"-c:a", "aac", # 音频转码成 AAC(保证 YouTube 兼容)
|
||||
"-ar", "44100", # 音频采样率
|
||||
"-b:a", "128k", # 音频码率
|
||||
"-ac", "2", # 双声道
|
||||
"-bufsize", bufsize,
|
||||
"-max_muxing_queue_size", "2048",
|
||||
"-avoid_negative_ts", "1",
|
||||
"-fflags", "+genpts", # 确保时间戳连续,防止花屏
|
||||
# 强制视频转码成 YouTube 最兼容的格式
|
||||
"-c:v", "libx264",
|
||||
"-preset", "veryfast",
|
||||
"-pix_fmt", "yuv420p",
|
||||
"-profile:v", "high",
|
||||
"-level", "4.1",
|
||||
"-r", "30", # 固定帧率
|
||||
"-g", "60", # GOP=2s
|
||||
"-b:v", "5000k",
|
||||
"-maxrate", "5000k",
|
||||
"-bufsize", "10000k",
|
||||
|
||||
# 音频转码成 AAC
|
||||
"-c:a", "aac",
|
||||
"-b:a", "128k",
|
||||
"-ar", "44100",
|
||||
"-ac", "2",
|
||||
|
||||
# 避免缓冲过长导致 "no data"
|
||||
"-muxdelay", "0",
|
||||
"-shortest",
|
||||
|
||||
# 输出容器
|
||||
"-f", "flv", out_url
|
||||
]
|
||||
|
||||
if extra_headers:
|
||||
base[ base.index("-user_agent") : base.index("-protocol_whitelist") ] += ["-headers", extra_headers]
|
||||
|
||||
if proxy_addr:
|
||||
base = ["ffmpeg", "-http_proxy", proxy_addr] + base[1:]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user