CLI loop for multiple png sequences

Hi there -

Sorry if this is a silly request, or one that you think has been answered before, but I’ve not been able to find a complete answer anywhere, and I just want to make sure I get it right.

I’m running TVAI on a Windows machine.

I have about 100 shots rendered as png sequences in their respective folders that need upscaling 2x (using the Gaia CG model). “All” I want to do is write a CLI batch that does the following:

1 - loops through a list of renders (ideally that list would be in another txt file?)
2 - for each image sequence, apply the topaz model Gaia CG and upscales to 200%
3 - save each render as a png sequence in the same folder as the input sequence, but with the suffix “_upscaled”

This seems fairly easy to do but I’m the opposite of versed with CLI and was advised to reach out to the community by the support team!

Thanks in advance -

I just realised that I can copy the ffmpeg command straight from Topaz, so that part is easy I suppose, it’s only the loop part I’m not 100% sure how to achieve?

not sure either how you make the ouput name a suffixed name?

I can get you one step closer.

"G:\Program Files (x86)\SVP 4\utils\ffmpeg.exe" -framerate 23.976 -i "E:\title_t00_1920x1080_amq-13_png\%%6d.png" [add your TVAI filter command here] -c:v png -pix_fmt rgb24 "F:\title_t00_1920x1080_amq-13_png_upscaled\%%6d.png"

(Not actually sure if you need the -framerate)
With this, you’ll have to change all the paths to be correct. Like the first path needs to point to the TVAI ffmpeg.
You would also have to copy this line once you’ve got all the TVAI command added and change the folder paths for each folder you want to run.

I have a script that will create the output folders. The bat file will fail if you don’t create them first and I don’t know how to make them in a bat file. Maybe you can change _upscaled\%%6d.png to \upscaled_%%6d.png and put them in the same folder. I suppose you asked for \%%6d_upscaled.png that should work too, I just like having the numbers near the end. Anyway, I have not ran a command setup that way, so I’m not certain it will work.

Anyway, doing it this way, your bat file will run each line one by one. As in: it will wait for the first line to complete before starting on the second.

Hey there!

thanks for getting back to me - so I made a lot of progress on the matter actually - wrote a CLI loop that takes sequences from a text file and runs ffmpeg on them, and outputs them with a suffix:


@echo off

cd /d "C:\Program Files\Topaz Labs LLC\Topaz Video AI"
setlocal enabledelayedexpansion

rem Get the path to the directory containing this batch file
set batch_dir=%~dp0
echo %batch_dir%

REM rem Set the path to the text file containing the list of image sequence paths
set paths_file=%batch_dir%image_sequence_paths.txt

echo Encoding the following sequences:

FOR /F “tokens=* delims=” %%d in (%paths_file%) DO (
set “filepath=%%d”
for %%j in (“!filepath!”) do (

	set "filename=%%~nxj"
	REM echo !filename!
	set "shot_name=!filename:~0,-8!"
	REM echo !shot_name!
    set "indentation=!filename:~-8!"
	REM echo !indentation!
	
	set "output_filename=%%~dpj!shot_name!upscaled_!indentation!"
	echo !output_filename!


    rem Run FFmpeg to upscale the image sequence
    ffmpeg "-hide_banner" "-framerate" "24" "-start_number" "1" "-i" "%%j" "-sws_flags" "spline+accurate_rnd+full_chroma_int" "-color_trc" "2" "-colorspace" "0" "-color_primaries" "2" "-filter_complex" "tvai_up=model=gcg-5:scale=0:w=4740:h=2536:device=2:vram=1:instances=0,scale=w=4740:h=2536:flags=lanczos:threads=0" "-c:v" "png" "-pix_fmt" "rgb48be" "-metadata" "videoai=Enhanced using gcg-5. Changed resolution to 4740x2536" "-start_number" "1" "!output_filename!"
    
    rem Print a message to indicate progress
    echo Processed "%%j"
)

)

echo All PNG image sequences have been upscaled.

pause

BUT - I am getting the following error:

[Parsed_tvai_up_0 @ 000001A3CEA836C0] Model not found: gcg-5
[Parsed_tvai_up_0 @ 000001A3CEA836C0] Failed to configure output pad on Parsed_tvai_up_0
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0

which is… weird, because all models, including Gaia, are downloaded :confused:

the exact same settings for ffmpeg pasted into the console directly from Topaz work of course.

hmmm… I think the problem is that I haven’t defined the env_variables for the models folder and download folder…will investigate next week.

that was the issue, need to declare environment variables for TVAI_MODEL_DATA_DIR and TVAI_MODEL_DIR

1 Like