AWS – SRS V6 Docker Cluster – Webrtc در حالی که FLV/HLS کار می کند شکست می خورد

من منشأ خوشه SRS را با کمک داکر تنظیم کردم. من می خواهم یک جریان RTMP را در مبدا ارسال کنم و با استفاده از HTTP-FLV ، HLS و WEBRTC ، آن را بر روی پروکسی بازتولید کنم. انگیزه من این است که وقتی چندین دوربین را با WEBRTC از طریق سرور AWS خود منتقل می کنم ، دوربین دوم تأخیر است. از درک من ، SRS روی موضوعی کار می کند که می تواند مشکلاتی ایجاد کند. به این ترتیب من تصمیم گرفتم از سیستم Multi-Container استفاده کنم (لطفا به من اطلاع دهید که آیا راه های بهتری وجود دارد!). تا کنون ، من فقط دو ظروف را امتحان می کنم:
- مبدا که جریان را دریافت می کند
- پروکسی که جریان منشاء و جریان صفحه HTML را می کشد
من موفق شده ام:
- تنظیمات تنظیم با یک کانتینر کاملاً برای همه پروتکل ها (FLV ، HLS و WEBRTC) کار می کند.
- یک تنظیم برای یک ظرف بسیار ایجاد کنید ، بازی HTTP-FLV و HLS به درستی کار می کند ، که ثابت می کند جریان از ابتدای پروکسی کشیده می شود.
مشکل من:
تولید مثل Webrtc تنها چیزی است که شکست می خورد. این مرورگر با Proxito ارتباط موفقی دارد (پیوند ایجاد شده برای نمایش پرونده های ورود به سیستم) ، اما هرگز یک ویدیو ظاهر نمی شود. دفتر خاطرات پروکسی نشان می دهد که برای کشیدن جریان به مبدأ متصل می شود ، اما اتصال سپس با خطایی در تجزیه و تحلیل ویدیو منقضی می شود یا شکست می خورد (AVC Demux AndexB: نه ضمیمه).
docker-compose.yml من:
version: '3.8'
networks:
srs-net:
driver: bridge
services:
srs-origin:
image: ossrs/srs:6
container_name: srs-origin
networks: [srs-net]
ports: ["1936:1935"]
expose:
- "1935"
volumes: ["./origin.conf:/usr/local/srs/conf/srs.conf:ro"]
command: ["./objs/srs", "-c", "conf/srs.conf"]
restart: unless-stopped
srs-proxy:
image: ossrs/srs:6
container_name: srs-proxy
networks: ["srs-net"]
ports:
- "1935:1935"
- "1985:1985"
- "8000:8000/udp"
- "8080:8080"
depends_on:
- srs-origin
volumes:
- "./proxy.conf:/usr/local/srs/conf/srs.conf:ro"
- "./html:/usr/local/srs/html"
command: ["./objs/srs", "-c", "conf/srs.conf"]
restart: unless-stopped
Origin.conf:
listen 1935;
daemon off;
srs_log_tank console;
srs_log_level trace;
vhost __defaultVhost__ {
}
proxy.conf:
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
srs_log_level trace;
http_server {
enabled on;
listen 8080;
dir ./html;
crossdomain on;
}
http_api {
enabled on;
listen 1985;
crossdomain on;
}
rtc_server {
enabled on;
listen 8000;
candidate xxx.xxx.xxx.xxx; # IP address
}
vhost __defaultVhost__ {
enabled on;
# Enable cluster mode to pull from the origin server
cluster {
mode remote;
origin srs-origin:1935;
}
# Low latency settings
play {
gop_cache off;
queue_length 1;
mw_latency 50;
}
# WebRTC configuration (Not working)
rtc {
enabled on;
rtmp_to_rtc on;
rtc_to_rtmp off;
# Important for SRS v6
bframe discard;
keep_bframe off;
}
# HTTP-FLV (working)
http_remux {
enabled on;
mount /[app]/[stream].flv;
}
# HLS (working)
hls {
enabled on;
hls_path ./html;
hls_fragment 3;
hls_window 9;
}
}
لوله FFMPEG من از دستگاه Python خود از دستگاه میزبان خود استفاده می کنم تا فیلم های ویدیویی را به سرور AWS خود فشار دهم:
IP_ADDRESS = ip_address
RTMP_SERVER_URL = f"rtmp://{IP_ADDRESS}:1936/live/Camera_0"
BITRATE_KBPS = bitrate # Target bitrate for the output stream (2 Mbps)
# Threading and queue for frame processing
ffmpeg_cmd = [
'ffmpeg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', f'{self.frame_width}x{self.frame_height}',
'-r', str(self.camera_fps),
'-i', '-',
# Add audio source (silent audio if no mic)
'-f', 'lavfi',
'-i', 'anullsrc=channel_layout=stereo:sample_rate=44100',
# Video encoding
'-c:v', 'libx264',
'-preset', 'ultrafast',
'-tune', 'zerolatency',
'-pix_fmt', 'yuv420p',
# Keyframe interval: 1 second. Consider 0.5s if still high, but increases bitrate.
'-g', str(2*self.camera_fps),
# Force no B-frames (zerolatency should handle this, but explicit is sometimes better)
'-bf', '0',
'-profile:v', 'baseline', # Necessary for apple devices
# Specific libx264 options for latency (often implied by zerolatency, but can be explicit)
# Add options to explicitly disable features not in Baseline profile,
# ensuring maximum compatibility and avoiding implicit enabling by preset.
'-x264-params', 'cabac=0:ref=1:nal-hrd=cbr:force-cfr=1:no-mbtree=1:slice-max-size=1500',
# Force keyframes only if input allows (might not be practical for camera input)
'-keyint_min', str(self.camera_fps), # Ensure minimum distance is also 1 second
# Rate control and buffering for low latency
'-b:v', f'{BITRATE_KBPS}k', # Your target bitrate (e.g., 1000k)
'-maxrate', f'{BITRATE_KBPS * 1.2}k', # Slightly higher maxrate than bitrate
'-bufsize', f'{BITRATE_KBPS * 1.5}k', # Buffer size related to maxrate
'-f', 'flv',
RTMP_SERVER_URL
]
self.ffmpeg_process = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, bufsize=10**5)


