SoFunction
Updated on 2024-11-19

Python on windows using ffmpeg to implement rtsp push streaming

rtsp pushstream

1、Download

rtsp server download URL:/aler9/rtsp-simple-server/releases

Windows environment select windows_amd64.zip file download

2、Configure environment variables

Take care of the newbies! Uh, never mind, everyone's a big shot~ skipped here

3. Initiation

There's nothing to it. Just double-click.

Command line startup:(command line start recommended)

After running is long this ghost, we have to pay attention to is the tcp port number, ok, the next step

I'm not sure if I'm going to be able to do that! vomit roar, and so on, and so on, careful friends may have found, the following is not a rtmp well ~ yes, congratulations on the discovery of a new continent! Back to a little to try it yourself oh.

4、Push flow

If you want to push out the local file to use the following command can be used, the parameters please adjust their own edible.

Push flow command:

ffmpeg -re -stream_loop -1 -i (your filename) -c copy -f rtsp rtsp://127.0.0.1:8554/video

A brief description of the parameters

  • -re is to read it as a stream.
  • -stream_loop -1 Indicates an infinite loop of reading.
  • -i is the input file.
  • -f Formatting where to output to

Of course we have another need:

Take the streams that are pulled in and process them before pushing them out.

Pull Stream ----- Processing ----- Push StreamHere it is basically the same as the rtmp push streaming method

It is necessary to put in the command

After -f, 'flv' is changed to 'rtsp'.

Just change rtmpurl to the rtsp pushstream address.

# Replace this with your own address
rtsp_url = 'rtsp://127.0.0.1:8554/video'
cap = (“streaming address”)
# Get video information
fps = int((cv2.CAP_PROP_FPS))
width = int((cv2.CAP_PROP_FRAME_WIDTH))
height = int((cv2.CAP_PROP_FRAME_HEIGHT))
command = ['ffmpeg',
               '-y',
               '-f', 'rawvideo',
               '-vcodec', 'rawvideo',
               '-pix_fmt', 'bgr24',
               '-s', "{}x{}".format(width, height),
               '-r', str(fps),
               '-i', '-',
               '-c:v', 'libx264',
               '-pix_fmt', 'yuv420p',
               '-preset', 'ultrafast',
               '-f', 'rtsp',
               rtsp_url]
p = (command, stdin=)
while (()):
    ret, frame = ()
    if not ret:
        print("Opening camera is failed")
        break
    frame = Functions for your image processing(frame)
    (())

5. Testing

Here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here, here.

import cv2
cap = ("rtsp://127.0.0.1:8554/video")
while (()):
    ret, frame = ()
    if not ret:
        print("Opening camera is failed")
        break
    ('Give me a name',frame)
    if (1) & 0xFF == ord('q'):
            break
()
()

Of course, if you don't want to write these lines of code either ~ I'll just have to teach you a little something else

VLC media player

Download Address:/vlc/

After running select media ---- network streaming ---- network ---- fill in the address (the address where rtsp just pushed the stream) ---- select playback

(Here's an easy way to do it, just ctrl+v the url directly after opening vlc and click OK)

Xunlei Video Newbie RecommendationsIf you just want to see if you can push the stream, use this to try it, more friendly to newbies, have Thunderbolt's direct use on the line, do not need to download and install the software again, but use it really not as good as vlc
Download address: forget about finding it yourself~

How to consume: Open it and enter the rtsp streaming address in the center box and you're done!

qq movie theaterUse the same Thunderbolt video...there's one for you!

Okay, it's done.

to this article on windows python ffmpeg rtsp push streaming article on this, more related python ffmpeg rtsp push streaming content, please search my previous posts or continue to browse the following related articles I hope that you will support me in the future more!