- Mar 16, 2018
- 17
- 11
I made a simple/ugly PowerShell script that utilizes FFmpeg to convert your media files to WebM/WebP, I'm not utilizing any arguments other than input/output and verbose reduction from FFmpeg. I recommend researching what additional arguments you could pass to FFmpeg.
download/install FFmpeg
create a new PowerShell (.ps1) in the parent directory to your content and paste this script
the game I created this script for had a media folder 701MB, after conversion it was only 32mb with no noticeable loss
Notes;
download/install FFmpeg
You must be registered to see the links
create a new PowerShell (.ps1) in the parent directory to your content and paste this script
Bash:
$inputDir = "images"
$outputDir = "optimized"
$copyOther = "true"
$localDir = Get-Location
$imageTypes = ".jpg", ".png", "webp"
$videoTypes = ".gif", ".mp4", ".webm"
$rep1 = Join-Path -Path $localDir -ChildPath $inputDir\
$rep2 = Join-Path -Path $localDir -ChildPath $outputDir\
function convertFile($file) {
$image = $imageTypes.Contains($file.Extension)
$video = $videoTypes.Contains($file.Extension)
$isDir = Test-Path $file.FullName -PathType Container
$newLoc = $file.FullName.Replace($rep1, $rep2)
if (-not $image -And -not $video -and -not $isDir -and $copyOther) {
Copy-Item -Path $file.FullName -Destination $newLoc
Write-Host "Copied" $file.FullName "to" $newLoc
}
if ($image -or $video) {
$newExt = ".webm"
if ($image) {
$newExt = ".webp"
}
New-Item -ItemType file -Path $newLoc.Replace($file.Extension, $newExt) -Force
Write-Host "Source:" $file.FullName
write-host "Output:" $newLoc.Replace($file.Extension, $newExt)
ffmpeg -hide_banner -loglevel warning -y -i $file.FullName $newLoc.Replace($file.Extension, $newExt)
}
}
Get-ChildItem -path $inputDir -Recurse | ForEach-Object -Process {convertFile($_)}
Notes;
- files that share a common name will overwrite, for example pills.jpg and pills.png will both become pills.webp and the last one to be processed will override the first.
- GIF are considered images and will be converted to WebM witch is a video and your games will need video tags for these files.
- Please share improvements to the script, as I would like to see what improvements you come up with.
- Share this with others, I want to start seeing <100mb game files
Last edited: