GithubHelp home page GithubHelp logo

gstreamer-python's Introduction

gstreamer-python

Purpose

  • abstraction over PyGOBJECT API for Gstreamer
  • work with Gstreamer metadata
  • common tools for Gstreamer pipeline management
  • easy gst-python installation

Install

Install OS packages

in-place

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-package

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

Test

PYTHONPATH=. pytest tests/ -s --verbose

Tools

Setup

  • 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

Setup Log Level
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

Make Gst.Memory writable

from gstreamer import map_gst_memory
with map_gst_memory(memory, Gst.MapFlags.READ | Gst.MapFlags.WRITE) as mapped:
            // do_something with mapped

Get Gst.Buffer shape (width,height) from Gst.Caps

from gstreamer import get_buffer_size
ret, (width, height) = get_buffer_size(Gst.Caps)

Convert Gst.Buffer to np.ndarray

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)

GstPipeline

  • 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:
    ...

GstVideoSource based on AppSink

  • 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)))

GstVideoSink based on AppSrc

  • 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))

Metadata

   x
   y
   width
   height
   confidence
   class_name
   track_id

Examples

Run Gstreamer pipeline in Python using Gst.ElementFactory

python examples/pipeline_with_factory.py

Run Gstreamer pipeline in Python using Gst.parse_launch

python examples/pipeline_with_parse_launch.py -p "videotestsrc num-buffers=100 pattern=1 ! autovideosink"

Capture frames (np.ndarray) from any Gstreamer pipeline

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"

Push images (np.ndarray) to any Gstreamer pipeline

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

gstreamer-python's People

Contributors

edumotya avatar jackersson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.