I’m trying to convert the following shell script to Python:
(Taken from Ridgeruns’ Gstreamer pipeline page)
CLIENT_IP=10.100.0.70
gst-launch-1.0 nvcamerasrc fpsRange="30 30" intent=3 ! nvvidconv flip-method=6 \
! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1' ! \
omxh264enc control-rate=2 bitrate=4000000 ! 'video/x-h264, stream-format=(string)byte-stream' ! \
h264parse ! rtph264pay mtu=1400 ! udpsink host=$CLIENT_IP port=5000 sync=false async=false
I’m having trouble with these two lines:
'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1' ! \
'video/x-h264, stream-format=(string)byte-stream'
I thought they were caps so I tried Gst.caps_from_string and set_property(‘caps’, …), but nvvidconv, omxh264enc, and h264parse all tell me they don’t have a caps property
Here’s what I have so far. Any advice?
"""
CLIENT_IP=10.100.0.70
gst-launch-1.0 nvcamerasrc fpsRange="30 30" intent=3 ! nvvidconv flip-method=6 \
! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1' ! \
omxh264enc control-rate=2 bitrate=4000000 ! 'video/x-h264, stream-format=(string)byte-stream' ! \
h264parse ! rtph264pay mtu=1400 ! udpsink host=$CLIENT_IP port=5000 sync=false async=false
"""
CLIENT_IP="10.100.0.70"
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
# Create elements
nvcamerasrc = Gst.ElementFactory.make('nvcamerasrc')
nvvidconv = Gst.ElementFactory.make('nvvidconv')
encoder = Gst.ElementFactory.make('omxh264enc')
parser = Gst.ElementFactory.make('h264parse')
payload = Gst.ElementFactory.make('rtph264pay')
udpsink = Gst.ElementFactory.make('udpsink')
# Configure elements
nvcamerasrc.set_property('fpsRange', "30 30")
nvcamerasrc.set_property('intent', 3)
caps = Gst.caps_from_string('video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1')
nvvidconv.set_property('caps', caps)
nvvidconv.set_property('flip-method', 6)
caps = Gst.caps_from_string('video/x-h264, stream-format=(string)byte-stream')
encoder.set_property('caps', caps)
encoder.set_property('control-rate', 2)
encoder.set_property('bitrate', 4000000)
payload.set_property('mtu', 1400)
udpsink.set_property('host', CLIENT_IP)
udpsink.set_property('port', 5000)
udpsink.set_property('sync', False)
udpsink.set_property('async', False)