Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,23 +118,83 @@ def process_video(video_file, language="hindi", progress=gr.Progress()):
|
|
| 118 |
|
| 119 |
print(f"SRT created: {srt_path} ({srt_size} bytes)")
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# Burn subtitles
|
| 122 |
progress(0.85, desc="Burning subtitles...")
|
| 123 |
output_path = os.path.join(temp_dir, "final.mp4")
|
| 124 |
|
| 125 |
print("Burning subtitles with FFmpeg...")
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
'ffmpeg', '-y',
|
| 130 |
'-i', video_file,
|
| 131 |
-
'-vf', f"subtitles={
|
| 132 |
'-c:a', 'copy',
|
| 133 |
'-c:v', 'libx264',
|
| 134 |
'-preset', 'medium',
|
| 135 |
'-crf', '23',
|
| 136 |
output_path
|
| 137 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
print(f"Video created: {output_path} ({os.path.getsize(output_path)} bytes)")
|
| 140 |
|
|
@@ -151,7 +211,6 @@ def process_video(video_file, language="hindi", progress=gr.Progress()):
|
|
| 151 |
full_text = " ".join([c['text'].strip() for c in result['chunks']])
|
| 152 |
|
| 153 |
status = f"""Processing Complete!
|
| 154 |
-
|
| 155 |
Statistics:
|
| 156 |
- Model: Whisper Large V3 Turbo
|
| 157 |
- Device: {device}
|
|
@@ -173,7 +232,7 @@ Files created successfully!
|
|
| 173 |
except subprocess.TimeoutExpired:
|
| 174 |
return None, None, "Processing timeout. Try a shorter video."
|
| 175 |
except subprocess.CalledProcessError as e:
|
| 176 |
-
error_detail = e.stderr.decode() if e.stderr else str(e)
|
| 177 |
return None, None, f"FFmpeg error: {error_detail}"
|
| 178 |
except Exception as e:
|
| 179 |
import traceback
|
|
@@ -265,4 +324,4 @@ if __name__ == "__main__":
|
|
| 265 |
share=False,
|
| 266 |
show_api=False,
|
| 267 |
show_error=True
|
| 268 |
-
)
|
|
|
|
| 118 |
|
| 119 |
print(f"SRT created: {srt_path} ({srt_size} bytes)")
|
| 120 |
|
| 121 |
+
# Read SRT content for debugging
|
| 122 |
+
with open(srt_path, 'r', encoding='utf-8-sig') as f:
|
| 123 |
+
srt_preview = f.read()[:500]
|
| 124 |
+
print(f"SRT preview:\n{srt_preview}")
|
| 125 |
+
|
| 126 |
# Burn subtitles
|
| 127 |
progress(0.85, desc="Burning subtitles...")
|
| 128 |
output_path = os.path.join(temp_dir, "final.mp4")
|
| 129 |
|
| 130 |
print("Burning subtitles with FFmpeg...")
|
| 131 |
|
| 132 |
+
# Fix: Escape the SRT path properly for FFmpeg
|
| 133 |
+
# Use absolute path and escape special characters
|
| 134 |
+
srt_path_escaped = srt_path.replace('\\', '/').replace(':', '\\:')
|
| 135 |
+
|
| 136 |
+
# Alternative approach: Use subtitles filter with proper escaping
|
| 137 |
+
ffmpeg_cmd = [
|
| 138 |
'ffmpeg', '-y',
|
| 139 |
'-i', video_file,
|
| 140 |
+
'-vf', f"subtitles={srt_path_escaped}:force_style='FontName=Noto Sans Devanagari,FontSize=24,Bold=1,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=2,Shadow=1'",
|
| 141 |
'-c:a', 'copy',
|
| 142 |
'-c:v', 'libx264',
|
| 143 |
'-preset', 'medium',
|
| 144 |
'-crf', '23',
|
| 145 |
output_path
|
| 146 |
+
]
|
| 147 |
+
|
| 148 |
+
print(f"FFmpeg command: {' '.join(ffmpeg_cmd)}")
|
| 149 |
+
|
| 150 |
+
try:
|
| 151 |
+
result = subprocess.run(
|
| 152 |
+
ffmpeg_cmd,
|
| 153 |
+
check=True,
|
| 154 |
+
capture_output=True,
|
| 155 |
+
text=True,
|
| 156 |
+
timeout=600
|
| 157 |
+
)
|
| 158 |
+
print(f"FFmpeg stdout: {result.stdout}")
|
| 159 |
+
print(f"FFmpeg stderr: {result.stderr}")
|
| 160 |
+
except subprocess.CalledProcessError as e:
|
| 161 |
+
print(f"FFmpeg failed!")
|
| 162 |
+
print(f"Return code: {e.returncode}")
|
| 163 |
+
print(f"Stdout: {e.stdout}")
|
| 164 |
+
print(f"Stderr: {e.stderr}")
|
| 165 |
+
|
| 166 |
+
# Try alternative method: ass filter instead
|
| 167 |
+
print("Trying alternative method with ass filter...")
|
| 168 |
+
|
| 169 |
+
# Convert SRT to ASS format (more reliable with FFmpeg)
|
| 170 |
+
ass_path = os.path.join(temp_dir, "subtitles.ass")
|
| 171 |
+
subprocess.run([
|
| 172 |
+
'ffmpeg', '-y',
|
| 173 |
+
'-i', srt_path,
|
| 174 |
+
ass_path
|
| 175 |
+
], check=True, capture_output=True)
|
| 176 |
+
|
| 177 |
+
if not os.path.exists(ass_path):
|
| 178 |
+
raise Exception(f"Failed to create ASS file at {ass_path}")
|
| 179 |
+
|
| 180 |
+
print(f"ASS file created: {ass_path}")
|
| 181 |
+
|
| 182 |
+
# Try again with ASS file
|
| 183 |
+
ass_path_escaped = ass_path.replace('\\', '/').replace(':', '\\:')
|
| 184 |
+
|
| 185 |
+
subprocess.run([
|
| 186 |
+
'ffmpeg', '-y',
|
| 187 |
+
'-i', video_file,
|
| 188 |
+
'-vf', f"ass={ass_path_escaped}",
|
| 189 |
+
'-c:a', 'copy',
|
| 190 |
+
'-c:v', 'libx264',
|
| 191 |
+
'-preset', 'medium',
|
| 192 |
+
'-crf', '23',
|
| 193 |
+
output_path
|
| 194 |
+
], check=True, capture_output=True, timeout=600)
|
| 195 |
+
|
| 196 |
+
if not os.path.exists(output_path):
|
| 197 |
+
return None, None, f"Output video was not created at: {output_path}"
|
| 198 |
|
| 199 |
print(f"Video created: {output_path} ({os.path.getsize(output_path)} bytes)")
|
| 200 |
|
|
|
|
| 211 |
full_text = " ".join([c['text'].strip() for c in result['chunks']])
|
| 212 |
|
| 213 |
status = f"""Processing Complete!
|
|
|
|
| 214 |
Statistics:
|
| 215 |
- Model: Whisper Large V3 Turbo
|
| 216 |
- Device: {device}
|
|
|
|
| 232 |
except subprocess.TimeoutExpired:
|
| 233 |
return None, None, "Processing timeout. Try a shorter video."
|
| 234 |
except subprocess.CalledProcessError as e:
|
| 235 |
+
error_detail = e.stderr.decode() if hasattr(e.stderr, 'decode') else str(e.stderr) if e.stderr else str(e)
|
| 236 |
return None, None, f"FFmpeg error: {error_detail}"
|
| 237 |
except Exception as e:
|
| 238 |
import traceback
|
|
|
|
| 324 |
share=False,
|
| 325 |
show_api=False,
|
| 326 |
show_error=True
|
| 327 |
+
)
|