Compare commits

...
Author SHA1 Message Date
Andrew BeveridgeandClaude Opus 4.5 4826bbc48f fix: Add monitoring.metricWriter IAM role for GCE encoding worker
The Ops Agent on the encoding-worker VM was failing to send metrics
to Cloud Monitoring due to missing IAM permissions. This adds the
roles/monitoring.metricWriter role to the encoding-worker service account.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:40:33 -05:00
Andrew BeveridgeandClaude Opus 4.5 4c34417969 fix: Add custom font support to GCE preview encoding
- Backend extracts font GCS path from job.style_assets
- Encoding service passes font_gcs_path to GCE worker
- GCE worker downloads custom font and registers with fontconfig
- Fonts are stored in /usr/local/share/fonts/custom for libass to find

This ensures preview videos render with the correct custom fonts
when users have uploaded custom themes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:35:30 -05:00
Andrew BeveridgeandClaude Opus 4.5 b62e9af567 fix: Install fonts on GCE encoding worker for ASS rendering
FFmpeg's libass filter needs fonts installed on the system to render
ASS subtitles correctly. Adds:
- fonts-noto: Noto Sans (default karaoke font)
- fonts-noto-cjk: CJK character support
- fontconfig: Font configuration system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:32:58 -05:00
Andrew Beveridge ☄️ a4b8c21357 Merge branch 'main' into chore/enable-gce-preview-encoding 2026-01-05 14:32:06 -05:00
Andrew Beveridge ☄️ 2fe8923cdd Update pyproject.toml 2026-01-05 14:31:13 -05:00
Andrew BeveridgeandClaude Opus 4.5 7c52c16f36 fix: Pass background image to GCE preview encoding
Extracts karaoke background image from job.style_assets and passes
it to the GCE encoding worker so preview videos render with the
correct background styling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:27:59 -05:00
Andrew BeveridgeandClaude Opus 4.5 5e8d9172c7 fix: Handle cached preview responses from GCE worker
- GCE worker now returns "cached" status for already-encoded previews
  instead of 409 Conflict
- Backend encoding service handles cached response by returning
  immediately without polling
- Also handles "in_progress" status when another request is encoding

This fixes the issue where subsequent preview requests would hang
indefinitely because the backend raised an error on 409.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 14:25:19 -05:00
Andrew BeveridgeandClaude Opus 4.5 9f95daebd8 chore: Bump version to 0.91.1
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 13:17:11 -05:00
Andrew BeveridgeandClaude Opus 4.5 ed7c638680 chore: Enable USE_GCE_PREVIEW_ENCODING in production CI
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 13:15:15 -05:00
4 changed files with 78 additions and 3 deletions

No files matched your search

+19
View File
@@ -495,12 +495,31 @@ async def generate_preview_video(
bucket_name = settings.gcs_bucket_name
preview_gcs_path = f"jobs/{job_id}/previews/{preview_hash}.mp4"
# Get background image and font from style assets if available
style_assets = job.style_assets or {}
background_image_gcs_path = None
for key in ["karaoke_background", "style_karaoke_background"]:
if key in style_assets:
background_image_gcs_path = f"gs://{bucket_name}/{style_assets[key]}"
gce_span.set_attribute("background_image", background_image_gcs_path)
break
font_gcs_path = None
for key in ["font", "style_font"]:
if key in style_assets:
font_gcs_path = f"gs://{bucket_name}/{style_assets[key]}"
gce_span.set_attribute("font", font_gcs_path)
break
gce_result = await encoding_service.encode_preview_video(
job_id=f"preview_{job_id}_{preview_hash}",
ass_gcs_path=f"gs://{bucket_name}/{ass_gcs_path}",
audio_gcs_path=f"gs://{bucket_name}/{job.input_media_gcs_path}",
output_gcs_path=f"gs://{bucket_name}/{preview_gcs_path}",
background_color="black",
background_image_gcs_path=background_image_gcs_path,
font_gcs_path=font_gcs_path,
)
gce_span.set_attribute("gce_status", gce_result.get("status"))
add_span_event("gce_encoding_complete")
+18 -1
View File
@@ -255,6 +255,7 @@ class EncodingService:
output_gcs_path: str,
background_color: str = "black",
background_image_gcs_path: Optional[str] = None,
font_gcs_path: Optional[str] = None,
) -> Dict[str, Any]:
"""
Submit a preview video encoding job to the GCE worker.
@@ -266,6 +267,7 @@ class EncodingService:
output_gcs_path: GCS path for output video
background_color: Background color (default: black)
background_image_gcs_path: Optional GCS path to background image
font_gcs_path: Optional GCS path to custom font file
Returns:
Response from the encoding worker
@@ -289,6 +291,8 @@ class EncodingService:
}
if background_image_gcs_path:
payload["background_image_gcs_path"] = background_image_gcs_path
if font_gcs_path:
payload["font_gcs_path"] = font_gcs_path
logger.info(f"[job:{job_id}] Submitting preview encoding job to GCE worker: {url}")
@@ -312,6 +316,7 @@ class EncodingService:
output_gcs_path: str,
background_color: str = "black",
background_image_gcs_path: Optional[str] = None,
font_gcs_path: Optional[str] = None,
timeout: float = 90.0,
poll_interval: float = 2.0,
) -> Dict[str, Any]:
@@ -328,6 +333,7 @@ class EncodingService:
output_gcs_path: GCS path for output video
background_color: Background color (default: black)
background_image_gcs_path: Optional GCS path to background image
font_gcs_path: Optional GCS path to custom font file
timeout: Maximum time to wait (default 90s for preview)
poll_interval: Seconds between status checks (default 2s)
@@ -335,15 +341,26 @@ class EncodingService:
Final job status with output files
"""
# Submit the job
await self.submit_preview_encoding_job(
submit_result = await self.submit_preview_encoding_job(
job_id=job_id,
ass_gcs_path=ass_gcs_path,
audio_gcs_path=audio_gcs_path,
output_gcs_path=output_gcs_path,
background_color=background_color,
background_image_gcs_path=background_image_gcs_path,
font_gcs_path=font_gcs_path,
)
# If cached, return immediately - video already exists in GCS
submit_status = submit_result.get("status")
if submit_status == "cached":
logger.info(f"[job:{job_id}] Preview already cached, returning immediately")
return {"status": "complete", "output_path": submit_result.get("output_path")}
# If in_progress, another request is encoding it - just wait for that
if submit_status == "in_progress":
logger.info(f"[job:{job_id}] Preview encoding already in progress, waiting")
# Wait for completion with shorter timeout
return await self.wait_for_completion(
job_id=job_id,
+40 -1
View File
@@ -1168,6 +1168,14 @@ encoding_worker_logging_iam = gcp.projects.IAMMember(
member=encoding_worker_sa.email.apply(lambda email: f"serviceAccount:{email}"),
)
# Grant encoding worker monitoring permissions (for Ops Agent metrics)
encoding_worker_monitoring_iam = gcp.projects.IAMMember(
"encoding-worker-monitoring-access",
project=project_id,
role="roles/monitoring.metricWriter",
member=encoding_worker_sa.email.apply(lambda email: f"serviceAccount:{email}"),
)
# Static external IP for encoding worker (Cloud Run doesn't have VPC access by default)
encoding_worker_ip = gcp.compute.Address(
"encoding-worker-ip",
@@ -1189,6 +1197,13 @@ echo "Starting encoding worker setup at $(date)"
apt-get update
apt-get install -y python3-pip python3-venv docker.io curl git xz-utils
# Install fonts for ASS subtitle rendering (libass uses fontconfig)
# - fonts-noto: Noto Sans (default karaoke font)
# - fonts-noto-cjk: CJK character support
# - fontconfig: Font configuration system
apt-get install -y fonts-noto fonts-noto-cjk fontconfig
fc-cache -fv # Rebuild font cache
# Enable and start Docker
systemctl enable docker
systemctl start docker
@@ -1281,6 +1296,7 @@ class EncodePreviewRequest(BaseModel):
output_gcs_path: str # gs://bucket/path/to/output.mp4
background_color: str = "black"
background_image_gcs_path: Optional[str] = None
font_gcs_path: Optional[str] = None # gs://bucket/path/to/custom-font.ttf
class JobStatus(BaseModel):
@@ -1382,6 +1398,19 @@ def run_preview_encoding(job_id: str, work_dir: Path, request: "EncodePreviewReq
bg_image_path = work_dir / "background.png"
download_single_file_from_gcs(request.background_image_gcs_path, bg_image_path)
# Download custom font if provided and register with fontconfig
if request.font_gcs_path:
# Use standard fontconfig location that's already in the search path
fonts_dir = Path("/usr/local/share/fonts/custom")
fonts_dir.mkdir(parents=True, exist_ok=True)
font_filename = request.font_gcs_path.split("/")[-1]
font_path = fonts_dir / font_filename
download_single_file_from_gcs(request.font_gcs_path, font_path)
logger.info(f"Downloaded custom font: {font_path}")
# Update fontconfig cache so libass can find the font
subprocess.run(["fc-cache", "-fv"], capture_output=True)
logger.info(f"Updated fontconfig cache with custom font: {font_filename}")
# Build FFmpeg command
output_path = work_dir / "preview.mp4"
@@ -1658,8 +1687,18 @@ async def submit_preview_encode_job(request: EncodePreviewRequest, background_ta
# Submit a preview encoding job
job_id = request.job_id
# If job already exists, return cached result or current status
if job_id in jobs:
raise HTTPException(status_code=409, detail=f"Job {job_id} already exists")
existing_job = jobs[job_id]
if existing_job["status"] == "complete":
# Return cached result - preview already encoded
return {"status": "cached", "job_id": job_id, "output_path": existing_job.get("output_path")}
elif existing_job["status"] == "failed":
# Previous attempt failed, allow retry by replacing the job
pass
else:
# Job is still in progress
return {"status": "in_progress", "job_id": job_id}
jobs[job_id] = {
"job_id": job_id,
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.91.1"
version = "0.91.2"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"