Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -197,15 +197,15 @@ def process_video(video_file, language="hindi", subtitle_position="bottom-center
|
|
| 197 |
|
| 198 |
# Position mapping: alignment and vertical margin
|
| 199 |
POSITION_MAP = {
|
| 200 |
-
"top-left": (7,
|
| 201 |
-
"top-center": (8,
|
| 202 |
-
"top-right": (9,
|
| 203 |
"middle-left": (4, 0),
|
| 204 |
"middle-center": (5, 0),
|
| 205 |
"middle-right": (6, 0),
|
| 206 |
-
"bottom-left": (1,
|
| 207 |
-
"bottom-center": (2,
|
| 208 |
-
"bottom-right": (3,
|
| 209 |
}
|
| 210 |
|
| 211 |
alignment, margin = POSITION_MAP.get(subtitle_position, (2, 50))
|
|
@@ -269,28 +269,44 @@ def process_video(video_file, language="hindi", subtitle_position="bottom-center
|
|
| 269 |
# Modify ASS file to change subtitle position
|
| 270 |
print(f"\nModifying subtitle position to: {subtitle_position}...")
|
| 271 |
with open(ass_path, 'r', encoding='utf-8') as f:
|
| 272 |
-
|
| 273 |
|
| 274 |
-
#
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
-
|
|
|
|
| 291 |
|
| 292 |
with open(ass_path, 'w', encoding='utf-8') as f:
|
| 293 |
-
f.
|
| 294 |
|
| 295 |
print(f"✅ Subtitle position updated: {subtitle_position}")
|
| 296 |
|
|
|
|
| 197 |
|
| 198 |
# Position mapping: alignment and vertical margin
|
| 199 |
POSITION_MAP = {
|
| 200 |
+
"top-left": (7, 120), # Increased top margin
|
| 201 |
+
"top-center": (8, 120),
|
| 202 |
+
"top-right": (9, 120),
|
| 203 |
"middle-left": (4, 0),
|
| 204 |
"middle-center": (5, 0),
|
| 205 |
"middle-right": (6, 0),
|
| 206 |
+
"bottom-left": (1, 120), # Increased bottom margin
|
| 207 |
+
"bottom-center": (2, 120),
|
| 208 |
+
"bottom-right": (3, 120),
|
| 209 |
}
|
| 210 |
|
| 211 |
alignment, margin = POSITION_MAP.get(subtitle_position, (2, 50))
|
|
|
|
| 269 |
# Modify ASS file to change subtitle position
|
| 270 |
print(f"\nModifying subtitle position to: {subtitle_position}...")
|
| 271 |
with open(ass_path, 'r', encoding='utf-8') as f:
|
| 272 |
+
ass_lines = f.readlines()
|
| 273 |
|
| 274 |
+
# Find and modify the Style line
|
| 275 |
+
modified = False
|
| 276 |
+
for i, line in enumerate(ass_lines):
|
| 277 |
+
if line.startswith('Style: Default,'):
|
| 278 |
+
# Split the style line by commas
|
| 279 |
+
parts = line.strip().split(',')
|
| 280 |
+
|
| 281 |
+
# ASS Style format (0-indexed after "Style: Default,"):
|
| 282 |
+
# 0=Fontname, 1=Fontsize, 2=PrimaryColour, 3=SecondaryColour, 4=OutlineColour,
|
| 283 |
+
# 5=BackColour, 6=Bold, 7=Italic, 8=Underline, 9=StrikeOut, 10=ScaleX, 11=ScaleY,
|
| 284 |
+
# 12=Spacing, 13=Angle, 14=BorderStyle, 15=Outline, 16=Shadow, 17=Alignment,
|
| 285 |
+
# 18=MarginL, 19=MarginR, 20=MarginV, 21=Encoding
|
| 286 |
+
|
| 287 |
+
if len(parts) >= 22:
|
| 288 |
+
parts[18] = str(alignment) # Alignment (index 18 after "Style: Default,")
|
| 289 |
+
|
| 290 |
+
# Set horizontal margins for center-aligned subtitles
|
| 291 |
+
if 'center' in subtitle_position:
|
| 292 |
+
parts[19] = '50' # MarginL (left margin)
|
| 293 |
+
parts[20] = '50' # MarginR (right margin)
|
| 294 |
+
else:
|
| 295 |
+
parts[19] = '20' # MarginL
|
| 296 |
+
parts[20] = '20' # MarginR
|
| 297 |
+
|
| 298 |
+
parts[21] = str(margin) # MarginV (vertical margin)
|
| 299 |
+
|
| 300 |
+
ass_lines[i] = ','.join(parts) + '\n'
|
| 301 |
+
modified = True
|
| 302 |
+
print(f"✅ Modified style: Alignment={alignment}, MarginV={margin}")
|
| 303 |
+
break
|
| 304 |
|
| 305 |
+
if not modified:
|
| 306 |
+
print("⚠️ Warning: Could not find Style line to modify, using default position")
|
| 307 |
|
| 308 |
with open(ass_path, 'w', encoding='utf-8') as f:
|
| 309 |
+
f.writelines(ass_lines)
|
| 310 |
|
| 311 |
print(f"✅ Subtitle position updated: {subtitle_position}")
|
| 312 |
|