diff --git a/development/stream_interface/create_dummy_streams.py b/development/stream_interface/create_dummy_streams.py deleted file mode 100644 index 83387f868..000000000 --- a/development/stream_interface/create_dummy_streams.py +++ /dev/null @@ -1,80 +0,0 @@ -import argparse -import os -import subprocess -import tempfile -from glob import glob -from threading import Thread -import yaml - - -CONFIG = {"protocols": ["tcp"], "paths": {"all": {"source": "publisher"}}} -BASE_STREAM_URL = "rtsp://localhost:8554/live" - - -def main(video_dir: str, n: int) -> None: - video_paths = glob(os.path.join(video_dir, "*.mp4")) + glob(os.path.join(video_dir, "*.webm")) - while len(video_paths) < n: - video_paths = video_paths * 2 - video_paths = video_paths[:n] - try: - with tempfile.TemporaryDirectory() as tmp_dir: - config_path = os.path.join(tmp_dir, "rtsp-simple-server.yml") - with open(config_path, "w") as f: - yaml.dump(CONFIG, f) - run_server(config_path=config_path) - threads = [] - for idx, video_path in enumerate(video_paths): - stream_url = f"{BASE_STREAM_URL}{idx}.stream" - print(f"Streaming {video_path} under {stream_url}") - threads.append( - stream_video(video_path=video_path, stream_url=stream_url) - ) - for t in threads: - t.join() - finally: - kill_server() - - -def run_server(config_path: str) -> None: - command = ( - f"docker run --rm --name rtsp_server -d -v {config_path}:/rtsp-simple-server.yml " - f"-p 8554:8554 aler9/rtsp-simple-server:v1.3.0" - ) - return_code = run_command(command=command.split()) - if return_code != 0: - raise RuntimeError("Could not run RTSP server!") - - -def kill_server() -> None: - run_command(command="docker kill rtsp_server".split()) - - -def stream_video(video_path: str, stream_url: str) -> Thread: - return run_command_in_thread( - command=f"ffmpeg -re -stream_loop -1 -i ".split() - + [f"{video_path}"] - + f"-f rtsp -rtsp_transport tcp {stream_url}".split() - ) - - -def run_command_in_thread(command: list) -> Thread: - thread = Thread(target=run_command, args=(command,)) - thread.start() - return thread - - -def run_command(command: list) -> int: - completed = subprocess.run(command) - return completed.returncode - - -if __name__ == "__main__": - parser = argparse.ArgumentParser("Script to run run dummy RTSP streams") - parser.add_argument( - "--video_dir", type=str, help="Directory with videos", required=True - ) - parser.add_argument( - "--n", type=int, help="Number of streams", required=False, default=6 - ) - args = parser.parse_args() - main(video_dir=args.video_dir, n=args.n) diff --git a/development/stream_interface/inference_pipeline_demo.py b/development/stream_interface/inference_pipeline_demo.py deleted file mode 100644 index a592a513b..000000000 --- a/development/stream_interface/inference_pipeline_demo.py +++ /dev/null @@ -1,161 +0,0 @@ -import argparse -import os -import subprocess -from datetime import datetime -from functools import partial -from threading import Thread -from typing import Optional, Union - -import cv2 -import numpy as np -import supervision as sv - -from inference.core.interfaces.camera.entities import VideoFrame -from inference.core.interfaces.stream.inference_pipeline import InferencePipeline -from inference.core.interfaces.stream.sinks import render_boxes, display_image, UDPSink, multi_sink -from inference.core.interfaces.stream.watchdog import ( - BasePipelineWatchDog, - PipelineWatchDog, -) -from inference.core.utils.environment import str2bool -from inference.core.utils.preprocess import letterbox_image - - -STOP = False - -MODELS = { - "a": "microsoft-coco/8", - "b": "microsoft-coco/9", - "c": "microsoft-coco/10", - "d": "microsoft-coco/11", - "e": "microsoft-coco/12", - "f": "eye-detection/39" -} - -STREAM_SERVER_URL = os.getenv("STREAM_SERVER", "rtsp://localhost:8554") -UDP_SERVER_HOST = os.getenv("UDP_SERVER_HOST", "127.0.0.1") -UDP_SERVER_PORT = int(os.getenv("UDP_SERVER_PORT", "9999")) - - -def main( - model_type: str, - stream_id: int, - max_fps: Optional[Union[int, float]], - enable_stats: bool, - output_type: str, -) -> None: - global STOP - watchdog = BasePipelineWatchDog() - ffmpeg_process = None - sinks = [] - if "video_stream" in output_type: - ffmpeg_process = open_ffmpeg_stream_process(stream_id=stream_id) - on_frame_rendered = partial(stream_prediction, ffmpeg_process=ffmpeg_process) - on_prediction = partial( - render_boxes, - display_statistics=enable_stats, - on_frame_rendered=on_frame_rendered, - ) - sinks.append(on_prediction) - if "udp_stream" in output_type: - udp_sink = UDPSink.init(ip_address=UDP_SERVER_HOST, port=UDP_SERVER_PORT) - on_prediction = udp_sink.send_predictions - sinks.append(on_prediction) - if "display" in output_type: - on_prediction = partial( - render_boxes, - display_statistics=enable_stats, - ) - sinks.append(on_prediction) - on_prediction = partial(multi_sink, sinks=sinks) - pipeline = InferencePipeline.init( - model_id=MODELS[model_type.lower()], - video_reference=f"{STREAM_SERVER_URL}/live{stream_id}.stream", - on_prediction=on_prediction, - max_fps=max_fps, - watchdog=watchdog, - ) - control_thread = Thread(target=command_thread, args=(pipeline, watchdog)) - control_thread.start() - pipeline.start() - STOP = True - pipeline.join() - if ffmpeg_process is not None: - ffmpeg_process.stdin.close() - ffmpeg_process.wait() - - -def stream_prediction(image: np.ndarray, ffmpeg_process: subprocess.Popen) -> None: - ffmpeg_process.stdin.write(image[:, :, ::-1].astype(np.uint8).tobytes()) - - -def open_ffmpeg_stream_process(stream_id: int) -> subprocess.Popen: - args = ( - "ffmpeg -re -stream_loop -1 -f rawvideo -pix_fmt " - "rgb24 -s 640x480 -i pipe:0 -pix_fmt yuv420p " - f"-f rtsp -rtsp_transport tcp {STREAM_SERVER_URL}/predictions{stream_id}.stream" - ).split() - return subprocess.Popen(args, stdin=subprocess.PIPE) - - -def command_thread(pipeline: InferencePipeline, watchdog: PipelineWatchDog) -> None: - global STOP - while not STOP: - key = input() - if key == "i": - print(watchdog.get_report()) - if key == "t": - pipeline.terminate() - STOP = True - elif key == "p": - pipeline.pause_stream() - elif key == "m": - pipeline.mute_stream() - elif key == "r": - pipeline.resume_stream() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser("Inference pipeline demo") - parser.add_argument( - "--model_type", - help=f"Type of a model from {list(MODELS.keys())}", - required=False, - type=str, - default="a", - ) - parser.add_argument( - "--stream_id", - help=f"Id of a stream", - required=True, - type=int, - ) - parser.add_argument( - "--max_fps", - help=f"Limit on FPS", - required=False, - type=int, - default=None, - ) - parser.add_argument( - "--enable_stats", - help=f"Flag to decide if stats to be displayed - pass 0 to disable", - required=False, - type=str2bool, - default=True, - ) - parser.add_argument( - "--output_type", - help=f"Flag to decide if output to be streamed or displayed on screen", - required=False, - type=str, - default="display", - ) - args = parser.parse_args() - main( - model_type=args.model_type, - stream_id=args.stream_id, - max_fps=args.max_fps, - enable_stats=args.enable_stats, - output_type=args.output_type, - ) diff --git a/development/stream_interface/stream_video.py b/development/stream_interface/stream_video.py deleted file mode 100644 index 0c1a33023..000000000 --- a/development/stream_interface/stream_video.py +++ /dev/null @@ -1,58 +0,0 @@ -import argparse -import os -import subprocess -from glob import glob -from threading import Thread - -BASE_STREAM_URL = "rtsp://localhost:8554/live" - - -def main(video_dir: str, n: int, id_offset: int) -> None: - video_paths = glob(os.path.join(video_dir, "*.mp4")) + glob(os.path.join(video_dir, "*.webm")) - print(video_paths) - while len(video_paths) < n: - video_paths = video_paths * 2 - video_paths = video_paths[:n] - threads = [] - for idx, video_path in enumerate(video_paths): - stream_url = f"{BASE_STREAM_URL}{id_offset + idx}.stream" - print(f"Streaming {video_path} under {stream_url}") - threads.append( - stream_video(video_path=video_path, stream_url=stream_url) - ) - for t in threads: - t.join() - - -def stream_video(video_path: str, stream_url: str) -> Thread: - return run_command_in_thread( - command=f"ffmpeg -re -stream_loop -1 -i ".split() - + [f"{video_path}"] - + f"-f rtsp -rtsp_transport tcp {stream_url}".split() - ) - - -def run_command_in_thread(command: list) -> Thread: - thread = Thread(target=run_command, args=(command,)) - thread.start() - return thread - - -def run_command(command: list) -> int: - completed = subprocess.run(command) - return completed.returncode - - -if __name__ == "__main__": - parser = argparse.ArgumentParser("Script to emit RTSP streams to RTSP server") - parser.add_argument( - "--video_dir", type=str, help="Directory with videos", required=True - ) - parser.add_argument( - "--n", type=int, help="Number of streams", required=False, default=6 - ) - parser.add_argument( - "--id_offset", type=int, help="Offset of stream_id", required=False, default=0, - ) - args = parser.parse_args() - main(video_dir=args.video_dir, n=args.n, id_offset=args.id_offset) diff --git a/docker/dockerfiles/Dockerfile.onnx.cpu b/docker/dockerfiles/Dockerfile.onnx.cpu index 4e300d6b8..23a88e297 100644 --- a/docker/dockerfiles/Dockerfile.onnx.cpu +++ b/docker/dockerfiles/Dockerfile.onnx.cpu @@ -3,7 +3,6 @@ FROM python:3.9 as base ARG DEBIAN_FRONTEND=noninteractive RUN apt update -y && apt install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.cpu.parallel b/docker/dockerfiles/Dockerfile.onnx.cpu.parallel index 1318783c8..bbfa70257 100644 --- a/docker/dockerfiles/Dockerfile.onnx.cpu.parallel +++ b/docker/dockerfiles/Dockerfile.onnx.cpu.parallel @@ -6,7 +6,6 @@ ARG DEBIAN_FRONTEND=noninteractive ARG TARGETPLATFORM RUN apt update -y && apt install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.cpu.slim b/docker/dockerfiles/Dockerfile.onnx.cpu.slim index c51fdaf3c..ddb5992be 100644 --- a/docker/dockerfiles/Dockerfile.onnx.cpu.slim +++ b/docker/dockerfiles/Dockerfile.onnx.cpu.slim @@ -4,7 +4,6 @@ ARG DEBIAN_FRONTEND=noninteractive ARG TARGETPLATFORM RUN apt update -y && apt install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.cpu.stream_manager b/docker/dockerfiles/Dockerfile.onnx.cpu.stream_manager index f6945c4b1..d1003dedf 100644 --- a/docker/dockerfiles/Dockerfile.onnx.cpu.stream_manager +++ b/docker/dockerfiles/Dockerfile.onnx.cpu.stream_manager @@ -5,7 +5,6 @@ WORKDIR /app ARG DEBIAN_FRONTEND=noninteractive RUN apt update -y && apt install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.gpu b/docker/dockerfiles/Dockerfile.onnx.gpu index 1d3d037d3..83bede9f2 100644 --- a/docker/dockerfiles/Dockerfile.onnx.gpu +++ b/docker/dockerfiles/Dockerfile.onnx.gpu @@ -3,7 +3,6 @@ FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 as base WORKDIR /app RUN rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.gpu.parallel b/docker/dockerfiles/Dockerfile.onnx.gpu.parallel index 44d8aeb15..f53b6622b 100644 --- a/docker/dockerfiles/Dockerfile.onnx.gpu.parallel +++ b/docker/dockerfiles/Dockerfile.onnx.gpu.parallel @@ -3,7 +3,6 @@ FROM nvcr.io/nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04 as base WORKDIR /app RUN rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.gpu.slim b/docker/dockerfiles/Dockerfile.onnx.gpu.slim index 41be637d7..ac983cfdc 100644 --- a/docker/dockerfiles/Dockerfile.onnx.gpu.slim +++ b/docker/dockerfiles/Dockerfile.onnx.gpu.slim @@ -3,7 +3,6 @@ FROM nvcr.io/nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04 as base WORKDIR /app RUN rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.gpu.stream_manager b/docker/dockerfiles/Dockerfile.onnx.gpu.stream_manager index ecdf9ee9a..561cc2aba 100644 --- a/docker/dockerfiles/Dockerfile.onnx.gpu.stream_manager +++ b/docker/dockerfiles/Dockerfile.onnx.gpu.stream_manager @@ -3,7 +3,6 @@ FROM nvcr.io/nvidia/cuda:11.4.2-cudnn8-runtime-ubuntu20.04 WORKDIR /app RUN rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.onnx.jetson.4.5.0 b/docker/dockerfiles/Dockerfile.onnx.jetson.4.5.0 index 21f7dd161..3b6fa882c 100644 --- a/docker/dockerfiles/Dockerfile.onnx.jetson.4.5.0 +++ b/docker/dockerfiles/Dockerfile.onnx.jetson.4.5.0 @@ -13,7 +13,6 @@ RUN apt-get update -y && apt-get upgrade -y && apt-get install -y \ gfortran \ build-essential \ libatlas-base-dev \ - ffmpeg \ libsm6 \ libxext6 \ wget \ diff --git a/docker/dockerfiles/Dockerfile.onnx.jetson.4.6.1 b/docker/dockerfiles/Dockerfile.onnx.jetson.4.6.1 index 6ad8751c1..a83a1ca2d 100644 --- a/docker/dockerfiles/Dockerfile.onnx.jetson.4.6.1 +++ b/docker/dockerfiles/Dockerfile.onnx.jetson.4.6.1 @@ -28,7 +28,6 @@ RUN apt-get update -y && apt-get upgrade -y && apt-get install -y \ gfortran \ build-essential \ libatlas-base-dev \ - ffmpeg \ libsm6 \ libxext6 \ wget \ diff --git a/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1 b/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1 index 2e2f5a3c4..877b30882 100644 --- a/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1 +++ b/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1 @@ -13,7 +13,6 @@ RUN apt-get update -y && apt-get install -y \ gfortran \ build-essential \ libatlas-base-dev \ - ffmpeg \ libsm6 \ libxext6 \ wget \ diff --git a/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1.stream_manager b/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1.stream_manager index 8c592227a..744160f7b 100644 --- a/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1.stream_manager +++ b/docker/dockerfiles/Dockerfile.onnx.jetson.5.1.1.stream_manager @@ -11,7 +11,6 @@ RUN apt-get update -y && apt-get install -y \ gfortran \ build-essential \ libatlas-base-dev \ - ffmpeg \ libsm6 \ libxext6 \ wget \ diff --git a/docker/dockerfiles/Dockerfile.onnx.lambda b/docker/dockerfiles/Dockerfile.onnx.lambda index f168c9fde..9ef86db9b 100644 --- a/docker/dockerfiles/Dockerfile.onnx.lambda +++ b/docker/dockerfiles/Dockerfile.onnx.lambda @@ -6,7 +6,6 @@ ARG DEBIAN_FRONTEND=noninteractive ARG TARGETPLATFORM RUN yum update -y && yum install -y \ - ffmpeg \ libsm6 \ libxext6 \ python3-pip \ diff --git a/docker/dockerfiles/Dockerfile.onnx.lambda.slim b/docker/dockerfiles/Dockerfile.onnx.lambda.slim index 86b5179ad..28d57ade0 100644 --- a/docker/dockerfiles/Dockerfile.onnx.lambda.slim +++ b/docker/dockerfiles/Dockerfile.onnx.lambda.slim @@ -5,7 +5,6 @@ ARG DEBIAN_FRONTEND=noninteractive ARG TARGETPLATFORM RUN yum update -y && yum install -y \ - ffmpeg \ libsm6 \ libxext6 \ python3-pip \ diff --git a/docker/dockerfiles/Dockerfile.onnx.trt b/docker/dockerfiles/Dockerfile.onnx.trt index 7a9158f19..c12d51f64 100644 --- a/docker/dockerfiles/Dockerfile.onnx.trt +++ b/docker/dockerfiles/Dockerfile.onnx.trt @@ -2,7 +2,6 @@ FROM nvcr.io/nvidia/tensorrt:22.12-py3 WORKDIR /app RUN apt-get update -y && apt-get install -y \ - ffmpeg \ libsm6 \ libxext6 \ libopencv-dev \ diff --git a/docker/dockerfiles/Dockerfile.onnx.udp.gpu b/docker/dockerfiles/Dockerfile.onnx.udp.gpu index 2f0f58ada..8698bcbec 100644 --- a/docker/dockerfiles/Dockerfile.onnx.udp.gpu +++ b/docker/dockerfiles/Dockerfile.onnx.udp.gpu @@ -3,7 +3,6 @@ FROM nvcr.io/nvidia/cuda:11.4.2-cudnn8-runtime-ubuntu20.04 WORKDIR /app RUN apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \ diff --git a/docker/dockerfiles/Dockerfile.stream_management_api b/docker/dockerfiles/Dockerfile.stream_management_api index b8c7c5e13..8ff63f0c1 100644 --- a/docker/dockerfiles/Dockerfile.stream_management_api +++ b/docker/dockerfiles/Dockerfile.stream_management_api @@ -5,7 +5,6 @@ WORKDIR /app ARG DEBIAN_FRONTEND=noninteractive RUN apt update -y && apt install -y \ - ffmpeg \ libxext6 \ libopencv-dev \ uvicorn \