- abstraction over PyGOBJECT API for Gstreamer
- work with Gstreamer metadata
- common tools for Gstreamer pipeline management
- easy gst-python installation
python3 -m venv venv
source venv/bin/activate
pip install --upgrade wheel pip setuptools
pip install --upgrade --requirement requirements.txt
./build-3rd-party.sh
./build-gst-python.sh
pip install git+https://github.com/jackersson/gstreamer-python.git@{tag_name}#egg=gstreamer-python
### to skip ./build-gst-python.sh
pip install . -v --install-option "build_py" --install-option "--skip-gst-python"
### to set specific gstreamer version
export GST_VERSION=1.14.5
PYTHONPATH=. pytest tests/ -s --verbose
- By default Gstreamer tools use libgstreamer-1.0.so.0
export LIB_GSTREAMER_PATH=libgstreamer-1.0.so.0
Export LIB_GSTREAMER_PATH with custom path to libgstreamer.so
export GST_PYTHON_LOG_LEVEL=0, 1, 2, 3, 4, 5
from gstreamer import map_gst_buffer
with map_gst_buffer(pbuffer, Gst.MapFlags.READ | Gst.MapFlags.WRITE) as mapped:
// do_something with mapped
from gstreamer import map_gst_memory
with map_gst_memory(memory, Gst.MapFlags.READ | Gst.MapFlags.WRITE) as mapped:
// do_something with mapped
from gstreamer import get_buffer_size
ret, (width, height) = get_buffer_size(Gst.Caps)
from gstreamer import gst_buffer_to_ndarray, gst_buffer_with_pad_to_ndarray
array = gst_buffer_to_ndarray(Gst.Buffer, width, height, channels)
# or
array = gst_buffer_with_pad_to_ndarray(Gst.Buffer, Gst.Pad, channels)
- With GstPipeline run any gst-launch pipeline in Python
from gstreamer import GstPipeline
command = "videotestsrc num-buffers=100 ! fakesink sync=false"
with GstPipeline(command) as pipeline:
...
- With GstVideoSource run any gst-launch pipeline and receive buffers in Python
from gstreamer import GstVideoSource
width, height, num_buffers = 1920, 1080, 100
caps_filter = 'capsfilter caps=video/x-raw,format=RGB,width={},height={}'.format(width, height)
command = 'videotestsrc num-buffers={} ! {} ! appsink emit-signals=True sync=false'.format(
num_buffers, caps_filter)
with GstVideoSource(command) as pipeline:
buffers = []
while len(buffers) < num_buffers:
buffer = pipeline.pop()
if buffer:
buffers.append(buffer)
print('Got: {} buffers'.format(len(buffers)))
- With GstVideoSink push buffers in Python to any gst-launch pipeline
from gstreamer import GstVideoSink
width, height = 1920, 1080
command = "appsrc emit-signals=True is-live=True ! videoconvert ! fakesink sync=false"
with GstVideoSink(command, width=width, height=height) as pipeline:
for _ in range(10):
pipeline.push(buffer=np.random.randint(low=0, high=255, size=(height, width, 3), dtype=np.uint8))
x
y
width
height
confidence
class_name
track_id
python examples/pipeline_with_factory.py
python examples/pipeline_with_parse_launch.py -p "videotestsrc num-buffers=100 pattern=1 ! autovideosink"
PYTHONPATH=. python examples/run_appsink.py -p "videotestsrc num-buffers=100 ! capsfilter caps=video/x-raw,format=RGB,width=640,height=480 ! appsink emit-signals=True"
PYTHONPATH=. python examples/run_appsrc.py -p "appsrc emit-signals=True is-live=True caps=video/x-raw,format=RGB,width=640,height=480 ! queue ! videoconvert ! autovideosink" -n 1000