Path: blob/master/stream/video_upload.py
641 views
import json1import logging2import os3import sys4from pathlib import Path56import requests7from gooey import Gooey, GooeyParser89LOG_LEVEL = os.environ.get("LOGGING", "INFO").upper()1011logging.basicConfig(12stream=sys.stdout,13level=LOG_LEVEL,14format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s",15)161718def stream_api(image_path, args):19if args.mask:20data = dict(mask_id=args.mask)21else:22data = None2324with open(image_path, "rb") as fp:25response = requests.post(args.sdk_url, files=dict(upload=fp), data=data)26if response.status_code < 200 or response.status_code > 300:27logging.error(response.text)28return None29else:30return response.json()313233@Gooey(program_name="Videos Uploader")34def main():35parser = GooeyParser(36description="Upload Videos from a folder to Stream file-upload"37)38parser.add_argument(39"folder", help="Folder containing videos to process.", widget="DirChooser"40)4142parser.add_argument(43"-m", "--mask", type=str, help="Camera Mask ID to use in the recognition."44)4546parser.add_argument(47"-s",48"--sdk-url",49default="http://localhost:8081",50help="Url to Stream File Upload Server",51)5253args = parser.parse_args()5455# Process files in folder56videos_directory = Path(args.folder)57with open("output.jsonl", "a") as outfile:58for file in videos_directory.iterdir():59if file.is_dir():60continue61logging.info(f"Processing file: {file}")62results = stream_api(file, args)63logging.info(f"Results:{results}")64if results:65json.dump(results, outfile)66outfile.write("\n")67outfile.flush()686970if __name__ == "__main__":71main()727374