1 Star 0 Fork 0

tgy/gstreamer-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

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

Make Gst.Buffer writable

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

Object Info MedataData

   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

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pande1/gstreamer-python.git
git@gitee.com:pande1/gstreamer-python.git
pande1
gstreamer-python
gstreamer-python
master

搜索帮助