Path: blob/master/stream/video_upload.py
1089 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):19data = dict(mask_id=args.mask) if args.mask else None2021with open(image_path, "rb") as fp:22response = requests.post(args.sdk_url, files=dict(upload=fp), data=data)23if response.status_code < 200 or response.status_code > 300:24logging.error(response.text)25return None26else:27return response.json()282930@Gooey(program_name="Videos Uploader")31def main():32parser = GooeyParser(33description="Upload Videos from a folder to Stream file-upload"34)35parser.add_argument(36"folder", help="Folder containing videos to process.", widget="DirChooser"37)3839parser.add_argument(40"-m", "--mask", type=str, help="Camera Mask ID to use in the recognition."41)4243parser.add_argument(44"-s",45"--sdk-url",46default="http://localhost:8081",47help="Url to Stream File Upload Server",48)4950args = parser.parse_args()5152# Process files in folder53videos_directory = Path(args.folder)54with open("output.jsonl", "a") as outfile:55for file in videos_directory.iterdir():56if file.is_dir():57continue58logging.info(f"Processing file: {file}")59results = stream_api(file, args)60logging.info(f"Results:{results}")61if results:62json.dump(results, outfile)63outfile.write("\n")64outfile.flush()656667if __name__ == "__main__":68main()697071