Apply the following patch to deepstream_test_1.py,then run python3 deepsteam_test_1.py /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264
This patch implements the following functions.
nvosd --> nvvideoconvert --> "video/x-raw(memory:NVMM), format=RGB" (for nvimagenc caps) --> nvimagenc --> fakesink.
Add sink probe at fakesink
element, save the gst_buffer to jpeg.
diff --git a/apps/deepstream-test1/deepstream_test_1.py b/apps/deepstream-test1/deepstream_test_1.py
index 861cefc..40bc5a3 100755
--- a/apps/deepstream-test1/deepstream_test_1.py
+++ b/apps/deepstream-test1/deepstream_test_1.py
@@ -33,6 +33,7 @@ PGIE_CLASS_ID_BICYCLE = 1
PGIE_CLASS_ID_PERSON = 2
PGIE_CLASS_ID_ROADSIGN = 3
MUXER_BATCH_TIMEOUT_USEC = 33000
+frame_count = 0
def osd_sink_pad_buffer_probe(pad,info,u_data):
frame_number=0
@@ -116,9 +117,30 @@ def osd_sink_pad_buffer_probe(pad,info,u_data):
l_frame=l_frame.next
except StopIteration:
break
-
- return Gst.PadProbeReturn.OK
+ return Gst.PadProbeReturn.OK
+
+
+def fake_sink_pad_buffer_probe(pad,info,u_data):
+ gst_buffer = info.get_buffer()
+ if not gst_buffer:
+ print("Unable to get GstBuffer ")
+ return
+
+ (result, mapinfo) = gst_buffer.map(Gst.MapFlags.READ)
+ assert result
+
+ try:
+ # use mapinfo.data here
+ global frame_count
+ if frame_count % 500 == 0:
+ with open(f"out_{frame_count}.jpeg", "wb") as f:
+ f.write(mapinfo.data)
+ frame_count += 1
+ finally:
+ gst_buffer.unmap(mapinfo)
+
+ return Gst.PadProbeReturn.OK
def main(args):
# Check input arguments
@@ -174,21 +196,39 @@ def main(args):
# Create OSD to draw on the converted RGBA buffer
nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")
-
if not nvosd:
sys.stderr.write(" Unable to create nvosd \n")
+ # Use convertor to convert from NV12 to RGB as required by nvimageenc
+ nvvidconv2 = Gst.ElementFactory.make("nvvideoconvert", "convertor2")
+ if not nvvidconv2:
+ sys.stderr.write(" Unable to create nvvidconv2 \n")
+
+ caps = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=RGB")
+ filter = Gst.ElementFactory.make("capsfilter", "filter1")
+ if not filter:
+ sys.stderr.write(" Unable to get the caps filter1 \n")
+ filter.set_property("caps", caps)
+
+ nvimageenc = Gst.ElementFactory.make("nvimageenc", "nvimageenc")
+ if not nvimageenc:
+ sys.stderr.write(" Unable to create nvimageenc \n")
+
# Finally render the osd output
- if is_aarch64():
- print("Creating nv3dsink \n")
- sink = Gst.ElementFactory.make("nv3dsink", "nv3d-sink")
- if not sink:
- sys.stderr.write(" Unable to create nv3dsink \n")
- else:
- print("Creating EGLSink \n")
- sink = Gst.ElementFactory.make("nveglglessink", "nvvideo-renderer")
- if not sink:
- sys.stderr.write(" Unable to create egl sink \n")
+ # if is_aarch64():
+ # print("Creating nv3dsink \n")
+ # sink = Gst.ElementFactory.make("nv3dsink", "nv3d-sink")
+ # if not sink:
+ # sys.stderr.write(" Unable to create nv3dsink \n")
+ # else:
+ # print("Creating EGLSink \n")
+ # sink = Gst.ElementFactory.make("nveglglessink", "nvvideo-renderer")
+ # if not sink:
+ # sys.stderr.write(" Unable to create egl sink \n")
+
+ sink = Gst.ElementFactory.make("fakesink", "fakesink")
+ if not sink:
+ sys.stderr.write(" Unable to create fakesink \n")
print("Playing file %s " %args[1])
source.set_property('location', args[1])
@@ -208,6 +248,9 @@ def main(args):
pipeline.add(pgie)
pipeline.add(nvvidconv)
pipeline.add(nvosd)
+ pipeline.add(nvvidconv2)
+ pipeline.add(filter)
+ pipeline.add(nvimageenc)
pipeline.add(sink)
# we link the elements together
@@ -227,7 +270,10 @@ def main(args):
streammux.link(pgie)
pgie.link(nvvidconv)
nvvidconv.link(nvosd)
- nvosd.link(sink)
+ nvosd.link(nvvidconv2)
+ nvvidconv2.link(filter)
+ filter.link(nvimageenc)
+ nvimageenc.link(sink)
# create an event loop and feed gstreamer bus mesages to it
loop = GLib.MainLoop()
@@ -244,6 +290,12 @@ def main(args):
osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)
+ fakesinkpad = sink.get_static_pad("sink")
+ if not fakesinkpad:
+ sys.stderr.write(" Unable to get sink pad of fakesink \n")
+
+ fakesinkpad.add_probe(Gst.PadProbeType.BUFFER, fake_sink_pad_buffer_probe, 0)
+
# start play back and listen to events
print("Starting pipeline \n")
pipeline.set_state(Gst.State.PLAYING)