feat: encode on the GPU and restart individual renditions
Hardware encoding
- Detect the best usable encoder at startup by encoding a test frame with each
candidate in turn (nvenc, qsv, amf, then libx264). Being compiled into ffmpeg
is not enough: h264_amf fails without amfrt64.dll and h264_qsv fails without an
Intel iGPU, so the probe is the only reliable answer.
- Translate the quality target into the chosen encoder's own vocabulary. libx264's
-crf and "ultrafast" mean nothing to h264_nvenc, which takes -cq and p1..p7, so
passing the configured values straight through would have been silently wrong.
- On the reference GTX 1060 a 1080p->720p rendition costs ~62% of a core on NVENC
versus ~109% on libx264 ultrafast.
Per-rendition supervision
- Track encoder processes per rendition, not per stream. is_running answered
"any alive", so when the source ("原画") encoder died while 1080p and 720p kept
running, the supervisor saw a healthy stream and never restarted it — the
source URL then 404'd permanently. It now requires every rendition to be alive
and reports which ones are down.
- Restart only the dead renditions, so a single failure no longer interrupts
viewers on the renditions that were fine.
Production serving
- Serve the built frontend from FastAPI with SPA fallback, so production is one
process and one port with no Node runtime. Node becomes a build-time dependency.
- start.ps1/start.sh build the frontend on first run instead of failing to a 503.
Cleanup
- Drop the duplicated top-left LIVE badge; the control strip already carries it.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
1 parent
996e3fea39
commit
4ee945ca0d
7 files changed
+394
-111
No files matched your search
@@ -1,5 +1,6 @@
|
||||
param(
|
||||
[switch]$InstallDeps,
|
||||
[switch]$BuildFrontend,
|
||||
[string]$HostAddress = "0.0.0.0",
|
||||
[int]$BackendPort = 8080
|
||||
)
|
||||
@@ -41,11 +42,29 @@ if ($InstallDeps) {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# The frontend is built once and then served by the backend, so Node is only
|
||||
# needed here — production never runs npm. Done automatically on a first start so
|
||||
# a fresh checkout does not come up as a 503 with no obvious cause.
|
||||
$FrontendDir = Join-Path $Base "frontend"
|
||||
$DistDir = Join-Path $FrontendDir "dist"
|
||||
if ($BuildFrontend -or -not (Test-Path (Join-Path $DistDir "index.html"))) {
|
||||
if (Get-Command "npm" -ErrorAction SilentlyContinue) {
|
||||
Write-Host "[StreamCore] Building frontend..."
|
||||
Push-Location $FrontendDir
|
||||
if (-not (Test-Path "node_modules")) { npm install }
|
||||
npm run build
|
||||
Pop-Location
|
||||
} else {
|
||||
Write-Warning "npm not found and frontend\dist is missing; the site will return 503."
|
||||
Write-Warning "Install Node.js and run: cd frontend; npm install; npm run build"
|
||||
}
|
||||
}
|
||||
|
||||
# MediaMTX, the transcoders and the HLS tree are managed by the backend itself:
|
||||
# it starts the media origin at boot, supervises ffmpeg, and restarts either if it
|
||||
# dies. This launcher only has to bring up the process that owns all of that.
|
||||
Write-Host "[StreamCore] Starting backend on ${HostAddress}:${BackendPort} ..."
|
||||
Write-Host "[StreamCore] MediaMTX, transcoders and HLS are supervised by the backend."
|
||||
Write-Host "[StreamCore] Frontend, MediaMTX, transcoders and HLS are served by the backend."
|
||||
|
||||
$backendArgs = @("-m", "uvicorn", "main:app", "--host", $HostAddress, "--port", "$BackendPort")
|
||||
& $Python @backendArgs
|
||||
Reference in new issue
Block a user