Skip to content

Instantly share code, notes, and snippets.

@RozeFound
Created April 24, 2024 07:01
Show Gist options
  • Select an option

  • Save RozeFound/07ca6796a55278cb22be4b036d76719b to your computer and use it in GitHub Desktop.

Select an option

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
@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%
)
@RozeFound
Copy link
Author

RozeFound commented Apr 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment