Last active
April 15, 2022 08:29
-
-
Save autch/6c30693255e1d3e070a7d11c62eb0e73 to your computer and use it in GitHub Desktop.
Fix FOV distortion in VRChat camera, inspired from https://gist.github.com/chigirits/55d6eed4396ed5da64878af2b43111ed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import functools | |
import glob | |
import itertools | |
import multiprocessing as mp | |
import os | |
import os.path | |
import subprocess | |
import sys | |
def convert_mapper(args, infile): | |
k = float(args.fov) / 60.0 | |
k2 = (k - k**3) / 6.0 | |
k4 = k | |
base, ext = os.path.splitext(infile) | |
outfile = base + f".fov{args.fov}" + ext | |
if os.path.exists(outfile): | |
print(f"File {outfile} already exists, skipping", file=sys.stderr) | |
return None | |
cmdline = [args.convert, infile, "-distort", | |
"barrel", f"0 {k2} 0 {k4}", outfile] | |
print(cmdline) | |
subprocess.run(cmdline) | |
return True | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--fov', '-f', help='target FOV', type=int, default=50) | |
parser.add_argument('--fov-from', '-F', | |
help='convert from FOV', type=int, default=60) | |
parser.add_argument('--convert', '-c', | |
help='path to convert(1)', default="convert") | |
parser.add_argument('files', type=str, nargs='+', help='files to process') | |
parser.add_argument('--jobs', '-j', help='num of concurrent convert(1)s', | |
type=int, default=os.cpu_count()) | |
args = parser.parse_args() | |
with mp.Pool(processes=args.jobs) as pool: | |
list(pool.imap_unordered(functools.partial(convert_mapper, args), | |
itertools.chain.from_iterable( | |
[glob.iglob(f) for f in args.files]), | |
)) | |
if __name__ == '__main__': | |
mp.freeze_support() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment