Commit 0fc5705a authored by Sikhin VC's avatar Sikhin VC

initial commit

parent 618fbea6
...@@ -8,6 +8,7 @@ import time ...@@ -8,6 +8,7 @@ import time
import subprocess import subprocess
import threading import threading
class Item(BaseModel): class Item(BaseModel):
rtsp: str rtsp: str
name: str name: str
...@@ -15,22 +16,25 @@ class Item(BaseModel): ...@@ -15,22 +16,25 @@ class Item(BaseModel):
# price: float # price: float
# tax: Union[float, None] = None # tax: Union[float, None] = None
def background(f): def background(f):
''' '''
a threading decorator a threading decorator
use @background above the function you want to run in the background use @background above the function you want to run in the background
''' '''
def backgrnd_func(*a, **kw): def backgrnd_func(*a, **kw):
threading.Thread(target=f, args=a, kwargs=kw).start() threading.Thread(target=f, args=a, kwargs=kw).start()
return backgrnd_func return backgrnd_func
@background @background
def video_rec(item): def video_rec(item):
# size = (640, 480) # size = (640, 480)
working_dir = "videos" working_dir = "/home/administrator/aarti_violation_videos"
file_name = item["name"] + ".mp4" file_name = item["name"] + ".webm"
file_name = os.path.join(working_dir, file_name) file_name = os.path.join(working_dir, file_name)
print(file_name) print(file_name)
# Below VideoWriter object will create # Below VideoWriter object will create
...@@ -50,7 +54,7 @@ def video_rec(item): ...@@ -50,7 +54,7 @@ def video_rec(item):
size = (frame_width, frame_height) size = (frame_width, frame_height)
result = cv2.VideoWriter(file_name, result = cv2.VideoWriter(file_name,
cv2.VideoWriter_fourcc(*'avc1'), cv2.VideoWriter_fourcc('V', 'P', '8', '0'),
10, size) 10, size)
# cap = cv2.VideoCapture(item["rtsp"]) # cap = cv2.VideoCapture(item["rtsp"])
t1 = time.time() t1 = time.time()
...@@ -71,22 +75,20 @@ def video_rec(item): ...@@ -71,22 +75,20 @@ def video_rec(item):
video.release() video.release()
app = FastAPI() app = FastAPI()
@app.post("/items/") @app.post("/items/")
async def create_item(item: Item): async def create_item(item: Item):
# def video_write(self, frame, unique_id): # def video_write(self, frame, unique_id):
# frame_width = int(frame.shape[1]) # frame_width = int(frame.shape[1])
# frame_height = int(frame.shape[0]) # frame_height = int(frame.shape[0])
item = item.dict() item = item.dict()
video_rec(item) video_rec(item)
if __name__ == "__main__": if __name__ == "__main__":
from uvicorn import run from uvicorn import run
run(app, host="0.0.0.0", port=2328) run(app, host="192.168.3.181", port=2328)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment