rtsp_fastapi icon indicating copy to clipboard operation
rtsp_fastapi copied to clipboard

If i want to stream multiple rtsp urls on a same web page in the form a grid how can i do that

Open hemantdawn opened this issue 1 year ago • 2 comments

hemantdawn avatar Nov 21 '23 06:11 hemantdawn

Hi @hemantdawn

Yes! There are some way to do that. In my case, I would change the variable "manager" to receive a empty dict like:

manager = {}

And you will need pass the number of each cam to receive the stream.

When you call the function video_feed, you need pass the cam on URL:

def streamer(cam_id):
    try:
        while manager[cam_id]:
            yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
                   bytearray(manager[cam_id].get()) + b'\r\n')
    except GeneratorExit:
        print("cancelled")

@app.get("/{cam_id}")
async def video_feed(cam_id: int):
    return StreamingResponse(streamer(cam_id), media_type="multipart/x-mixed-replace;boundary=frame")

See if these examples help. If you need more help, I can update the repo with a complete code.

mpimentel04 avatar Nov 23 '23 10:11 mpimentel04

Hi @hemantdawn

Yes! There are some way to do that. In my case, I would change the variable "manager" to receive a empty dict like:

manager = {}

And you will need pass the number of each cam to receive the stream.

When you call the function video_feed, you need pass the cam on URL:

def streamer(cam_id):
    try:
        while manager[cam_id]:
            yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
                   bytearray(manager[cam_id].get()) + b'\r\n')
    except GeneratorExit:
        print("cancelled")

@app.get("/{cam_id}")
async def video_feed(cam_id: int):
    return StreamingResponse(streamer(cam_id), media_type="multipart/x-mixed-replace;boundary=frame")

See if these examples help. If you need more help, I can update the repo with a complete code.

Hi @mpimentel04, can you please update the repo for this issue? Thank you.

kiennt120 avatar Dec 27 '23 19:12 kiennt120