CamiloVega commited on
Commit
4e5d878
·
verified ·
1 Parent(s): 18391a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  from bs4 import BeautifulSoup
9
  import torch
10
  import whisper
11
- from moviepy.editor import VideoFileClip
12
  from pydub import AudioSegment
13
  import fitz
14
  import docx
@@ -192,13 +192,26 @@ def download_social_media_video(url):
192
  raise
193
 
194
  def convert_video_to_audio(video_file):
195
- """Convert a video file to audio."""
196
  try:
197
- video = VideoFileClip(video_file)
198
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_file:
199
- video.audio.write_audiofile(temp_file.name, verbose=False, logger=None)
200
- logger.info(f"Video converted to audio: {temp_file.name}")
201
- return temp_file.name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  except Exception as e:
203
  logger.error(f"Error converting video: {str(e)}")
204
  raise
 
8
  from bs4 import BeautifulSoup
9
  import torch
10
  import whisper
11
+ import subprocess
12
  from pydub import AudioSegment
13
  import fitz
14
  import docx
 
192
  raise
193
 
194
  def convert_video_to_audio(video_file):
195
+ """Convert a video file to audio using ffmpeg directly."""
196
  try:
 
197
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_file:
198
+ output_file = temp_file.name
199
+
200
+ # Use ffmpeg directly via subprocess
201
+ command = [
202
+ "ffmpeg",
203
+ "-i", video_file,
204
+ "-q:a", "0",
205
+ "-map", "a",
206
+ "-vn",
207
+ output_file,
208
+ "-y" # Overwrite output file if it exists
209
+ ]
210
+
211
+ subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
212
+
213
+ logger.info(f"Video converted to audio: {output_file}")
214
+ return output_file
215
  except Exception as e:
216
  logger.error(f"Error converting video: {str(e)}")
217
  raise