Skip to content

Instantly share code, notes, and snippets.

@EvelynSubarrow
Created August 10, 2020 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvelynSubarrow/0645f5aa42e90327264e7e6148e9dee9 to your computer and use it in GitHub Desktop.
Save EvelynSubarrow/0645f5aa42e90327264e7e6148e9dee9 to your computer and use it in GitHub Desktop.
Vita video generator, ffmpeg/py37+
#!/usr/bin/env python3
import glob, os, os.path, argparse
parser = argparse.ArgumentParser()
parser.add_argument('fileglob')
args = parser.parse_args()
# The mapping selects all audio, then deselects all English language parts, selecting Japanese positively is harder
# Obviously this is only really useful for anime
globglogabgalab = glob.glob(args.fileglob)
for f in globglogabgalab:
fns = f
fss = f[:f.rfind(".")]
fnse = fns.replace("[", r"\[").replace("]", r"\]").replace(" ", r"\ ")
prefix = "vita/"
if os.path.exists(f"{prefix}{fss}.mp4"): continue
if fns[-3:]=="mkv":
subpath = fnse
substring = f',subtitles={subpath}'
elif os.path.exists(fnse[:-3] + "srt"):
subpath = fnse[:-3] + "srt"
substring = f',subtitles={subpath}'
else:
substring = ""
os.system(f"""ffmpeg \
-i "{fns}" \
-map v \
-map a -map -0:m:language:eng \
-vf "scale='-1':'min(ih,720)'{substring}" \
-crf 25 \
-vcodec libx264 -pix_fmt yuv420p \
-strict -2 \
-map_chapters -1 \
"{prefix}{fss}.mp4";""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment