Ffmpeg on OS-X unable to write to models directory - workaround

I’m using Topaz Video AI on OS-X, calling it via the ffmpeg command line from a bash script. It seems OS-X prevents write access the the ‘models’ directly that is inside the ‘Topaz Video AI.app’ in the system /Applications directory.

When running ffmpeg, the topaz filter may need to download new models and it will try and save them into that models directory, which fails. I was unable to find any way to get OS-X to let ffmpeg write to there. But I was able to find a workaround.

The filter can use the TVAI_MODEL_DATA_DIR and TVAI_MODEL_DIR environment variables to specify a different location for the models. Simply setting these fails since then the ffmpeg filter can’t find some additional files that are needed, like you’re product key. But if you ‘copy’ the models directory and set those variables, then it works as expected.

Instead of completely copying the somewhat large models directory, I create a tree of symbolic links from my new writable models directory (~/.topaz_cmdline_models) to the files in the OS-X app. This is a very fast and lightweight operation, so it can simply be run every time I run my script.

Anyway, so for others who find themselves in this same situation. Here is the bash code I include just above calling ffmpeg. I hope it’s useful:

# Set up writable models directory. Link-farm to the app's models directory
TVAI_APP_MODELS='/Applications/Topaz Video AI.app/Contents/MacOS/../Resources/models'
TVAI_USER_MODELS="$HOME/.topaz_cmdline_models"
(cd "$TVAI_APP_MODELS" ; find . -type f -print0) | while IFS= read -r -d '' filesubpath; do
    mkdir -p "$(dirname "$TVAI_USER_MODELS/$filesubpath")"
    ln -sf "$TVAI_APP_MODELS/$filesubpath" "$TVAI_USER_MODELS/$filesubpath"
done
# Exports to get Topaz to use custom models dir
export TVAI_MODEL_DATA_DIR="$TVAI_USER_MODELS"
export TVAI_MODEL_DIR="$TVAI_USER_MODELS"

nice "/Applications/Topaz Video AI.app/Contents/MacOS/ffmpeg" ....

It seems like an oversight that the default location of models and presets is not /Library/Application Support/Topaz (system install), or ~/Library/Application Support/Topaz (user install) which I believe is the recommended location for macOS. It seems weird that models are currently stored in the app package under /Applications/Topaz Video AI.app/Contents/Resources/models - app packages should not contain runtime-downloaded files or user-edited files. The app package should not really change after version install.

I believe that this would also reduce the need to re-download already installed models between upgrades.

Perhaps someone could correct me on this assumption?

I’ve tested and I do have non-sudo write permission from the terminal in either Application Support dir (root or ~), usual unix access permission allowing. So this looks like the correct solution for Topaz to do.

An alternative workaround could be to move ‘models’ into the correct place in Application Support and symlink it to where TVAI expects.

1 Like