Created
June 9, 2019 01:56
-
-
Save himkt/bde8349249b39bcfe0391f2a3d6157bd to your computer and use it in GitHub Desktop.
VOB 形式の動画を MOV 形式に変換するスクリプト
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 subprocess | |
import pathlib | |
BASE_COMMAND = 'ffmpeg -fflags +genpts -i {input}' | |
BASE_COMMAND += ' -c:a copy -c:v copy -threads 8 -sn -y {output}' | |
def load_arguments(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('root_dir') | |
parser.add_argument('--dry-run', action='store_true') | |
return parser.parse_args() | |
def traverse(base_dir): | |
return pathlib.Path(base_dir).glob('**/*.VOB') | |
def noop_or_create_dir(path): | |
path.parent.mkdir(parents=True, exist_ok=True) | |
def convert(input_file, output_file, dry_run): | |
command = BASE_COMMAND.format(input=input_file.as_posix(), | |
output=output_file.as_posix()) | |
if dry_run: | |
print(command) | |
else: | |
subprocess.call(command, shell=True) | |
def to_output_path(root_dir, path): | |
def decorate_dir(base_dir): | |
if base_dir[-1] != '/': | |
base_dir += '/' | |
return base_dir | |
root_dir_str = decorate_dir(root_dir) | |
output_path = path.as_posix().replace(root_dir_str, '') | |
output_path = output_path.replace('/', '_') | |
output_path = output_path.replace('.VOB', '.mov') | |
return pathlib.Path(output_path) | |
def main(): | |
args = load_arguments() | |
for input_path in traverse((args.root_dir)): | |
output_path = to_output_path(args.root_dir, input_path) | |
noop_or_create_dir(output_path) | |
convert(input_path, output_path, dry_run=args.dry_run) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment