How to convert gstreamer commands to python code

Hi,

I’d like to convert gstreamer commands as below to python code.

gst-launch-1.0 v4l2src device=/dev/video0 ! ‘video/x-raw, width=1920, height=1080, framerate=60/1, format=UYVY’ ! nvvidconv ! ‘video/x-raw(memory:NVMM), width=1920, height=1080, framerate=60/1, format=I420’ ! nvoverlaysink sync=false

Could you let me know your idea?

Thanks & BR,

Hi nwlee,
We don’t have experience in this. I search online and get https://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.pdf

Please check if it helps.

Hi Dane,

Thank you for your support.

I saw the document that you sent. But, I don’t know exactly.

I’d like to know that working the gst command with the python code to the v4l2src method (not nvcamerasrc, filesrc).

Could you give me a sample command?

Thank you $ BR,

Hi Dane,

Please let me know your idea.

If you don’t know this issue, please assign known person for this issue.

Thanks & BR,

Hi Dane,

I have written as below.

================================================================================================
import cv2
import numpy as np
import gi
gi.require_version(“Gst”,“1.0”)
from gi.repository import Gst
import time

Gst.init(None)

class mygst:
def init(self):
self.pipeline = None
self.connection = None
self.client_address = None
self.bitrate = 2000000

self.control_queue = None

if self.pipeline is not None:
  return

pipeline_string = " v4l2src device=/dev/video0" + \
                  " ! 'video/x-raw, width=1920, height=1080, framerate=60/1, format=UYVY' " + \
                  " ! nvvidconv " + \
                  " ! 'video/x-raw(memory:NVMM), format=NV12' " + \
	      " ! tee name=t t. " + \
                  " ! queue " + \
                  " ! omxh264enc bitrate=8000000 " + \
                  " ! h264parse " + \
                  " ! matroskamux " + \
                  " ! filesink location=EO_image.mp4 t. " + \
                  " ! queue " + \
                  " ! nvtee " + \
                  " ! nvoverlaysink sync=false "

self.pipeline = Gst.parse_launch(pipeline_string)

ret = self.pipeline.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
  print("Unable to set pipeline to playing")
  self.pipeline.set_state(Gst.State.NULL)
  self.pipeline = None

def main():

prevTime = time.time()

cap = cv2.VideoCapture(“EO_image.mp4”)

while True:
ret, frame = cap.read()

curTime = time.time()
sec = curTime - prevTime
fps = 1/sec

print("sec : ",sec)
print("fps : ",fps)

str = "FPS : %0.1f" % fps

cv2.putText(frame,str,(0,100),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0))

if not ret:
  print("Video Error")
cv2.imshow('image',frame)
cv2.imwrite('img.jpg',frame)

#server = mygst()
#server.__init__()

if cv2.waitKey(50) & 0xFF == 27:
  break

cv2.destroyAllWindows()
cap.release()

main()

================================================================================================

But, It’s not working.

What is wrong?

I need your help.

Thanks & BR,

Please check if you can get solution here:
http://gstreamer-devel.966125.n4.nabble.com/template/NamlServlet.jtp?macro=search_page&node=966125&query=python