File size: 1,866 Bytes
1425afc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | import threading
from queue import Queue
import uuid
import time
from .job_queue import jobs, update, notify_webhook
from .transcription import transcribe_video
from .render import render_video
from .highlights import detect_highlights
batch_queue = Queue()
def create_batch_job(video_path, webhook=None):
job_id = str(uuid.uuid4())
jobs[job_id] = {
"id": job_id,
"status": "queued",
"progress": 0,
"clips": [],
"video": video_path,
"webhook": webhook,
}
batch_queue.put(job_id)
return job_id
def worker():
while True:
job_id = batch_queue.get()
job = jobs[job_id]
try:
update(job_id, status="processing", progress=5)
# 1. TRANSCRIBE
words = transcribe_video(job["video"])
update(job_id, progress=30)
# 2. DETECT HIGHLIGHTS
highlights = detect_highlights(words)
update(job_id, progress=50)
outputs = []
# 3. RENDER MULTIPLE CLIPS
for i, segment in enumerate(highlights):
start = segment[0]["start"]
end = segment[-1]["end"]
clip_path = render_video(job["video"], words)
outputs.append(clip_path)
update(job_id, progress=50 + int((i+1)/len(highlights)*40))
# 4. FINALIZE
update(job_id,
status="completed",
progress=100,
clips=outputs)
notify_webhook(job_id)
except Exception as e:
update(job_id,
status="failed",
error=str(e))
notify_webhook(job_id)
batch_queue.task_done()
def start_batch_worker():
t = threading.Thread(target=worker, daemon=True)
t.start() |