Please convert the following gst-launch-1.0 command-line pipeline into a Python script using the GStreamer Python bindings (GstPy).
Original gst-launch-1.0 Pipeline:
gst-launch-1.0 -e
aravissrc features="OverlapMode=On Width=1024 Height=1024 ExposureAuto=Continuous AcquisitionFrameRate=88.5 AcquisitionFrameRateEnable=1 GevSCPSPacketSize=8164 Gain=0 GainAuto=Continuous GammaEnable=1 GammaSelector=sRGB" !
video/x-bayer,width=1024,height=1024 !
tcamconvert !
nvvidconv compute-hw=1 ! "video/x-raw(memory:NVMM),format=NV12,width=640,height=640" !
tee name=t
t. ! queue max-size-buffers=1 leaky=downstream ! m.sink_0
nvstreammux name=m batch-size=1 width=640 height=640 live-source=1 !
nvinfer config-file-path=config_infer_primary_yoloV8.txt !
nvdsosd ! nvegltransform ! fpsdisplaysink text-overlay=false video-sink=nveglglessink
t. ! queue max-size-buffers=1 leaky=downstream !
nvvidconv compute-hw=1 !
x264enc bitrate=10000 speed-preset=ultrafast tune=zerolatency !
video/x-h264,stream-format=avc,alignment=au !
splitmuxsink location="output_%05d.mp4" max-size-time=30000000000 muxer=mp4mux
Requirements for the Python Script:
Use GstPy: The script should use the standard GStreamer Python bindings (gi.repository.Gst). Include necessary imports like import gi; gi.require_version('Gst', '1.0'); from gi.repository import Gst, GLib.
Pipeline Structure: Create a Gst.Pipeline.
Element Creation: Instantiate each element using Gst.ElementFactory.make(). Handle potential None returns if an element factory is missing.
Property Setting: Set all specified properties for each element using element.set_property(). Pay close attention to:
The complex features string for aravissrc. Treat it as a single string property.
Numerical properties (width, height, batch-size, bitrate, max-size-time, max-size-buffers, GevSCPSPacketSize, AcquisitionFrameRate, Gain). Ensure correct data types (int, float, bool where applicable like GammaEnable).
Boolean properties derived from flags (compute-hw=1, live-source=1, text-overlay=false).
String properties (config-file-path, location, video-sink, muxer).
Enum-like properties (leaky, speed-preset, tune, format, stream-format, alignment, ExposureAuto, GainAuto, GammaSelector, OverlapMode). Use Gst introspection or common sense for potential enum values if direct string setting doesn't work (though often strings work for enums in GstPy).
Caps Filters: Create Gst.CapsFilter elements and set their caps property using Gst.Caps.from_string() for the specified capabilities (video/x-bayer,..., video/x-raw(memory:NVMM),..., video/x-h264,...).
Linking: Link the elements in the correct sequence using element.link().
Tee Handling: Correctly handle the tee element:
Get request pads from the tee (tee.get_request_pad('src_%u')).
Get static sink pads from the downstream elements (queue.get_static_pad('sink')).
Link the tee's source pads to the queue's sink pads.
NvStreamMux Handling: Correctly handle the nvstreammux element:
Get a request sink pad from the muxer (muxer.get_request_pad('sink_%u')).
Get the static source pad from the upstream element (queue.get_static_pad('src')).
Link the queue's source pad to the muxer's sink pad.
Main Loop: Include a GLib.MainLoop to run the pipeline asynchronously.
Bus Handling: Implement basic message handling on the pipeline's bus to listen for EOS (End-of-Stream) and ERROR messages, allowing the script to terminate gracefully. The -e flag in the original command implies EOS should be handled.
State Management: Set the pipeline state to PLAYING to start it and handle cleanup (setting state to NULL) upon exit.
Comments: Add comments to explain the different sections of the code (element creation, property setting, linking, main loop, etc.).
DeepStream Elements: Ensure all NVIDIA DeepStream elements (nvvidconv, nvstreammux, nvinfer, nvdsosd, nvegltransform, nveglglessink) are correctly instantiated and configured. Note that tcamconvert is likely from The Imaging Source, not NVIDIA, but should be handled similarly.
Please generate a complete, runnable Python script that replicates the functionality of the provided gst-launch-1.0 command.