Fix relay YouTube bloccato: rimuovi ffprobe su RTMP live

ffprobe su rtmp://mediamtx si bloccava in Sidekiq e impediva
l'avvio del relay verso YouTube (pagina sempre in attesa).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-04 08:44:57 +02:00
parent 8263475146
commit 02ff1de0f6

View File

@@ -21,7 +21,7 @@ module Streams
# YouTube richiede FLV H.264/AAC stabili; -c copy lascia spesso streamStatus=inactive.
pid = Process.spawn(
*youtube_ffmpeg_args(intake, output, log_path, with_audio: intake_has_audio?(intake)),
*youtube_ffmpeg_args(intake, output, log_path),
pgroup: true
)
Process.detach(pid)
@@ -68,28 +68,16 @@ module Streams
private
def youtube_ffmpeg_args(intake, output, log_path, with_audio:)
base = [
# Non usare ffprobe su RTMP live: si blocca e impedisce l'avvio del relay (Sidekiq in hang).
# Audio: traccia AAC da anullsrc (YouTube la richiede); il mic del telefono resta su _air/HLS.
def youtube_ffmpeg_args(intake, output, log_path)
[
"ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "warning",
"-fflags", "+genpts+discardcorrupt", "-use_wallclock_as_timestamps", "1",
"-rw_timeout", "15000000",
"-i", intake
]
encode = youtube_encode_flags(output, log_path)
if with_audio
base + ["-map", "0:v:0", "-map", "0:a:0"] + encode
else
# _air senza audio (overlay 0:a?): YouTube richiede comunque AAC.
base + [
"-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=48000",
"-map", "0:v:0", "-map", "1:a:0"
] + encode
end
end
def youtube_encode_flags(output, log_path)
[
"-i", intake,
"-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=48000",
"-map", "0:v:0", "-map", "1:a:0",
"-c:v", "libx264", "-preset", "veryfast", "-tune", "zerolatency",
"-pix_fmt", "yuv420p", "-r", "30", "-g", "30", "-keyint_min", "30", "-sc_threshold", "0",
"-b:v", "4000k", "-maxrate", "4000k", "-bufsize", "8000k",
@@ -99,17 +87,6 @@ module Streams
]
end
def intake_has_audio?(url)
require "open3"
stdout, _stderr, status = Open3.capture3(
"ffprobe", "-v", "error", "-rw_timeout", "5000000",
"-select_streams", "a", "-show_entries", "stream=index", "-of", "csv=p=0", url
)
status.success? && stdout.strip.present?
rescue StandardError
false
end
def schedule_youtube_activate(session)
return if session.youtube_broadcast_id.blank?