Created
December 20, 2025 18:10
-
-
Save EdNutting/aafc9dad1be7c4e49f1fbe435a3bca5a to your computer and use it in GitHub Desktop.
PowerShell script to run FFmpeg as a local RTMP server, saving recordings to local files. Files saved into date-stamped folders, with incrementing file names. Automatically saves files and starts the server again - ideal for use with BlackMagic Atem Mini to record takes across a network. Uses MKV container file format to minimise risk of corrupt…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # rtmp-recorder.ps1 | |
| # Automatically records RTMP streams with NVENC HEVC encoding | |
| $OutputDir = "G:\Video\Recordings" # Change this to your preferred location | |
| $Port = 1935 | |
| $App = "live" | |
| $StreamKey = "stream" | |
| Write-Host "RTMP Recorder Started (NVENC HEVC)" -ForegroundColor Green | |
| Write-Host "Listening on rtmp://0.0.0.0:$Port/$App/$StreamKey" -ForegroundColor Cyan | |
| Write-Host "Press Ctrl+C to stop the recorder completely" -ForegroundColor Yellow | |
| Write-Host "" | |
| while ($true) { | |
| $dateFolder = Get-Date -Format "yyyy-MM-dd" | |
| $dayDir = Join-Path $OutputDir $dateFolder | |
| # Create date folder if it doesn't exist | |
| if (!(Test-Path $dayDir)) { | |
| New-Item -ItemType Directory -Path $dayDir | Out-Null | |
| Write-Host "Created folder: $dayDir" -ForegroundColor Magenta | |
| } | |
| # Find the next available number for today's folder | |
| $counter = 0 | |
| $existingFiles = Get-ChildItem -Path $dayDir -Filter "*.mkv" -ErrorAction SilentlyContinue | |
| foreach ($file in $existingFiles) { | |
| if ($file.BaseName -match '^\d+$') { | |
| $num = [int]$file.BaseName | |
| if ($num -ge $counter) { | |
| $counter = $num + 1 | |
| } | |
| } | |
| } | |
| $filename = Join-Path $dayDir ("{0:D3}.mkv" -f $counter) | |
| Write-Host "[$dateFolder/$counter] Waiting for stream..." -ForegroundColor Cyan | |
| ffmpeg -hide_banner -loglevel warning -listen 1 -i "rtmp://0.0.0.0:$Port/$App/$StreamKey" ` | |
| -c:v hevc_nvenc -preset p4 -cq 26 -rc vbr ` | |
| -c:a aac -b:a 128k ` | |
| $filename | |
| # Check if file was created and has content | |
| if (Test-Path $filename) { | |
| $size = (Get-Item $filename).Length | |
| if ($size -gt 0) { | |
| $sizeMB = [math]::Round($size / 1MB, 2) | |
| Write-Host "[$dateFolder/$counter] Saved: $filename ($sizeMB MB)" -ForegroundColor Green | |
| } else { | |
| Remove-Item $filename -ErrorAction SilentlyContinue | |
| Write-Host "[$dateFolder/$counter] No data received, removed empty file" -ForegroundColor Yellow | |
| } | |
| } | |
| Start-Sleep -Seconds 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment