Spaces:
Sleeping
Sleeping
Commit ·
4e5d552
1
Parent(s): a1f7a61
Add TheBoldFont, update caption styling, and fix atomic write
Browse files
static/fonts/TheBoldFont.ttf
ADDED
|
Binary file (15.4 kB). View file
|
|
|
video_creator/libraries/video_composer.py
CHANGED
|
@@ -185,7 +185,7 @@ class VideoComposer:
|
|
| 185 |
elif position == "center":
|
| 186 |
y_pos = height * 0.5
|
| 187 |
else: # bottom
|
| 188 |
-
y_pos = height * 0.85
|
| 189 |
|
| 190 |
for caption in captions:
|
| 191 |
start_time = caption["startMs"] / 1000
|
|
@@ -203,13 +203,18 @@ class VideoComposer:
|
|
| 203 |
try:
|
| 204 |
# Try caption method with fixed height to avoid NoneType error
|
| 205 |
# Allocating 20% of height for caption box
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
txt_clip = TextClip(
|
| 207 |
caption["text"],
|
| 208 |
fontsize=70,
|
| 209 |
color="white",
|
| 210 |
-
font=
|
| 211 |
stroke_color="black",
|
| 212 |
-
stroke_width=
|
| 213 |
bg_color=final_bg_color,
|
| 214 |
method="caption",
|
| 215 |
size=(int(width * 0.9), int(height * 0.2)),
|
|
@@ -222,7 +227,7 @@ class VideoComposer:
|
|
| 222 |
caption["text"],
|
| 223 |
fontsize=60,
|
| 224 |
color="white",
|
| 225 |
-
font=
|
| 226 |
stroke_color="black",
|
| 227 |
stroke_width=2,
|
| 228 |
bg_color=final_bg_color,
|
|
|
|
| 185 |
elif position == "center":
|
| 186 |
y_pos = height * 0.5
|
| 187 |
else: # bottom
|
| 188 |
+
y_pos = height * 0.70 # Changed from 0.85 to 0.70 as requested
|
| 189 |
|
| 190 |
for caption in captions:
|
| 191 |
start_time = caption["startMs"] / 1000
|
|
|
|
| 203 |
try:
|
| 204 |
# Try caption method with fixed height to avoid NoneType error
|
| 205 |
# Allocating 20% of height for caption box
|
| 206 |
+
|
| 207 |
+
# Use TheBoldFont.ttf
|
| 208 |
+
font_path = Path(__file__).parent.parent.parent / "static" / "fonts" / "TheBoldFont.ttf"
|
| 209 |
+
font_name = str(font_path) if font_path.exists() else "Liberation-Sans-Bold"
|
| 210 |
+
|
| 211 |
txt_clip = TextClip(
|
| 212 |
caption["text"],
|
| 213 |
fontsize=70,
|
| 214 |
color="white",
|
| 215 |
+
font=font_name,
|
| 216 |
stroke_color="black",
|
| 217 |
+
stroke_width=1.5,
|
| 218 |
bg_color=final_bg_color,
|
| 219 |
method="caption",
|
| 220 |
size=(int(width * 0.9), int(height * 0.2)),
|
|
|
|
| 227 |
caption["text"],
|
| 228 |
fontsize=60,
|
| 229 |
color="white",
|
| 230 |
+
font=font_name,
|
| 231 |
stroke_color="black",
|
| 232 |
stroke_width=2,
|
| 233 |
bg_color=final_bg_color,
|
video_creator/short_creator.py
CHANGED
|
@@ -182,24 +182,38 @@ class ShortCreator:
|
|
| 182 |
|
| 183 |
# Render final video
|
| 184 |
output_path = self.config.videos_dir_path / f"{video_id}.mp4"
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
# Cleanup temp files
|
| 198 |
for temp_file in temp_files:
|
| 199 |
if temp_file.exists():
|
| 200 |
temp_file.unlink()
|
| 201 |
-
|
| 202 |
-
logger.info(f"Video {video_id} created successfully at {output_path}")
|
| 203 |
|
| 204 |
def get_status(self, video_id: str) -> VideoStatus:
|
| 205 |
"""Get video processing status"""
|
|
|
|
| 182 |
|
| 183 |
# Render final video
|
| 184 |
output_path = self.config.videos_dir_path / f"{video_id}.mp4"
|
| 185 |
+
# Use a temp path for atomic write to prevent premature "ready" status
|
| 186 |
+
temp_output_path = self.config.videos_dir_path / f"{video_id}.tmp.mp4"
|
| 187 |
|
| 188 |
+
try:
|
| 189 |
+
VideoComposer.render(
|
| 190 |
+
scenes=scenes,
|
| 191 |
+
music_path=selected_music["path"],
|
| 192 |
+
output_path=temp_output_path,
|
| 193 |
+
orientation=orientation,
|
| 194 |
+
caption_position=config.captionPosition.value,
|
| 195 |
+
caption_bg_color=config.captionBackgroundColor,
|
| 196 |
+
music_volume=config.musicVolume.value,
|
| 197 |
+
padding_back=config.paddingBack
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
# Atomic rename to final path
|
| 201 |
+
if temp_output_path.exists():
|
| 202 |
+
temp_output_path.rename(output_path)
|
| 203 |
+
logger.info(f"Video {video_id} created successfully at {output_path}")
|
| 204 |
+
else:
|
| 205 |
+
raise Exception("Rendered file not found at temp path")
|
| 206 |
+
|
| 207 |
+
except Exception as e:
|
| 208 |
+
# Cleanup temp file on failure
|
| 209 |
+
if temp_output_path.exists():
|
| 210 |
+
temp_output_path.unlink()
|
| 211 |
+
raise e
|
| 212 |
|
| 213 |
# Cleanup temp files
|
| 214 |
for temp_file in temp_files:
|
| 215 |
if temp_file.exists():
|
| 216 |
temp_file.unlink()
|
|
|
|
|
|
|
| 217 |
|
| 218 |
def get_status(self, video_id: str) -> VideoStatus:
|
| 219 |
"""Get video processing status"""
|