File size: 1,491 Bytes
d2542a3
 
 
6a6ee7b
d2542a3
 
 
 
 
 
 
 
 
 
6a6ee7b
d2542a3
6a6ee7b
 
 
 
 
 
 
 
 
 
 
d2542a3
 
6a6ee7b
 
d2542a3
 
 
6a6ee7b
d2542a3
 
 
 
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
from fastapi import APIRouter, UploadFile, File
from fastapi.responses import JSONResponse
from utils.file_utils import save_uploaded_file
from services.extractor import extract_frames, extract_features
from services.summarizer import get_scores, get_selected_indices, save_summary_video
from config import UPLOAD_DIR, OUTPUT_DIR

router = APIRouter()

@router.post("/summarize")
def summarize_video(video: UploadFile = File(...)):
    if not video.filename.lower().endswith(('.mp4', '.avi', '.mov', '.mkv')):
        return JSONResponse(content={"error": "Unsupported file format"}, status_code=400)

    print("\n-----------> Uploading Video ....")
    video_path = save_uploaded_file(video, UPLOAD_DIR)

    print("\n-----------> Extracting Frames ....")
    frames, picks = extract_frames(video_path)

    print("\n-----------> Extracting Features ....")
    features = extract_features(frames)

    print("\n-----------> Getting Scores ....")
    scores = get_scores(features)

    print("\n-----------> Selecting Indices ....")
    selected = get_selected_indices(scores, picks)
    output_path = f"{OUTPUT_DIR}/summary_{video.filename}"

    print("\n-----------> Saving Video ....")
    save_summary_video(video_path, selected, output_path)
    summary_url = f"/static/outputs/summary_{video.filename}"

    print("\n-----------> Returning Response ....")
    return JSONResponse(content={
        "message": "Summarization complete",
        "summary_video_url": summary_url
    })