skkalwar/video_encode
0
1import shutil2from fastapi.responses import JSONResponse3from fastapi.middleware.cors import CORSMiddleware4from fastapi import FastAPI, UploadFile, File, BackgroundTasks, Form5from typing import Optional6from wasabi_settings import settings7from db import db8 9from transcoder import process_transcoding_task10 11app = FastAPI()12 13# Allow CORS for all origins (adjust this in production)14app.add_middleware(15 CORSMiddleware,16 allow_origins=["*"], 17 allow_credentials=True,18 allow_methods=["*"],19 allow_headers=["*"],20)21 22 23@app.get("/")24async def root():25 return JSONResponse(26 content={"status": "ok", "message": "Btube Backend is running!"},27 status_code=20028 )29 30 31 32@app.post("/api/transcode")33async def transcode(34 background_tasks: BackgroundTasks,35 public_id: str = Form(...), 36 video_type: str = Form(...),37 location: str = Form(...),38 39):40 db.transcodequeue.insert_one({41 "public_id": public_id,42 "video_type": video_type,43 "status": "queued"44 })45 46 # Add background task47 background_tasks.add_task(process_transcoding_task, public_id, video_type, location)48 49 return JSONResponse(50 content={"status": "queued", "public_id": public_id, "message": "Transcoding started in background"},51 status_code=20052 )