ahmedghani commited on
Commit
ca390ae
β€’
1 Parent(s): 8278bd0
Files changed (1) hide show
  1. video_convertor.py +1 -55
video_convertor.py CHANGED
@@ -2,60 +2,6 @@ import os
2
  from moviepy.editor import *
3
  from pydub import AudioSegment
4
 
5
- # class VideoConverter:
6
- # def __init__(self, input_file):
7
- # self.input_file = input_file
8
- # self.video = None
9
- # self.audio = None
10
-
11
- # if not os.path.exists(self.input_file):
12
- # raise FileNotFoundError(f"File not found: {self.input_file}")
13
-
14
- # self.load_video()
15
-
16
- # def load_video(self):
17
- # try:
18
- # self.video = VideoFileClip(self.input_file)
19
- # self.audio = self.video.audio
20
- # except Exception as e:
21
- # raise Exception(f"Error loading video: {e}")
22
-
23
- # def convert_video(self, output_file, format):
24
- # if format not in ['webm', 'wmv', 'mkv', 'mp4', 'avi', 'mpeg', 'vob', 'flv']:
25
- # raise ValueError(f"Unsupported format: {format}")
26
-
27
- # try:
28
- # self.video.write_videofile(output_file, codec=format.lower())
29
- # print(f"Video converted to {format} format successfully!")
30
- # return output_file
31
- # except Exception as e:
32
- # raise Exception(f"Error converting video: {e}")
33
-
34
-
35
- # def convert_audio(self, output_file, format):
36
- # if format not in ['mp3', 'wav', 'ogg', 'flac', 'aac']:
37
- # raise ValueError(f"Unsupported format: {format}")
38
-
39
- # try:
40
- # audio_segment = AudioSegment.from_file(self.input_file, self.audio.codec)
41
- # audio_segment.export(output_file, format=format.lower())
42
- # print(f"Audio converted to {format} format successfully!")
43
- # return output_file
44
- # except Exception as e:
45
- # raise Exception(f"Error converting audio: {e}")
46
-
47
- # def convert_video(input_file, format):
48
- # try:
49
- # converter = VideoConverter(input_file)
50
- # if format in ['webm', 'wmv', 'mkv', 'mp4', 'avi', 'mpeg', 'vob', 'flv']:
51
- # return None, converter.convert_video(f"output.{format}", format), "Converted video successfully!"
52
- # elif format in ['mp3', 'wav', 'ogg', 'flac', 'aac']:
53
- # return converter.convert_audio(f"output.{format}", format), None, "Converted audio successfully!"
54
- # else:
55
- # return None, None, "Unsupported format!"
56
- # except Exception as e:
57
- # return None, None, str(e)
58
-
59
  class VideoConverter:
60
  def __init__(self, input_file):
61
  self.input_file = input_file
@@ -81,7 +27,7 @@ class VideoConverter:
81
  raise ValueError(f"Unsupported format: {format}")
82
 
83
  try:
84
- self.video.write_videofile(output_file, codec=video_codecs[format.lower()])
85
  print(f"Video converted to {format} format successfully!")
86
  return output_file
87
  except Exception as e:
 
2
  from moviepy.editor import *
3
  from pydub import AudioSegment
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  class VideoConverter:
6
  def __init__(self, input_file):
7
  self.input_file = input_file
 
27
  raise ValueError(f"Unsupported format: {format}")
28
 
29
  try:
30
+ self.video.write_videofile(output_file, codec=video_codecs[format.lower()], threads=4)
31
  print(f"Video converted to {format} format successfully!")
32
  return output_file
33
  except Exception as e: