Created
April 24, 2024 07:01
-
-
Save RozeFound/07ca6796a55278cb22be4b036d76719b to your computer and use it in GitHub Desktop.
Windows batch file to convert any image to AVIF image using nconvert and cavif
This file contains hidden or 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
| @echo off | |
| set FILENAME=%~p1%~n1 | |
| set EXT=%~x1 | |
| set FILENAME-WITH-EXT=%FILENAME%.png | |
| set QUALITY=16 | |
| IF NOT "%EXT%"==".png" ( | |
| nconvert -quiet -out png %FILENAME%%EXT% | |
| ) | |
| IF /I "%2"=="-l" ( | |
| set ARGS=--lossless | |
| ) ELSE ( | |
| set ARGS=--cpu-used 0 --bit-depth 8 --rate-control q --crf %QUALITY% --enable-full-color-range^ | |
| --bit-rate 0 --tune psnr --encoder-usage good --adaptive-quantization variance --enable-cdef --full-still-picture-header^ | |
| --row-mt --enable-rect-partitions --enable-ab-partitions --enable-1to4-partitions --enable-adaptive-quantization-b | |
| set ADD-ARGS= --profile 1 --pix-fmt yuv444 | |
| ) | |
| set ALPHA-FILENAME=%FILENAME%-alpha.avif | |
| cavif -i %FILENAME-WITH-EXT% -o %ALPHA-FILENAME% --encode-target alpha --monochrome %ARGS% | |
| IF EXIST %ALPHA-FILENAME% ( | |
| cavif -i %FILENAME-WITH-EXT% -o %FILENAME%.avif --encode-target image --attach-alpha %ALPHA-FILENAME% %ARGS% %ADD-ARGS% | |
| del %ALPHA-FILENAME% | |
| ) ELSE ( | |
| cavif -i %FILENAME-WITH-EXT% -o %FILENAME%.avif --encode-target image %ARGS% %ADD-ARGS% | |
| ) | |
| IF NOT "%EXT%"==".png" ( | |
| del %FILENAME-WITH-EXT% | |
| ) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nconvert: https://www.xnview.com/en/nconvert/
cavif: https://github.com/avif-community/cavif