Advertisement
Rnery

Mass converter..

Dec 8th, 2023
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from os import path
  4. from subprocess import run
  5.  
  6.  
  7. class VideoConverter:
  8.     def __init__(self, input_directory: str, output_directory: str, output_format: str):
  9.         self.input_directory = input_directory
  10.         self.output_directory = output_directory
  11.         self.output_format = output_format
  12.  
  13.     def convert_video(self, input_file: str):
  14.         output_file = path.join(self.output_directory, path.basename(input_file))
  15.         command = ["ffmpeg", "-i", input_file, "-c:v", self.output_format, "-c:a", "copy", output_file]
  16.         run(command)
  17.  
  18.  
  19. def main():
  20.     input_directory = "/path/to/input/videos"
  21.     output_directory = "/path/to/output/videos"
  22.     output_format = "mp4"
  23.  
  24.     video_converter = VideoConverter(input_directory, output_directory, output_format)
  25.     for input_file in os.listdir(video_converter.input_directory):
  26.         video_converter.convert_video(path.join(video_converter.input_directory, input_file))
  27.  
  28.  
  29. if __name__ == "__main__":
  30.     main()
Tags: python python3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement