0

No Stream content when view from rtsp player.

  • I have captured screen using python mss,

  • converted to opencv frame and trying to live stream using gstreamer

  • ffplay rtsp://127.0.0.1:8554/test doesnot play any stream neither gives any error.

  • I have found similar examples with inputs from rtsp camera and local video file.Write opencv frames into gstreamer rtsp server pipeline

#!/usr/bin/env python3

import cv2
import gi
import mss
import numpy as np

gi.require_version("Gst", "1.0")
gi.require_version("GstRtspServer", "1.0")
from gi.repository import Gst, GstRtspServer, GObject



class SensorFactory(GstRtspServer.RTSPMediaFactory):
****

def on_need_data(self, src, lenght):
    monitor = {"top": 120, "left": 280, "width": 640, "height": 480}
    
    with mss.mss() as sct:
        while True:
            grab = sct.grab(monitor)
            img = np.array(grab)
            img = cv2.resize(img, (640, 480))
            # frame = img
            frame = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            data = frame.tostring()
            buf = Gst.Buffer.new_allocate(None, len(data), None)
            buf.fill(0, data)
            buf.duration = self.duration
            timestamp = self.number_frames * self.duration
            buf.pts = buf.dts = int(timestamp)
            buf.offset = timestamp
            self.number_frames += 1
            retval = src.emit("push-buffer", buf)
            print(
                "pushed buffer, frame {}, duration {} ns, durations {} s".format(
                    self.number_frames, self.duration, self.duration / Gst.SECOND
                )
            )
            if retval != Gst.FlowReturn.OK:
                print(retval)

    def do_create_element(self, url):
        ****
    def do_configure(self, rtsp_media):
        ****


    class GstServer(GstRtspServer.RTSPServer):
        ****
Amulya Acharya
  • 701
  • 14
  • 17
  • what are you doing? what is the server? are you making your own rtsp server, or are you only trying to read from a server? your code doesn't show that. if ffplay can't do it, the issue is with the server or the network. – Christoph Rackwitz Jul 14 '21 at 11:36
  • @ChristophRackwitz I am just changing source of streaming from camera to mss screenshorts https://stackoverflow.com/questions/47396372/write-opencv-frames-into-gstreamer-rtsp-server-pipeline?rq=1 – Amulya Acharya Jul 15 '21 at 01:57

0 Answers0