Check whether output is smaller than input? (ffmpeg conversion with batch)
I’ve made a batch file that’s able to compress many png
files (with ffmpeg
) as well as remove any unneeded metadata (using exiftool
).
@echo off
title Compress png to png
color 08
FOR %%a IN (*.png) DO (
echo Compressing: %%~na
exiftool "%%a" -all= -overwrite_original
ffmpeg -i "%%a" "converted%%~na.png"
del "%%a"
)
This results in up to 60x smaller file sizes! (In small png icons at least)
Unfortunately sometimes the compression with ffmpeg
does not actually reduce file size, but rather increase it—especially when the image is larger—Which ruins the whole purpose of this process.
So I wonder whether there is a way to check the output (once compressed by ffmpeg
) and see whether it’s smaller in size than the input. And then act accordingly.
Like this…
@echo off
title Compress png to png
color 08
FOR %%a IN (*.png) DO (
echo Compressing: %%~na
exiftool "%%a" -all= -overwrite_original
ffmpeg -i "%%a" "converted%%~na.png"
CHECK: Is compressed file smaller in size than "%%a" ?
If not, then delete converted%%~na.png, and move* "%%a" in converted
If it is, then just delete "%%a"
del "%%a"
)
Download requires files, if you wanna test it and figure it out (22.7MB)
Also let me know whether there is a better way to do all this.
Read more here: Source link