0

从 rtsp 播放器查看时没有流内容。

  • 我已经使用 python mss 捕获了屏幕,

  • 转换为 opencv 帧并尝试使用 gstreamer 进行直播

  • ffplay rtsp://127.0.0.1:8554/test 不播放任何流也不给出任何错误。

  • 我发现了来自 rtsp 相机和本地视频文件的输入的类似示例。将opencv帧写入gstreamer rtsp服务器管道

#!/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):
        ****
4

0 回答 0