Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you are looking solution in python, for RTSP Streaming with Gstreamer and FFmpeg, then you can use my powerful vidgear library that supports FFmpeg backend with its WriteGear API for writing to network. Also you can use its CamGear API for multi-threaded Gstreamer input thus boosting performance even more, the complete example is as follows:

# import required libraries
from vidgear.gears import CamGear
from vidgear.gears import WriteGear
import cv2

# Open gstreamer source
g_source = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1920, height=1080,format=NV12, framerate=30/1 ! 
 nvvidconv ! video/x-raw,format=I420 ! appsink"
stream = CamGear(source=g_source , logging=True).start() 

# define required FFmpeg parameters for your writer
output_params = {"-vcodec":"libx264","-profile:v":"main","-preset:v":"medium","-g":60,"-keyint_min":60,"-sc_threshold":0,"-b:v":"2500k","-maxrate":"2500k","-bufsize":"2500k", "-f":"flv"}

# Define writer with defined parameters
writer = WriteGear(output_filename = 'rstp://192.168.1.102:5000', logging =True, **output_params)

# loop over
while True:

    # read frames from stream
    frame = stream.read()

    # check for frame if Nonetype
    if frame is None:
        break


    # {do something with the frame here}


    # write frame to writer
    writer.write(frame)

    # Show output window
    cv2.imshow("Output Frame", frame)

    # check for 'q' key if pressed
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

# close output window
cv2.destroyAllWindows()

# safely close video stream
stream.stop()

# safely close writer
writer.close()

Docs: https://abhitronix.github.io/vidgear

If you are looking solution in python, for RTSP Streaming with Gstreamer and FFmpeg, then you can use my powerful vidgear library that supports FFmpeg backend with its WriteGear API for writing to network. Also you can use its CamGear API for multi-threaded Gstreamer input thus boosting performance even more, the complete example is as follows:

# import required libraries
from vidgear.gears import CamGear
from vidgear.gears import WriteGear
import cv2

# Open gstreamer source
g_source = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1920, height=1080,format=NV12, framerate=30/1 !  nvvidconv ! video/x-raw,format=I420 ! appsink"
stream = CamGear(source=g_source , CamGear(source=g_source, logging=True).start() 

# define required FFmpeg parameters for your writer
output_params = {"-vcodec":"libx264","-profile:v":"main","-preset:v":"medium","-g":60,"-keyint_min":60,"-sc_threshold":0,"-b:v":"2500k","-maxrate":"2500k","-bufsize":"2500k", {"-vcodec":"libx264","-profile:v":"main","-preset:v":"veryfast","-g":60,"-keyint_min":60,"-sc_threshold":0,"-b:v":"2500k","-maxrate":"2500k","-bufsize":"2500k", "-f":"flv"}

# Define writer with defined parameters
writer = WriteGear(output_filename = 'rstp://192.168.1.102:5000', logging =True, **output_params)

# loop over
while True:

    # read frames from stream
    frame = stream.read()

    # check for frame if Nonetype
    if frame is None:
        break


    # {do something with the frame here}


    # write frame to writer
    writer.write(frame)

    # Show output window
    cv2.imshow("Output Frame", frame)

    # check for 'q' key if pressed
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

# close output window
cv2.destroyAllWindows()

# safely close video stream
stream.stop()

# safely close writer
writer.close()

Docs: https://abhitronix.github.io/vidgear