-
-
Save xCatG/36430f0fa3fb2e9c302789e2de274562 to your computer and use it in GitHub Desktop.
powerscript to use ffmpeg to stream all mp4 files from a dir
This file contains 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
# 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