File size: 1,594 Bytes
091117d
 
 
fba6e1e
091117d
5093bc2
 
 
091117d
fba6e1e
5093bc2
fba6e1e
 
 
 
 
 
2d729d2
fba6e1e
 
 
2d729d2
fba6e1e
825522e
091117d
 
 
0936f88
fba6e1e
0936f88
fba6e1e
0936f88
fba6e1e
091117d
 
 
5093bc2
fba6e1e
2a37377
fba6e1e
 
 
 
 
2a37377
 
5093bc2
fba6e1e
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
from vitpose import VitPose
import requests
import os
from config import API_URL,API_KEY
from fastapi import UploadFile
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def process_video(file_name: str,vitpose: VitPose,user_id: str,player_id: str):
    
    video_path = file_name

    contents = open(video_path, "rb").read()

    with open(video_path, "wb") as f:
        f.write(contents)
    
    logger.info(f"file saved {video_path}")
   
    logger.info(f"starting task {video_path}")
    
    new_file_name = os.path.join("static", video_path)
    logger.info(f"new file name {new_file_name}")
    
    vitpose.output_video_path = new_file_name
    annotated_frames = vitpose.run(video_path)
    
    vitpose.frames_to_video(annotated_frames)
    
    logger.info(f"Video processed {video_path}")
    
    with open(new_file_name, "rb") as f:
        contents = f.read()
        
    url = API_URL+ "/excercises/webhooks/video-processed"
    logger.info(f"Sending video to {url}")
    files = {"file": (video_path, contents, "video/mp4")}
    logger.info(f"video_path: {video_path}")
    response = requests.post(url, files=files, 
                             data={"user_id":user_id,"typeMessage":"video_processed","file_name":video_path,
                                   "player_id":player_id}, 
                             stream=True,
                             headers={"token":API_KEY})
    logger.info(f"Response: {response.status_code}")
    logger.info(f"Response: {response.text}")
    logger.info(f"Video sent to {url}")