Skip to content

Instantly share code, notes, and snippets.

@CoderCowMoo
Last active April 25, 2024 10:51
Show Gist options
  • Save CoderCowMoo/4c0bc9c537784ae1afda506bd18fc94b to your computer and use it in GitHub Desktop.
Save CoderCowMoo/4c0bc9c537784ae1afda506bd18fc94b to your computer and use it in GitHub Desktop.
# You take too many clips and its using up all your storage space?
# Don't know what to do?
# just save this file and make a .bat or shortcut file with the following content
# powershell.exe -NoExit -command "& 'C:\A path with spaces\watch_it.ps1' -filePath 'C:\Wherever you save videos'"
# you also have to edit below where the ffmpeg executable is.
# Geforce experience defaults to C:\Users\User\Videos
# This'll watch every directory there, and spawn a ffmpeg process for each video created,
param(
[Parameter(Mandatory=$true)][ValidateScript({ Test-Path -Path $_ })][string]$filePath
)
Function Register-Watcher {
param ($folder)
$filter = "*.*" #all files
$global:watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true
EnableRaisingEvents = $true
}
Register-ObjectEvent $Watcher -EventName "Created" -Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
# Exit if the created file has the ".processed" extension to avoid recursively applying.
if ($name.EndsWith(".processed")) {
Write-Host "Skipping file with .processed extension: $name"
return
}
$new_path = "$path.processed"
$filename = Split-Path $path -leaf
# I'm gonna have to do path manipulation here. I really dont want to.
$ArgumentList = "-i ""$path"" -c:v h264 -crf 27 -f mp4 -preset slow ""$new_path"""
# im better. I thought id have to but nah
Write-Host $ArgumentList
$proc = Start-Process -NoNewWindow -Wait -filePath "C:\ProgramData\chocolatey\bin\ffmpeg.exe" $ArgumentList
Write-Host """$new_path"""
Write-Host """$path"""
Write-Host """$filename"""
Write-Host "Renaming file: $new_path to $filename"
Move-Item -Path $new_path -Destination $path -Force
Write-Host "File renamed successfully: $filename"
Write-Host "Enabling watcher events..."
$watcher.EnableRaisingEvents = $true
}
}
Register-Watcher $filePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment