Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start the server in the backgroud? #13

Open
pteran2403 opened this issue Feb 2, 2023 · 2 comments
Open

How to start the server in the backgroud? #13

pteran2403 opened this issue Feb 2, 2023 · 2 comments

Comments

@pteran2403
Copy link

Hi @prabhakar-sivanesan Awesome project,
I have a question, I noticed the RTSP stream only starts when a connection is made. For example, only starts when I connect to the stream via VLC and stops when I stop the stream (or close VLC).
How can I make the rtsp server run in the backgroud without having to open VLC?

I added the following line but doesn't seem to make a difference:
.set_state(Gst.State.PLAYING)

@prabhakar-sivanesan
Copy link
Owner

Hi @pteran2403,

You can run this python script to start the server and stearm the data. You can also run this as a system service or cron job in the backgroud.

@pteran2403
Copy link
Author

pteran2403 commented May 24, 2023

I am running it in the background as a service but I would like to keep the RTSP running in the background without the need of calling the rtsp. I know I have to so add a ( udpsrc port=5400 name=pay0 caps=\"application/x-rtp, media=video, clock-rate=90000, encoding-name=(string)H264, payload=96 \ but I dont know where to put my opencv injector code

I tried:

import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GLib, GObject
Gst.init([])


def create_rtsp_server():
    server = GstRtspServer.RTSPServer.new()
    server.set_property("service", "8554")
    server.attach(None)

    factory = GstRtspServer.RTSPMediaFactory.new()

    pipeline = "( udpsrc port=5400 name=pay0 caps=\"application/x-rtp, media=video, clock-rate=90000, encoding-name=(string)H264, payload=96 \" )"
    factory.set_launch(pipeline)
    factory.set_shared(True)
    server.get_mount_points().add_factory("/stream", factory)


def process_video(path):
    pipeline = Gst.parse_launch(f" filesrc location={path} \
                                ! decodebin \
                                ! nvvideoconvert \
                                ! nvv4l2h264enc \
                                ! h264parse \
                                ! rtph264pay \
                                ! udpsink host=127.0.0.1 port=5400 sync=true async=false ")

    create_rtsp_server()
    pipeline.set_state(Gst.State.PLAYING)
    loop = GLib.MainLoop.new(None, False)
    loop.run()


process_video("path/to/mp4/video.mp4")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants