Texture Tools Exporter Standalone - Batch Scripting / Command-line

What are all the supported batch commands for the Standalone exporter?

The examples provided in the announcement are lacking, particularly in terms of settings such as compression quality and mipmaps.

How do I convert an entire folder of PNGs to DDS at once?
Naming each specific PNG in the batch file is not really time-saving unless you are reconverting the same files.

Hi Snazz!

For all of the commands supported by the standalone exporter, run nvtt_export --help. This will print out all known command line options and flags, as well as a short description of each one.

Batch files contain a series of command lines to be run by nvtt_export - like calling the program multiple times, but without nvtt_export at the front. (As described in the announcement, this is faster than calling the program multiple times because it only has to launch once.)

At the moment, the batch file interface is targeted towards batch files that are automatically generated by a program you write. For instance, you might have some custom workflow that requires converting files multiple different ways, or combining nvtt_export with outputs from a different image processing program. So, at the moment, there aren’t any specialized commands in the standalone exporter for converting folders of files - but this is easier in the Photoshop version, and possible with a bit extra in the standalone version!

So, at the moment, the easiest way to convert an entire folder of PNGs without additional programming is to use the Photoshop plugin together with Photoshop Actions - for instance, by using Photoshop’s Automate > Batch… menu.

However, if you aren’t able to use the Photoshop plugin, here’s what a simple Python script to generate a batch file for all of the files in a folder looks like. If you have access to Python, you can pass this script the directory to convert (e.g. if this script were named convertPNGToDDSScript.py, you could run convertPNGToDDSScript.py C:\path\to\Pictures), and it’ll generate a file you can pass to nvtt_export --batch [name of batch file].

import os
import sys

dirName = sys.argv[1] # Get the name of the folder passed to this script
print(f'Creating batch script for directory {dirName}')

filesInDir = os.listdir(dirName) # Get all files in the directory
filesInDir = [f for f in filesInDir if f.lower().endswith('png')] # Get only PNG files
filesInDir = [os.path.join(dirName, f) for f in filesInDir] # Get absolute paths
filesInDir = [f for f in filesInDir if os.path.isfile(f)] # Ignore directories

outScript = open('convertPNGToDDS.nvtt', 'w') # Start a new script

for file in filesInDir:
  newFileName = file.rpartition('.')[0] + '.dds' # Replace .png with .dds
  outScript.write(f'{file} --format bc7 --output {newFileName}\n')

outScript.close()
print('Done')

Note that this could be shorter depending on the use case - this handles things like folders that end in “.png”, files with extensions like “.PNG”, and cases where the directory you run nvtt_export from is different from the directory in which the Python script was run, which might not always be necessary to handle.

Hope this helps!

2 Likes