Tool Converting images to webp and videos to webm

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
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($_)}
the game I created this script for had a media folder 701MB, after conversion it was only 32mb with no noticeable loss

Notes;
  1. 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.
  2. GIF are considered images and will be converted to WebM witch is a video and your games will need video tags for these files.
  3. Please share improvements to the script, as I would like to see what improvements you come up with.
  4. Share this with others, I want to start seeing <100mb game files :D
 
Last edited:

toolkitxx

Well-Known Member
Modder
Donor
Game Developer
May 3, 2017
1,473
1,789
Why there is no thumbnail for webm videos in windows?
Thumbnails depend on which application you have set for opening those files. Almost no common application like VLC etc will create automatic thumnails for webm files.
 

s4msepi0l

Member
Jun 20, 2017
177
350
Tested this but there's no use for it since WebPy compresses it better (probably same image quality/size, but 10 times faster since it's multi threaded), and has extractor included so you don't have to use a different tool for that. I can set the quality to 90 on webPy and there'll be around 60% decrease in size with absolutely no decrease in quality.
 

gue5t

Active Member
Sep 11, 2016
594
1,029
... I can set the quality to 90 on webPy and there'll be around 60% decrease in size with absolutely no decrease in quality.
You are instructing the program to sacrifice the quality of the input file (25% of image quality by default) in order to save space and then claiming there is "absolutely no decrease in quality" in the output file? Just because you can't see the differences doesn't mean they aren't there ...

P.S. Also webPy doesn't work on video files.
 
Last edited:
  • Like
Reactions: toolkitxx

s4msepi0l

Member
Jun 20, 2017
177
350
You are instructing the program to sacrifice the quality of the input file (25% of image quality by default) in order to save space and then claiming there is "absolutely no decrease in quality" in the output file? Just because you can't see the differences doesn't mean they aren't there ...

P.S. Also webPy doesn't work on video files.
Wow you really got me there sherlock, obviously I meant no decrease in quality to the naked eye
 
Last edited:

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,268
22,310
Tried it, lots of files got corrupted file header:
You don't have permission to view the spoiler content. Log in or register now.
original folder:
You don't have permission to view the spoiler content. Log in or register now.
"optimized" folder:
You don't have permission to view the spoiler content. Log in or register now.
There's even one of the folders missing as you can see :unsure:
There are admittedly a lot of webm and webp files in the original already, but that might still be something you want to have a look at.

Got hundreds of those while running the script:
You don't have permission to view the spoiler content. Log in or register now.
 

gue5t

Active Member
Sep 11, 2016
594
1,029
Wow you really got me there sherlock, obviously I meant no decrease in quality to the naked eye
No offense but it seems you forgot to write the "that I can see" part of the sentence, please don't assume others will understand what you meant to say when you write something different from it and also don't assume that webp/webm is some kind of magic that can reduce the size of a file magically over two times without visual quality loss...

Here is a google dev quote for you (source: ):
WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index.
And here you can find an explanation of the compression process:
 
Last edited:

s4msepi0l

Member
Jun 20, 2017
177
350
No offense but it seems you forgot to write the "that I can see" part of the sentence, please don't assume others will understand what you meant to say when you write something different from it and also don't assume that webp/webm is some kind of magic that can reduce the size of a file magically over two times without visual quality loss...

Here is a google dev quote for you (source: ):

And here you can find an explanation of the compression process:
Your autism is showing a bit, tone it down sperg