mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-18 20:56:54 +02:00
debug(ffmpeg): add env HOME, high-visibility style, and detailed SRT logs
This commit is contained in:
1 parent
16435d499a
commit
80a13d02ae
1 file changed
+31
-20
+31
-20
@@ -20,42 +20,50 @@ API_KEY = os.environ.get("API_KEY", "default-key")
|
|||||||
TEMP_DIR = Path("/tmp/ffmpeg_processing")
|
TEMP_DIR = Path("/tmp/ffmpeg_processing")
|
||||||
TEMP_DIR.mkdir(parents=True, exist_ok=True)
|
TEMP_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# List available fonts for debugging
|
# Set HOME for libass/fontconfig to ensure cache can be written
|
||||||
|
os.environ["HOME"] = "/tmp"
|
||||||
|
|
||||||
|
# List available filters and fonts for debugging
|
||||||
try:
|
try:
|
||||||
|
print("📋 Checking FFmpeg environment...")
|
||||||
|
filters_out = subprocess.run(["ffmpeg", "-filters"], capture_output=True, text=True).stdout
|
||||||
|
has_subtitles = "subtitles" in filters_out
|
||||||
|
has_drawtext = "drawtext" in filters_out
|
||||||
|
print(f"✅ Filters found: subtitles={has_subtitles}, drawtext={has_drawtext}")
|
||||||
|
|
||||||
print("📋 Available fonts:")
|
print("📋 Available fonts:")
|
||||||
subprocess.run(["fc-list"], check=True)
|
subprocess.run(["fc-list"], check=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Failed to list fonts: {e}")
|
print(f"⚠️ Failed to check FFmpeg environment: {e}")
|
||||||
|
|
||||||
# Font path for text overlay (installed via fonts-dejavu in Dockerfile)
|
|
||||||
# Robust font detection
|
# Robust font detection
|
||||||
def get_font_path():
|
def get_font_path():
|
||||||
possible_paths = [
|
possible_paths = [
|
||||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||||
"/usr/share/fonts/truetype/dejavu-core/DejaVuSans.ttf",
|
"/usr/share/fonts/truetype/dejavu-core/DejaVuSans.ttf",
|
||||||
"/usr/share/fonts/TTF/DejaVuSans.ttf",
|
"/usr/share/fonts/TTF/DejaVuSans.ttf",
|
||||||
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
|
||||||
"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
|
|
||||||
]
|
]
|
||||||
for path in possible_paths:
|
for path in possible_paths:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
print(f"✅ Found font at: {path}")
|
print(f"✅ Found font at: {path}")
|
||||||
return path
|
return path
|
||||||
|
|
||||||
# Fallback: search anywhere in /usr/share/fonts
|
# Fallback search
|
||||||
print("⚠️ Specific font not found, searching recursively...")
|
print("⚠️ Specific font not found, searching recursively in /usr/share/fonts...")
|
||||||
try:
|
try:
|
||||||
|
found = []
|
||||||
for root, dirs, files in os.walk("/usr/share/fonts"):
|
for root, dirs, files in os.walk("/usr/share/fonts"):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(".ttf") and ("Sans" in file or "Arial" in file):
|
if file.endswith(".ttf"):
|
||||||
full_path = os.path.join(root, file)
|
found.append(os.path.join(root, file))
|
||||||
print(f"✅ Found fallback font at: {full_path}")
|
if found:
|
||||||
return full_path
|
print(f"✅ Found {len(found)} fonts, using first: {found[0]}")
|
||||||
|
return found[0]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Error searching for fonts: {e}")
|
print(f"⚠️ Error searching for fonts: {e}")
|
||||||
|
|
||||||
print("❌ No TTF font found! Text overlay may fail.")
|
print("❌ No TTF font found!")
|
||||||
return "font.ttf" # Hope for the best or let ffmpeg fail
|
return "Arial"
|
||||||
|
|
||||||
FONT_PATH = get_font_path()
|
FONT_PATH = get_font_path()
|
||||||
|
|
||||||
@@ -178,9 +186,14 @@ def generate_simple_srt(text: str, srt_path: Path):
|
|||||||
|
|
||||||
current_time += duration
|
current_time += duration
|
||||||
|
|
||||||
print(f"📄 Generated SRT content:\n{srt_content}")
|
print(f"📄 Generated {len(chunks)} SRT chunks. Content:\n{srt_content}")
|
||||||
with open(srt_path, "w", encoding="utf-8") as f:
|
with open(srt_path, "w", encoding="utf-8") as f:
|
||||||
f.write(srt_content)
|
f.write(srt_content)
|
||||||
|
|
||||||
|
if srt_path.exists():
|
||||||
|
print(f"✅ SRT file written: {srt_path.stat().st_size} bytes at {srt_path}")
|
||||||
|
else:
|
||||||
|
print(f"❌ Failed to write SRT file at {srt_path}")
|
||||||
|
|
||||||
|
|
||||||
def format_srt_time(seconds: float) -> str:
|
def format_srt_time(seconds: float) -> str:
|
||||||
@@ -446,19 +459,17 @@ async def process_reel(request: ReelRequest, x_api_key: str = Header(None)):
|
|||||||
text_filter = ""
|
text_filter = ""
|
||||||
if has_tts:
|
if has_tts:
|
||||||
# Subtitles (TikTok style) using SRT (already generated in TTS block)
|
# Subtitles (TikTok style) using SRT (already generated in TTS block)
|
||||||
# Force style to look like TikTok/Reels text
|
print(f"🎬 Overlaying subtitles from TTS SRT: {tts_srt_path}")
|
||||||
# We use DejaVu Sans exactly as listed in fc-list
|
style = f"FontName=DejaVu Sans,FontSize=120,PrimaryColour=&H0000FFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=3,Shadow=0,Bold=1,Alignment=2,MarginV=150"
|
||||||
style = f"FontName=DejaVu Sans,FontSize={request.font_size},PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=3,Shadow=0,Bold=1,Alignment=2,MarginV=300"
|
|
||||||
srt_path_str = str(tts_srt_path).replace("\\", "/").replace(":", "\\:")
|
srt_path_str = str(tts_srt_path).replace("\\", "/").replace(":", "\\:")
|
||||||
text_filter = f"subtitles='{srt_path_str}':force_style='{style}'"
|
text_filter = f"subtitles='{srt_path_str}':force_style='{style}'"
|
||||||
else:
|
else:
|
||||||
# Standard Text (without TTS)
|
# Standard Text (without TTS)
|
||||||
# We use subtitles filter here too because drawtext filter was reported missing
|
print(f"🎬 Overlaying subtitles from standard text: {request.text[:30]}...")
|
||||||
print("📝 Using subtitles filter for standard text overlay (fallback from drawtext)")
|
|
||||||
std_srt_path = job_dir / "std_text.srt"
|
std_srt_path = job_dir / "std_text.srt"
|
||||||
generate_simple_srt(request.text, std_srt_path)
|
generate_simple_srt(request.text, std_srt_path)
|
||||||
|
|
||||||
style = f"FontName=DejaVu Sans,FontSize={request.font_size},PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=3,Shadow=0,Bold=1,Alignment=2,MarginV=300"
|
style = f"FontName=DejaVu Sans,FontSize=120,PrimaryColour=&H0000FFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=3,Shadow=0,Bold=1,Alignment=2,MarginV=150"
|
||||||
srt_path_str = str(std_srt_path).replace("\\", "/").replace(":", "\\:")
|
srt_path_str = str(std_srt_path).replace("\\", "/").replace(":", "\\:")
|
||||||
text_filter = f"subtitles='{srt_path_str}':force_style='{style}'"
|
text_filter = f"subtitles='{srt_path_str}':force_style='{style}'"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user