Last active
September 18, 2019 04:18
-
-
Save itsdogtime/d6be4c72692d4c52d984531c7cfbd877 to your computer and use it in GitHub Desktop.
misc ffmpeg things
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
# -*- coding: utf-8 -*- | |
#!/usr/bin/python3 | |
import subprocess | |
import glob | |
import re | |
import os | |
_OUT_FOLDER = "processed/" | |
if not os.path.exists( _OUT_FOLDER ): | |
os.mkdir( _OUT_FOLDER ) | |
cmd = u" ".join([ | |
'ffmpeg', | |
'-i "%s"', | |
"-sub_charenc 'UTF-8'", | |
"-f srt ", | |
'-i "%s"', | |
"-c copy", | |
"-map 0:0", | |
"-map 0:1", | |
"-map 1:0", # Insert as first subtitle stream. | |
"-metadata:s:s:0 language=jpn", | |
"-metadata:s:s:0 title=Japanese", | |
"-map 0:2?", "-map 0:3?", "-map 0:4?", "-map 0:5?", # just in case | |
"-map 0:6?", "-map 0:7?", "-map 0:8?", "-map 0:9?", | |
"-map 0:10?", "-map 0:11?", "-map 0:12?", "-map 0:14?", | |
"-map 0:15?", "-map 0:16?", "-map 0:17?", "-map 0:18?", | |
"%s"]) | |
re_episode = re.compile( "s\d{2}e\d{2}", re.IGNORECASE ) | |
for v in glob.glob( "*.mkv" ): | |
# Skip files already done. | |
if os.path.exists( _OUT_FOLDER + v ): | |
print(v, "already in output folder. Skipping.") | |
continue | |
for s in glob.glob( "*.srt" ): | |
vid_episode = re_episode.search( v ) | |
srt_episode = re_episode.search( s ) | |
if vid_episode.group().lower() == srt_episode.group().lower(): | |
proc = subprocess.Popen( cmd % ( v, s, _OUT_FOLDER + v ), shell=True ) | |
proc.wait( ) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment