Update app.py
Browse files
app.py
CHANGED
@@ -104,14 +104,14 @@ def get_file_info(file_path):
|
|
104 |
logger.error(f"Error getting file info: {str(e)}")
|
105 |
return None
|
106 |
|
107 |
-
def
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
def process_media(file_path, is_url=False):
|
117 |
global generated_file, transcription_text
|
@@ -141,6 +141,8 @@ def process_media(file_path, is_url=False):
|
|
141 |
if not file_info:
|
142 |
return "Unable to process file: Could not determine file type", False
|
143 |
|
|
|
|
|
144 |
# Determine if it's audio or video
|
145 |
is_audio = any(stream['codec_type'] == 'audio' for stream in file_info['streams'])
|
146 |
is_video = any(stream['codec_type'] == 'video' for stream in file_info['streams'])
|
@@ -150,17 +152,21 @@ def process_media(file_path, is_url=False):
|
|
150 |
try:
|
151 |
if is_video:
|
152 |
# Extract audio from video
|
153 |
-
|
154 |
elif is_audio:
|
155 |
# Convert audio to WAV
|
156 |
-
|
157 |
else:
|
158 |
return "Unsupported file type: Neither audio nor video detected", False
|
159 |
|
|
|
|
|
160 |
logger.info(f"Audio extracted to WAV: {wav_path}")
|
161 |
except subprocess.CalledProcessError as e:
|
162 |
-
logger.error(f"FFmpeg conversion failed: {
|
163 |
-
|
|
|
|
|
164 |
|
165 |
# Chunk the audio file
|
166 |
audio = AudioSegment.from_wav(wav_path)
|
|
|
104 |
logger.error(f"Error getting file info: {str(e)}")
|
105 |
return None
|
106 |
|
107 |
+
def get_file_info(file_path):
|
108 |
+
try:
|
109 |
+
result = subprocess.run(['ffprobe', '-v', 'quiet', '-print_format', 'json', '-show_format', '-show_streams', file_path],
|
110 |
+
capture_output=True, text=True, check=True)
|
111 |
+
return json.loads(result.stdout)
|
112 |
+
except subprocess.CalledProcessError as e:
|
113 |
+
logger.error(f"Error getting file info: {str(e)}")
|
114 |
+
return None
|
115 |
|
116 |
def process_media(file_path, is_url=False):
|
117 |
global generated_file, transcription_text
|
|
|
141 |
if not file_info:
|
142 |
return "Unable to process file: Could not determine file type", False
|
143 |
|
144 |
+
logger.info(f"File info: {json.dumps(file_info, indent=2)}")
|
145 |
+
|
146 |
# Determine if it's audio or video
|
147 |
is_audio = any(stream['codec_type'] == 'audio' for stream in file_info['streams'])
|
148 |
is_video = any(stream['codec_type'] == 'video' for stream in file_info['streams'])
|
|
|
152 |
try:
|
153 |
if is_video:
|
154 |
# Extract audio from video
|
155 |
+
cmd = ['ffmpeg', '-i', temp_file, '-vn', '-acodec', 'pcm_s16le', '-ar', '44100', '-ac', '2', wav_path, '-v', 'verbose']
|
156 |
elif is_audio:
|
157 |
# Convert audio to WAV
|
158 |
+
cmd = ['ffmpeg', '-i', temp_file, '-acodec', 'pcm_s16le', '-ar', '44100', '-ac', '2', wav_path, '-v', 'verbose']
|
159 |
else:
|
160 |
return "Unsupported file type: Neither audio nor video detected", False
|
161 |
|
162 |
+
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
163 |
+
logger.info(f"FFmpeg command output: {result.stdout}")
|
164 |
logger.info(f"Audio extracted to WAV: {wav_path}")
|
165 |
except subprocess.CalledProcessError as e:
|
166 |
+
logger.error(f"FFmpeg conversion failed. Error output: {e.stderr}")
|
167 |
+
logger.error(f"FFmpeg command: {e.cmd}")
|
168 |
+
logger.error(f"Return code: {e.returncode}")
|
169 |
+
return f"FFmpeg conversion failed: {e.stderr}", False
|
170 |
|
171 |
# Chunk the audio file
|
172 |
audio = AudioSegment.from_wav(wav_path)
|