artificialguybr commited on
Commit
738eaed
·
1 Parent(s): 698dfc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -14,6 +14,8 @@ import torch
14
  import bitsandbytes
15
  import scipy
16
  from googletrans import Translator
 
 
17
 
18
  ZipFile("ffmpeg.zip").extractall()
19
  st = os.stat('ffmpeg')
@@ -31,13 +33,35 @@ whisper_model = WhisperModel("large-v2", device="cuda", compute_type="float16")
31
  print("cwd", os.getcwd())
32
  print(os.listdir())
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def process_video(Video, target_language):
35
  current_path = os.getcwd()
36
  print("Iniciando process_video")
37
  common_uuid = uuid.uuid4()
38
  print("Checking FFmpeg availability...")
39
  run(["ffmpeg", "-version"])
 
 
 
 
40
 
 
 
 
 
 
41
 
42
  audio_file = f"{common_uuid}.wav"
43
  run(["ffmpeg", "-i", Video, audio_file])
 
14
  import bitsandbytes
15
  import scipy
16
  from googletrans import Translator
17
+ import re
18
+ import subprocess
19
 
20
  ZipFile("ffmpeg.zip").extractall()
21
  st = os.stat('ffmpeg')
 
33
  print("cwd", os.getcwd())
34
  print(os.listdir())
35
 
36
+
37
+ def get_video_duration(video_path):
38
+ result = subprocess.run(["ffmpeg", "-i", video_path, "-hide_banner"], capture_output=True, text=True, stderr=subprocess.STDOUT)
39
+ output = result.stdout
40
+ match = re.search(r"Duration: (\d+:\d+:\d+.\d+)", output)
41
+ if match:
42
+ duration_str = match.group(1)
43
+ h, m, s = map(float, re.split('[:.]', duration_str))
44
+ duration = h * 3600 + m * 60 + s
45
+ return duration
46
+ else:
47
+ return None
48
+
49
  def process_video(Video, target_language):
50
  current_path = os.getcwd()
51
  print("Iniciando process_video")
52
  common_uuid = uuid.uuid4()
53
  print("Checking FFmpeg availability...")
54
  run(["ffmpeg", "-version"])
55
+ duration = get_video_duration(Video)
56
+ if duration is None:
57
+ print("Could not determine video duration.")
58
+ return None
59
 
60
+ # Check duration
61
+ if duration > 900:
62
+ print("Video is longer than 15 minutes.")
63
+ gr.Warning("Warning: Video is longer than 15 minutes.")
64
+ return None
65
 
66
  audio_file = f"{common_uuid}.wav"
67
  run(["ffmpeg", "-i", Video, audio_file])