fix: use ffmpeg rtsp

This commit is contained in:
rendies 2023-01-18 16:47:12 +07:00
parent 695c5fe4a3
commit aedcb241dc
2 changed files with 22 additions and 4 deletions

View File

@ -41,6 +41,21 @@ def video_feed():
return Response(generate(), return Response(generate(),
mimetype = "multipart/x-mixed-replace; boundary=frame") mimetype = "multipart/x-mixed-replace; boundary=frame")
def open_ffmpeg_stream_process(height, width):
# args = (
# "ffmpeg -re -stream_loop -1 -f rawvideo -pix_fmt "
# "rgb24 -s 1920x1080 -i pipe:0 -pix_fmt yuv420p "
# "-f rtsp rtsp://172.23.90.205:8554/stream"
# ).split()
args = (
"ffmpeg -re -stream_loop -1 -f rawvideo -vcodec rawvideo -pix_fmt "
"rgb24 -s " + str(width) + "x" + str(height) + " -i pipe:0 -pix_fmt nv12 "
"-c:v libx264 -preset fast -crf 22 -bf 0 "
"-f rtsp -rtsp_transport tcp rtsp://172.17.2.39/counter"
).split()
return subprocess.Popen(args, stdin=subprocess.PIPE)
def PeopleCounter(): def PeopleCounter():
global outputFrame, lock, people_count global outputFrame, lock, people_count
# construct the argument parse and parse the arguments # construct the argument parse and parse the arguments
@ -110,7 +125,9 @@ def PeopleCounter():
if config.Thread: if config.Thread:
vs = thread.ThreadingClass(config.url) vs = thread.ThreadingClass(config.url)
ret, frame = vs.read()
height, width, ch = frame.shape
ffmpeg_process = open_ffmpeg_stream_process(height, width)
# loop over frames from the video stream # loop over frames from the video stream
while True: while True:
# grab the next frame and handle if we are reading from either # grab the next frame and handle if we are reading from either
@ -328,7 +345,8 @@ def PeopleCounter():
# show the output frame # show the output frame
with lock: with lock:
outputFrame = frame.copy() ffmpeg_process.stdin.write(frame.astype(np.uint8).tobytes())
# outputFrame = frame.copy()
# cv2.imshow("Real-Time Monitoring/Analysis Window", frame) # cv2.imshow("Real-Time Monitoring/Analysis Window", frame)
key = cv2.waitKey(1) & 0xFF key = cv2.waitKey(1) & 0xFF

View File

@ -5,14 +5,14 @@
# e.g., 'email@gmail.com' # e.g., 'email@gmail.com'
MAIL = '' MAIL = ''
# Enter the ip camera url (e.g., url = 'http://191.138.0.100:8040/video') # Enter the ip camera url (e.g., url = 'http://191.138.0.100:8040/video')
url = 'rtsp://admin:Asainfra333@172.17.0.60:554' url = 'rtsp://172.17.2.39/main'
# ON/OFF for mail feature. Enter True to turn on the email alert feature. # ON/OFF for mail feature. Enter True to turn on the email alert feature.
ALERT = False ALERT = False
# Set max. people inside limit. Optimise number below: 10, 50, 100, etc. # Set max. people inside limit. Optimise number below: 10, 50, 100, etc.
Threshold = 10 Threshold = 10
# Threading ON/OFF # Threading ON/OFF
Thread = False Thread = True
# Simple log to log the counting data # Simple log to log the counting data
Log = False Log = False
# Auto run/Schedule the software to run at your desired time # Auto run/Schedule the software to run at your desired time