<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello WisdomPill,</p>
<p>I would suggest checking out this example if you haven't done so
already:</p>
<p><a class="moz-txt-link-freetext" href="https://github.com/GStreamer/gst-rtsp-server/blob/master/examples/test-appsrc.c">https://github.com/GStreamer/gst-rtsp-server/blob/master/examples/test-appsrc.c</a></p>
<p>It is in C and I apologize I am not familiar with the python
interface.<br>
</p>
<p>Two things I notice is it doesn't look like you are setting the
appsrc format to time. By default it is bytes. You can change
that like this (C++):</p>
<p>gst_util_set_object_arg(<span style=" color:#000080;">G_OBJECT</span>(video_appsrc),<span
style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"format"</span>,<span
style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"time"</span>);</p>
<p>Since you are setting the PTS on the frames, you need to do
this. You might be getting invalid/unexpected format errors
because of this.<br>
</p>
<p>I would also recommend setting up pushing frames on the
"media-configured" signal on the media factory (assuming you are
using a live source). You can stop pushing frames when you get
GST_FLOW_NOT_OK when you push your frames.<br>
</p>
<p>This way you can start pushing frames only when a client
connects. And stop pushing when they disconnect.</p>
<p>It also does not look like you are setting the caps on the
appsrc. I am fairly certain you need to do this.<br>
</p>
<p>You might also want to post what log output and what errors you
are getting so people can better help you.</p>
<p>Good luck, appsrc rtsp servers are pretty challenging.<br>
</p>
<p>Cheers,<br>
Michael.<br>
</p>
<br>
<div class="moz-cite-prefix">On 11/20/2017 8:13 AM, WisdomPill
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:1511194409619-0.post@n4.nabble.com">
<pre wrap="">I'm trying to put opencv images into a gstreamer rtsp server in python.
I have some issue writing in the mediafactory, I'm new to gst-rtsp-server
ancd there's little documentation so I don't know exactly if I'm using the
right approach. I'm using a thread to start the MainLoop and I'm using the
main thread to create a buffer to push in the appsrc element of the
mediafactory pipeline. Am I using the right approach to obtain my objective?
Can anyone help me? My code is below:
from threading import Thread
from time import clock
import cv2
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GObject
class SensorFactory(GstRtspServer.RTSPMediaFactory):
def __init__(self, **properties):
super(SensorFactory, self).__init__(**properties)
self.launch_string = 'appsrc !
video/x-raw,width=320,height=240,framerate=30/1 ' \
'! videoconvert ! x264enc
speed-preset=ultrafast tune=zerolatency ' \
'! rtph264pay config-interval=1 name=pay0
pt=96'
self.pipeline = Gst.parse_launch(self.launch_string)
self.appsrc = self.pipeline.get_child_by_index(4)
def do_create_element(self, url):
return self.pipeline
class GstServer(GstRtspServer.RTSPServer):
def __init__(self, **properties):
super(GstServer, self).__init__(**properties)
self.factory = SensorFactory()
self.factory.set_shared(True)
self.get_mount_points().add_factory("/test", self.factory)
self.attach(None)
GObject.threads_init()
Gst.init(None)
server = GstServer()
loop = GObject.MainLoop()
th = Thread(target=loop.run)
th.start()
print('Thread started')
cap = cv2.VideoCapture(0)
print(cap.isOpened())
frame_number = 0
fps = 30
duration = 1 / fps
timestamp = clock()
while cap.isOpened():
ret, frame = cap.read()
if ret:
print('Writing buffer')
data = frame.tostring()
buf = Gst.Buffer.new_allocate(None, len(data), None)
buf.fill(0, data)
buf.duration = fps
timestamp = clock() - timestamp
buf.pts = buf.dts = int(timestamp)
buf.offset = frame_number
frame_number += 1
retval = server.factory.appsrc.emit('push-buffer', buf)
print(retval)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
By the way I tried to copy the buffer creation from opencv source code but
I'm not sure I correctly trandlated the c++ code in python.
--
Sent from: <a class="moz-txt-link-freetext" href="http://gstreamer-devel.966125.n4.nabble.com/">http://gstreamer-devel.966125.n4.nabble.com/</a>
_______________________________________________
gstreamer-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a>
</pre>
</blockquote>
<br>
</body>
</html>