ahmedghani commited on
Commit
fc72765
β€’
1 Parent(s): ea82e76

added codec

Browse files
__pycache__/video_convertor.cpython-38.pyc ADDED
Binary file (2.31 kB). View file
 
__pycache__/video_watermark_remover.cpython-38.pyc ADDED
Binary file (3.51 kB). View file
 
video_convertor.py CHANGED
@@ -2,6 +2,60 @@ 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
@@ -21,17 +75,18 @@ class VideoConverter:
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}")
 
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
 
75
  raise Exception(f"Error loading video: {e}")
76
 
77
  def convert_video(self, output_file, format):
78
+ video_codecs = {'webm': 'libvpx', 'wmv': 'wmv2', 'mkv': 'libx264', 'mp4': 'libx264', 'avi': 'libxvid', 'mpeg': 'mpeg2video', 'vob': 'mpeg2video', 'flv': 'flv'}
79
+
80
+ if format not in video_codecs:
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:
88
  raise Exception(f"Error converting video: {e}")
89
 
 
90
  def convert_audio(self, output_file, format):
91
  if format not in ['mp3', 'wav', 'ogg', 'flac', 'aac']:
92
  raise ValueError(f"Unsupported format: {format}")