Commit graph

9 commits

Author SHA1 Message Date
719946b3cd refactor/package-layout (#3)
All checks were successful
CI / backend-tests (push) Successful in 29s
CI / frontend-build (push) Successful in 9m48s
Reviewed-on: #3
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 20:47:12 +01:00
victormanuel.caverogracia
6e660d8f92 perf(pipeline): GPU cut, CPU VAD, cheap blur, hook+captions in one pass, 6 clip workers
Same clips to the eye (SSIM 0.990-0.9998 vs before, audio identical,
frames checked by eye), faster:
- Cut on the card end to end (NVDEC -> NVENC, hwaccel_output_format cuda)
  for 8-bit 4:2:0 h264/hevc/vp9/av1 sources; byte-identical decoded frames
  to the CPU cut, -64% CPU. Anything else, or a failed GPU cut, decodes on
  the CPU as before.
- Silero VAD on one CPU thread instead of CUDA (one 32 ms chunk per launch):
  transcription 2-3x faster (9 min audio: 28 -> 9 s). Over 3,939 words one
  changed ("claudio" -> "cloud", said "Claude") and a few times moved <=48 ms.
- The blurred backdrop is blurred at quarter size and scaled up
  (ffmpeg_utils.blurred_backdrop): ~45% less CPU on those segments.
- hooked_ and subtitled_ come out of ONE ffmpeg (hooks.add_hook_to_video
  also=...), one decode instead of two; subtitled_ is one generation fewer.
  Same filenames, so the editor's walk-back is unchanged. Falls back to the
  two passes if the combined one fails.
- CLIP_WORKERS default 3 -> 6: -14-16% wall per job at load 48-67, same CPU,
  peak VRAM 12 GB of 20.

Bench on balrog (3 Carlos Gracia videos, old/new side by side).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 20:28:22 +02:00
victormanuel.caverogracia
a4c92cac2c perf(pipeline): halve a job's CPU with byte-identical clips
Reverts 1d3d20c (NVDEC decode + quarter-size blur): it changed the
delivered pixels (SSIM 0.998-0.9997, not identical), and clips must not
change. Replaces it with two fixes that leave every clip byte-identical.

- Parakeet's onnxruntime pool threads no longer spin
  (transcribe_backends.parakeet_session_options). While the GPU did the
  work they burned ~160 CPU-s per 9 min of audio, the biggest CPU cost of
  a job. The VAD keeps load_vad's defaults: any options there make
  onnx_asr drop its default providers and a word changes.
- analyze_scenes_strategy and split_layout read their sampled frames in
  one forward pass (frame_sampler.read_at) instead of a seek per sample,
  which re-decoded the GOP every time: 89 -> 6 CPU-s for one clip's
  samples, same frames.

Bench on balrog, 3 Carlos Gracia videos (2.5/9/17 min, 15 clips), Gemini
decisions recorded once and replayed: every clip identical to the old
code (decoded-frame MD5s + audio). Serial stage profile of the 9 min
video: 629 -> 273 CPU-s per job; Python side 332 -> 57 CPU-s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:40:22 +02:00
victorcavero14
fdad2a46fa perf(asr): Parakeet peak VRAM 6.1 -> 4.6 GB with the same transcripts
Benchmarked in the prod container on 10 real user videos (40 min of audio,
EN/ES/PT/FR-AR, 4,850 words) before changing anything:

  config              peak VRAM  ASR time  words != prod  ts drift
  prod (batch 8)        6.1 GB     32 s        -             -
  batch 4 + lean arena  4.6 GB     38 s      1 (*)        0.1 ms
  batch 2 + lean arena  4.1 GB     40 s      dropped a sentence
  int8                  3.9 GB    350 s      11.7 %       168 ms

(*) outside the mixed-language clip, which goes to whisper in prod anyway.
Ship batch 4 with the arena growing only by what is requested and no max
cuDNN workspace (those two alone change nothing in the output).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 00:55:08 +02:00
victorcavero14
fed9395022 fix(gpu): stop jobs from filling the card (CUDA OOM at peak)
On 22-sep-2026 30-60% of jobs failed per hour at peak with 8 concurrent
jobs on a 20 GB GPU: a job three clips into its render still held 5.9 GB.

- main.py releases the ASR models right after transcribing (Parakeet's
  onnxruntime CUDA arena lived until the process exited); TransNetV2
  empties torch's cache after each pass.
- Host-wide cap on GPU transcriptions (flock slots on the shared output
  volume, ASR_HOST_SLOTS=2), across job processes and deploy containers.
- The queue only starts a job when nvidia-smi reports GPU_MIN_FREE_MB free
  (an idle card always starts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-22 22:42:52 +02:00
juancarlos.cavero
86bbc8b1cb fix(gpu): release the ASR models after a SaaSShorts transcription too
30 minutes after 60fa37a reached prod the uvicorn process held 5.1 GB of
VRAM again, with the release counter at zero: saasshorts.generate_tiktok_subs
transcribes in-process through its own call to transcribe_media, a third
path next to the thumbnail studio and the dubbed-subtitle one. Same
finally-release there, and release_models() now also drops the TransNetV2
singleton that the same in-process pipeline leaves in torch.
2026-09-21 03:56:59 +02:00
juancarlos.cavero
60fa37a969 fix(gpu,proxy): release ASR models in the API, probe one video not the playlist
Three failures measured in prod on 17-sep-2026, one deploy.

1. 5 of 12 jobs failed with "ffmpeg could not cut clip ... exit 187, 0 bytes".
   Exit 187 is AVERROR_EXIT after "h264_nvenc: Could not open encoder":
   VRAM was full. The uvicorn process itself held 7.7 GB of the 20 GB card
   while idle: the thumbnail studio and /api/subtitle on a dubbed clip
   transcribe in-process, and the whisper (ctranslate2) and parakeet
   (onnxruntime CUDA) singletons then lived in the API for good. Both call
   transcribe_backends.release_models() now; the loaders fetch their model
   inside the ASR gate so a release can never pull it from under a running
   transcription.

2. 26 of the 37 probes that reached the per-GB proxy in 10 days were
   `watch?v=X&list=...` or mix links. Neither the probe nor the download set
   `noplaylist`, so yt-dlp walked the whole list, died on its first private /
   age-gated / bot-checked entry (a video nobody pasted), the probe read it
   as an IP problem and paid the proxy to walk the same list again, and the
   user got a 400 for a valid link. Reproduced in the prod container: the
   same URL with noplaylist answers in 9.6 s on a static. The probe also
   keeps every attempt's error per route now, so the anonymous retry's
   bot-check cannot overwrite a "confirm your age" from the cookie attempt
   into an escalation.

3. noplaylist does nothing for a search or a bare playlist URL: one
   `results?search_query=` held the probe thread for 2220 s in the container
   and still failed. Search, playlist, channel and feed URLs are refused by
   path before any request, with a message that says what to paste.
2026-09-17 17:19:57 +02:00
juancarlos.cavero
b8159990a9 fix(transcribe): manejar vídeos sin audio + alerta de fallos honesta
El error del admin ('High download failure rate... rebuild image') era
engañoso: el fallo real no era descarga sino transcripción de un vídeo SUBIDO
sin pista de audio (un clip generado por IA, Gen-4 de Runway). faster-whisper
revienta dentro de libav con 'tuple index out of range' cuando el fichero no
tiene audio.

- transcribe_media detecta la ausencia de pista de audio (ffprobe) ANTES de
  transcribir y lanza NoAudioError con mensaje claro; main.py lo convierte en
  un fallo user-facing ('NO_AUDIO: este vídeo no tiene audio...') en vez de un
  traceback. Verificado en contenedor con vídeo con/sin audio.
- La alerta de tasa de fallos ya no culpa siempre a la descarga: clasifica el
  último error (proxy / youtube download / no audio / transcription / gemini /
  ffmpeg) y lo pone en el título.

123 tests (nuevos: vídeo mudo + clasificación de fallos).
2026-07-21 21:13:59 +02:00
juancarlos.cavero
719d444139 feat: GPU pipeline — Parakeet ASR backend with whisper fallback + NVENC encoder helper
- transcribe_backends.py: parakeet-tdt-0.6b-v3 (onnx-asr, VAD+timestamps) as
  selectable backend (TRANSCRIBE_BACKEND), token->word reconstruction keeping
  the leading-space convention, absolute timestamps, native floats, language
  detection via py3langid, and automatic whisper fallback (errors, empty
  output, or language outside parakeet's 25).
- whisper singleton + ASR GPU semaphore (model stays resident; GPU decodes
  serialized; CPU path behavior unchanged).
- ffmpeg_utils.py: central encoder args (FFMPEG_ENCODER=x264|nvenc|auto with
  cached probe + fallback); migrated the 9 hardcoded libx264 call sites.
- saasshorts now honors WHISPER_* config instead of hardcoded base/cpu/int8.
- Dockerfile: ARG GPU=1 installs CUDA user-space libs (cuBLAS/cuDNN9) +
  onnx-asr/onnxruntime-gpu; LD_LIBRARY_PATH + NVIDIA_DRIVER_CAPABILITIES.
- Validated on prod GPU (RTX 4000 Ada, driver 580): 94s clip transcribed in
  6.5s, word timestamps within ~0.1s of whisper, fallback path exercised.
2026-07-18 01:38:11 +02:00