- replace INPUT_RTSP_STREAMLINK and OUTPUT_RTSP_STREAMLINK with rtsp://yadayada
- pip install opencv-python numpy tqdm
- python process_rtsp_to_image.py
- bash publish_image_to_rtsp.sh
Last active
August 5, 2021 13:11
-
-
Save sloev/ba1b146fb927ae108d66fb8df155a060 to your computer and use it in GitHub Desktop.
rtsp -> python opencv -> rtsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| from threading import Thread | |
| import time | |
| import os | |
| class ThreadedCamera(object): | |
| def __init__(self, source = 0): | |
| self.capture = cv2.VideoCapture(source) | |
| self.thread = Thread(target = self.update, args = ()) | |
| self.thread.daemon = True | |
| self.thread.start() | |
| self.status = False | |
| self.frame = None | |
| def update(self): | |
| while True: | |
| if self.capture.isOpened(): | |
| (self.status, self.frame) = self.capture.read() | |
| def grab_frame(self): | |
| if self.status: | |
| return self.frame | |
| return None | |
| if __name__ == '__main__': | |
| stream_link = "INPUT_RTSP_STREAMLINK" | |
| streamer = ThreadedCamera(stream_link) | |
| while True: | |
| frame = streamer.grab_frame() | |
| if frame is not None: | |
| cv2.imwrite("input.tmp.jpg", frame) | |
| os.rename("input.tmp.jpg", "input.jpg") | |
| time.sleep(5) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ffmpeg -loop 1 -re -i "input.jpg" -b:v 0.256M -an -rtsp_transport tcp \ | |
| -vf drawtext="fontfile=monofonto.ttf: fontsize=20: box=1: [email protected]: boxborderw=5: fontcolor=white: x=(w-text_w-10): y=(h-text_h-10): text='processed\: %{gmtime\:%H\\\\\:%M\\\\\:%S}'" \ | |
| -vcodec libx264 -r 30 -f rtsp OUTPUT_RTSP_STREAMLINK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment