Skip to content

Instantly share code, notes, and snippets.

@Mr-Z-2697
Last active June 5, 2022 17:07
Show Gist options
  • Save Mr-Z-2697/3254a4e37027229c8170e661bc1c0f9a to your computer and use it in GitHub Desktop.
Save Mr-Z-2697/3254a4e37027229c8170e661bc1c0f9a to your computer and use it in GitHub Desktop.
When something like Topaz Video Enhance AI outputs image sequences, keep watch the output folder and auto encode into pieces and delete images so besides some extra storage ios you will not be limited by its output formats(which is just kinda crap).
import os,sys
import pathlib
import subprocess
import time
rootd=pathlib.Path(__file__).parent.absolute()
os.chdir(rootd)
while True:
time.sleep(5)
files=list(rootd.glob('*.tif'))
filesb=[os.path.basename(str(n))[:-4] for n in files]
if len(filesb)>=120:
files=files[:120]
filesb=filesb[:120]
di=len(filesb[0])
si=filesb[0]
while si[0]=='0' and len(si)!=1:
si=si[1:]
si=int(si)
ei=si+120-1
ffc=f'ffmpeg -hide_banner -r 30000/1001 -start_number {si} -i "%0{di}d.tif" -frames 120 -vf zscale=m=709:c=0:d=error_diffusion:f=spline36:r=tv,format=yuv420p10le -crf 12 -c:v libx264 -x264opts colormatrix=bt709 "{si}-{ei}".hevc -y'
e=subprocess.run(ffc,shell=True)
if e.returncode!=0:
e=subprocess.run(ffc,shell=True)
for x in files:
os.remove(str(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment