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

initial commit

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