Gstreamer Python Read File Into Video Stream

gstreamer-python

jackersson / gstreamer-python Goto Github PK

102.0 6.0 28.0 176 KB
Python 97.39% Shell 2.61%

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

  • How to install Gstreamer on Ubuntu
  • How to install Gstreamer Python Bindings

in-identify

python3 -m venv venv                    source                    venv/bin/actuate 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/[electronic mail protected]{tag_name}                      #egg=gstreamer-python                                          ### to skip ./build-gst-python.sh                    pip install                    .                    -five --install-option                                          "build_py"                                        --install-option                                          "--skip-gst-python"                                                              ### to set specific gstreamer version                    export                    GST_VERSION=one.14.v

Test

PYTHONPATH=. pytest tests/ -s --verbose

Tools

Setup

  • By default Gstreamer tools use libgstreamer-1.0.so.0
                    export                    LIB_GSTREAMER_PATH=libgstreamer-one.0.and so.0

Export LIB_GSTREAMER_PATH with custom path to libgstreamer.and then

Setup Log Level
                    consign                    GST_PYTHON_LOG_LEVEL=0, ane, two, 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                                      

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

                    from gstreamer import get_buffer_size ret, (width, meridian) = 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=imitation"                                        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, top, num_buffers = 1920, 1080, 100 caps_filter =                                          'capsfilter caps=video/x-raw,format=RGB,width={},acme={}'                    .format(width, superlative)                    command                    =                                          'videotestsrc num-buffers={} ! {} ! appsink emit-signals=True sync=false'                    .format( num_buffers, caps_filter) with GstVideoSource(control) 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 button buffers in Python to any gst-launch pipeline
from gstreamer import GstVideoSink  width, superlative = 1920, 1080                    control                    =                                          "appsrc emit-signals=True is-alive=True ! videoconvert ! fakesink sync=false"                                        with GstVideoSink(control, width=width, acme=tiptop) as pipeline:                    for                    _                    in                    range(ten):         pipeline.push(buffer=np.random.randint(low=0, high=255, size=(height, width, iii), dtype=np.uint8))

Metadata

Object Info MedataData

                                          ten    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 design=1 ! autovideosink"                                      

Capture frames (np.ndarray) from whatsoever 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 whatsoever 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

jackersson avatar edumotya avatar

gstreamer-python's Problems

libgst_objects_info_meta.and so: cannot open up shared object file: No such file or directory

After executed the installation part, I tried to import from pygst_utils.gst_objects_info_meta import gst_meta_write and got an mistake:

                  >>> from pygst_utils.gst_objects_info_meta import gst_meta_write Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/local/lib/python3.vi/dist-packages/pygst_utils/gst_objects_info_meta.py", line 27, in <module>     libc = CDLL(os.path.join(cwd, "3rd_party/gstreamer/build/libgst_objects_info_meta.and so"))   File "/usr/lib/python3.six/ctypes/__init__.py", line 348, in __init__     self._handle = _dlopen(self._name, mode) OSError: /usr/local/lib/python3.6/dist-packages/pygst_utils/3rd_party/gstreamer/build/libgst_objects_info_meta.so: cannot open shared object file: No such file or directory                                  

Whatever ideas on how to solve it?

OSError: dlopen(libgstreamer-ane.0.so.0, six): image not found

gst_hack.py was throwing this error, when running on a mac:

                  --------------------------------------------------------------------------- OSError                                   Traceback (nigh recent call last) ~/Documents/mythic-projects/OKR_2019Q2/gstreamer_tutorials/test_gst_pipeline.py in <module>       6 import os       7 import logging ----> 8 from pygst_utils import utils       9 logging.basicConfig(level=logging.DEBUG)      10  ~/Documents/mythic-projects/OKR_2019Q2/venv/lib/python3.half dozen/site-packages/pygst_utils/__init__.py in <module>       four from gi.repository import Gst, GstBase, GObject, GLib       5 ----> 6 from .gst_hacks import map_gst_buffer, get_buffer_size       seven from .gst_hacks import map_gst_memory       viii  ~/Documents/mythic-projects/OKR_2019Q2/venv/lib/python3.6/site-packages/pygst_utils/gst_hacks.py in <module>      25 _GST_MAP_INFO_POINTER = Arrow(_GstMapInfo)      26 ---> 27 _libgst = CDLL("libgstreamer-i.0.so.0")      28 _libgst.gst_buffer_map.argtypes = [c_void_p, _GST_MAP_INFO_POINTER, c_int]      29 _libgst.gst_buffer_map.restype = c_int  /Library/Frameworks/Python.framework/Versions/three.6/lib/python3.6/ctypes/__init__.py in __init__(self, name, way, handle, use_errno, use_last_error)     346     347         if handle is None: --> 348             self._handle = _dlopen(self._name, mode)     349         else:     350             self._handle = handle  OSError: dlopen(libgstreamer-1.0.so.0, six): prototype non establish                                  

I was able to become around it past setting https://github.com/jackersson/pygst-utils/blob/master/pygst_utils/gst_hacks.py#L27 to the .dylib path

for my automobile, it was this:

libgst = CDLL("/usr/local/lib/libgstreamer-ane.0.dylib")

Install choice --skip-gst-python fails

I just tried to install gstreamer-python while skipping gst-python and installation failed.

Error logs:

gstreamer-python-install-error.txt

Steps to reproduce:

                  git clone git+https://github.com/jackersson/gstreamer-python.git cd gstreamer-python pip3 --user install . -v --install-pick "build_py" --install-option "--skip-gst-python"                                  

I would be grateful for any pointers to set up this!

PYGOBJECT version mismatch

Was following the README.doctor file and got this error when running the "build-gst-python.sh" script:

checking for GST... yep
checking for PYGOBJECT... configure: error: Package requirements (pygobject-3.0 >= 3.8) were not met:

No packet 'pygobject-3.0' establish

Consider adjusting the PKG_CONFIG_PATH surround variable if you
installed software in a non-standard prefix.

Alternatively, you lot may ready the environs variables PYGOBJECT_CFLAGS
and PYGOBJECT_LIBS to avoid the need to call pkg-config.
Run into the pkg-config man page for more than details.

make: *** No targets specified and no makefile found. Stop.
make: Nothing to be done for 'install'.

Whatsoever tips on how to set up this?

Internal streaming error during appsrc case

Hey,

thanks for this cracking piece of work. I want to apply it in an app to push frames to a pipeline subsequently some figurer vision magic. However, when running the appsrc instance, I encounter the post-obit fault:

                  [email protected]:~/gstreamer-python$ PYTHONPATH=. python examples/run_appsrc.py -p "appsrc emit-signals=Truthful is-live=True caps=video/x-raw,format=RGB,width=640,meridian=480 ! queue ! videoconvert ! autovideosink"  -n 1000  INFO   | pygst.GstPipeline    | 13.08 12:22:31.595 | MainThread | GstPipeline   gst-launch-1.0 appsrc emit-signals=True is-live=Truthful caps=video/ten-raw,format=RGB,width=640,top=480 ! queue ! videoconvert ! autovideosink  INFO   | pygst.GstPipeline    | xiii.08 12:22:31.672 | MainThread | Starting GstPipeline  DEBUG  | pygst.GstPipeline    | 13.08 12:22:31.674 | MainThread | GstPipeline Setting pipeline state to PLAYING ...   DEBUG  | pygst.GstPipeline    | 13.08 12:22:31.675 | MainThread | GstPipeline Pipeline state ready to PLAYING   ERROR  | pygst.GstPipeline    | 13.08 12:22:31.695 | Thread-ane | Gstreamer.GstPipeline: Fault gst-stream-error-quark:  Internal data stream error. (1): gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstAppSrc:appsrc0: streaming stopped, reason not-negotiated (-four).   DEBUG  | pygst.GstPipeline    | 13.08 12:22:31.696 | Thread-1 | GstPipeline Stopping pipeline ...  DEBUG  | pygst.GstPipeline    | thirteen.08 12:22:31.697 | Thread-1 | GstPipeline Reseting pipeline state ....  DEBUG  | pygst.GstPipeline    | xiii.08 12:22:31.698 | Thread-1 | GstPipeline Gst.Pipeline successfully destroyed  INFO   | pygst.GstPipeline    | xiii.08 12:22:38.935 | MainThread | GstPipeline Shutdown requested ...  INFO   | pygst.GstPipeline    | xiii.08 12:22:38.935 | MainThread | GstPipeline successfully destroyed  DEBUG  | pygst.GstContext     | 13.08 12:22:38.935 | MainThread | GstContext Quitting principal loop ...  DEBUG  | pygst.GstContext     | 13.08 12:22:38.937 | MainThread | GstContext Joining main loop thread...                                  

platform: Jetson nano with jetpack four.five.1
python: iii.6.nine
gstreamer: 1.xiv.5

Any idea what might be the reason?
Cheers

[Question] Change the buffer size

As per README, you can modify the buffer equally

with map_gst_buffer(buffer, Gst.MapFlags.READ | Gst.MapFlags.WRITE) every bit mapped:

My question is: what if I want to increase the buffer size by appending some bytes from Python?
Is it possible? If so, how to convert Python bytearray to C byte assortment, using Ctypes?

Thanks.

All-time Regards,

Yu

GStreamer seems to accept moved from autogen to meson...

.... which breaks this script. I'll come across if I can go it working 'by hand' and make a pull asking if I get it working.

Recommended way to handle KeyboardInterrupt (ctrl-c) properly in apps

Hi

(lamentable this may not be an issue only a question)

I accept made a test Python app that use the GstContext. Equally GstContext runs inside a thread and I could not find a fashion to "terminate" it properly. The main thread could not catch the KeyboardInterrupt (even I take tried the signal).

Is there a way to handle KeyboardInterrupt at the master thread (app) and shutdown pipeline gracefully?

Thanks.

Yu

dynamically calculation a pipline

run_rtsp case throw: TypeError: 'Iterator' object is not iterable

Throw an Error TypeError: 'Iterator' object is non iterable in case run_rtsp.py.

return [eastward for e in element.iterate_elements() if isinstance(e, cls)]

Log:

                  Traceback (near contempo call last):   File "rtsp-server.py", line 212, in do_configure     appsrcs = get_child_by_cls(rtsp_media.get_element(), GstApp.AppSrc)   File "rtsp-server.py", line 162, in get_child_by_cls     return [e for east in element.iterate_elements() if isinstance(e, cls)] TypeError: 'Iterator' object is non iterable                                  

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 edifice UI on the spider web.

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Motorcar Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo Laravel

    A PHP framework for web artisans

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

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

  • spider web

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

  • server

    A server is a program fabricated to process requests and evangelize data to clients.

  • Auto learning

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

  • Visualization

    Some thing interesting nigh visualization, utilise information art

  • Game

    Some thing interesting virtually game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open up source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo Alibaba

    Alibaba Open Source for everyone

  • D3 photo D3

    Data-Driven Documents codes.

  • Tencent photo Tencent

    China tencent open source team.

Jobs

Jooble

campbellblipt1987.blogspot.com

Source: https://githubhelp.com/jackersson/gstreamer-python

0 Response to "Gstreamer Python Read File Into Video Stream"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel