Skip to content

Instantly share code, notes, and snippets.

@xCatG
Created January 26, 2024 23:51
Show Gist options
  • Save xCatG/36430f0fa3fb2e9c302789e2de274562 to your computer and use it in GitHub Desktop.
Save xCatG/36430f0fa3fb2e9c302789e2de274562 to your computer and use it in GitHub Desktop.
powerscript to use ffmpeg to stream all mp4 files from a dir
# PowerShell script for streaming MP4 files to YouTube using FFmpeg
# Define the directory containing your MP4 files
$VideoDir = Get-Location
# Your YouTube Stream Key
$StreamKey = "your youtube stream key"
# Infinite loop to keep the script running
while ($true) {
# Get all MP4 files in the directory
$VideoFiles = Get-ChildItem -Path $VideoDir -Filter *.mp4
# Loop through each video file
foreach ($VideoFile in $VideoFiles) {
Write-Host "Streaming: $($VideoFile.FullName)"
# Construct the FFmpeg command, with intel chipset in mind
$FFmpegCommand = "ffmpeg -report -init_hw_device qsv=hw -filter_hw_device hw -v verbose -hwaccel qsv -hwaccel_output_format qsv -re -i `"$($VideoFile.FullName)`" -c:v hevc_qsv -b:v 2500k -maxrate 3600k -bufsize 6000k -vf `"scale_qsv=w=1280:h=720`" -g 60 -look_ahead 1 -c:a copy -f flv -flvflags no_duration_filesize rtmp://a.rtmp.youtube.com/live2/$StreamKey"
# Execute the FFmpeg command
try {
Invoke-Expression $FFmpegCommand
} catch {
Write-Host "FFmpeg exited with an error. Attempting to restart streaming..."
# Additional error handling can be added here if needed
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment