Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import argparse
  2. import subprocess
  3. import pathlib
  4.  
  5.  
  6. BASE_COMMAND = 'ffmpeg -fflags +genpts -i {input}'
  7. BASE_COMMAND += ' -c:a copy -c:v copy -threads 8 -sn -y {output}'
  8.  
  9.  
  10. def load_arguments():
  11. parser = argparse.ArgumentParser()
  12. parser.add_argument('root_dir')
  13. parser.add_argument('--dry-run', action='store_true')
  14. return parser.parse_args()
  15.  
  16.  
  17. def traverse(base_dir):
  18. return pathlib.Path(base_dir).glob('**/*.VOB')
  19.  
  20.  
  21. def noop_or_create_dir(path):
  22. path.parent.mkdir(parents=True, exist_ok=True)
  23.  
  24.  
  25. def convert(input_file, output_file, dry_run):
  26. command = BASE_COMMAND.format(input=input_file.as_posix(),
  27. output=output_file.as_posix())
  28.  
  29. if dry_run:
  30. print(command)
  31. else:
  32. subprocess.call(command, shell=True)
  33.  
  34.  
  35. def to_output_path(root_dir, path):
  36. def decorate_dir(base_dir):
  37. if base_dir[-1] != '/':
  38. base_dir += '/'
  39. return base_dir
  40.  
  41. root_dir_str = decorate_dir(root_dir)
  42. output_path = path.as_posix().replace(root_dir_str, '')
  43. output_path = output_path.replace('/', '_')
  44. output_path = output_path.replace('.VOB', '.mov')
  45. return pathlib.Path(output_path)
  46.  
  47.  
  48. def main():
  49. args = load_arguments()
  50.  
  51. for input_path in traverse((args.root_dir)):
  52. output_path = to_output_path(args.root_dir, input_path)
  53. noop_or_create_dir(output_path)
  54. convert(input_path, output_path, dry_run=args.dry_run)
  55.  
  56.  
  57. if __name__ == '__main__':
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement