Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement