Thumb 605efe67 17c4 4892 a77e 802c99d4eb58

PylonGStreamer

A sample showing how you can integrate Basler's pylon API into GStreamer's AppSrc element (so you can use your camera as a source for a pipeline!). Applications include streaming video across network, displaying to framebuffers, etc.

Project State

Public Project Participation icon Participation wanted

Licences

Software Licence: Apache 2.0
Hardware Licence: Project has no hardware

Project Tags

Admins

mattb

Members

heshanfer
Andy504
dcfortin

Does this project pique your interest?

Login or register to join or follow this project.

pylongstreamer (using the InstantCameraAppSrc class):
Example of using Basler's Pylon API with GStreamer's GstAppSrc element.

InstantCameraAppSrc Functional Descrtiption:
A Typical Image Streaming Pipeline would look as follows:

The GStreamer AppSrc element is the source for the pipeline.
When AppSrc needs an image, it sends the "need-data" signal.
This triggers a callback function where the user can "push" their own data buffer to the src pad of the AppSrc element.
The data buffer is then picked up by the rest of the pipeline.
The InstantCameraAppSrc class provides a convinient way to access a Basler camera in your GStreamer application:
For example, InitCamera() can be used to configure the camera and pylon driver as you like.
And the source element for the pipeline can be created with: GstElement* source = myCamera.GetGstAppSrc();

By default, the InstantCameraAppSrc will use the camera in free-running mode, and the pylon driver's Grab Engine with the LatestImageOnly strategy, so that only the latest image received by the camera is available to be retrieved. If a new image arrives before the previous one is retrieved, it is overwritten in the Grab Engine. This strategy makes for the "live-ist" of streams. :-)

The CInstantCameraAppSrc class is an extension of the Pylon::CInstantCamera class.
It accesses the camera using pylon's GenICam-compliant generic API, so it will work with both USB and GigE cameras out of the box. :-)

pylongstreamer example program usage:
pylongstreamer -(option) -(pipeline)

Options:
-camera serialnumber
-aoi width height
-rescale width height
-rotate degress

-framerate framespersecond
-usetrigger
-ondemand


Pipelines (created with the CPipelineHelper class):
-display
-framebuffer /dev/fbX
-h264stream ipaddress
-
h264file
filename numberofframes

Quick-Start (Just pick a pipeline. It will use the first camera found, and set it to 640x480, 30fps):
pylongstreamer -display

Examples:
Save a video:
  pylongstreamer -camera 12345678 -aoi 320 240 -framerate 15 -h264file mymovie.h264 100
Display stream in a window:
  pylongstreamer -framerate 30 -display
Display stream on a seconday screen:
  pylongstreamer -aoi 640 480 -framebuffer /dev/fb1
Use a TTL trigger to control the camera, rescale and rotate image, compress the images to h264, and stream across the network:
  pylongstreamer -camera 21234567 -aoi 1024 768 -rescale 320 240 -rotate 90 -framerate 60 -usetrigger -h264stream 192.168.1.150

Option Details:
-camera: Use a specific camera by entering the serial number.
-ondemand: Camera will be software triggered with each need-data signal instead of freerunning. May lower CPU load, but may be less 'real-time'.
-usetrigger: Camera will expect to be hardware triggered by user via IO ports (cannot be used with -ondemand).

Pipeline Example Details:
-h264stream (Encodes images as h264 and transmits stream to another PC running a GStreamer receiving pipeline.)
-h264file (Encodes images as h264 and saves stream to local file.)
-display (displays the raw image stream in a window on the local machine.)
-framebuffer (directs raw image stream to Linux framebuffer, e.g. /dev/fb0)

Requirements:
This is built and tested with GStreamer 1.0 and Pylon 5.0.9 (Linux) / Pylon 5.0.10 (Windows).
Project supports Windows and Linux; x86 x64, and ARM. Repo includes Visual Studio 2013 solution and a Linux makefile.
Note for Linux users: You may need to install the following libraries:
gstreamer1.0
gstreamer1.0-dev
gstreamer1.0-libav
gstreamer1.0-plugins-bad
libgstreamer-plugins-base1.0-dev

(on Ubuntu systems, all can be isntalled using apt-get install)

Note about GStreamer Plugins (elements):
Some GStreamer elements (plugins) used in the pipeline examples may not be available on all systems. Consult GStreamer for more information: https://gstreamer.freedesktop.org/

PARTICIPATION WANTED!
Please share your experience, feature requests, and support requests in the project's forum.

Thanks and I hope you enjoy! :-)

-Matt

GitHub Repository

https://github.com/MattsProjects/pylon_gstreamer

Commits

Matthew B
pushed 963e80c2c3aae67930639e0aaa842d6f5cbfad55
Delete pylon_gstreamer_orig.zip
2017-11-16 16:12:23 UTC
matt breit
pushed 916944e295704690440b1aea710f3ddbf50a7dda
Bugfix (API Break): moved control of h264file file size from pipelinehelper to instantcameraappsrc. Pipeline helper was setting num-buffers on source, but source is a gstbin made by instantcamerappsrc, so it is not possible to access the child appsrc element like this. pylongstreamer:numFramesToRecord is now applied to appsrc element in instantcameraappsrc:GetSource() before element is binned. additionally, the binned source now forwards the appsrc's EOS message to the pipeline when num-buffers is hit. Finally, removed muxer from pipelinehelper:h264file pipeline. It caused negotiation error with omxh264 (odd, but at least this was seen on rpi3 today...). API Break: pipelinehelper:h264file no longer accepts number of frames to record as argument.
2017-11-10 22:00:00 UTC
MattB
pushed bb542d1c6c3ab9785d12c3f934a3eeea5260ee3a
changed from using std::exception(string) to std::runtime_error(string)
2017-09-26 18:34:47 UTC
MattB
pushed 5e65197c18649d3226b071b528f8ebd0462473e1
pylongstreamer: updated the sample program to support new InstantCameraAppSrc feature (it now uses the rescaler and rotator from the instantcameraappsrc instead of the pipelinehelper). Also started to clean up exception handling.
2017-09-22 14:59:16 UTC
MattB
pushed 743882f926d0b4ec91f329e6d34beb427b728af9
InstantCameraAppSrc: new features (api break): now provides a gst bin element as a source, which includes appsrc+rescaler+rotator (previously just appsrc was provided). GetGstAppSrc() now changed to GetSource() and m_source is now m_appsrc. Fix: moved device enumeration and attachment of camera to device from InitCamera() to constructor. This makes it possible to change settings of camera before calling InitCamera(), for example if you want to reset the camera to default settins first.
2017-09-22 14:57:21 UTC
Matthew B
pushed 5fb1ea6d061c98bf8528169cbb395dc9d5cc9ab7
CPipelineHelper: cleaned up rescaler code.
2017-09-21 01:54:51 UTC
Matthew B
pushed 543afeb6c9fcb4a4e364dc0e433e084ef9c44333
StopCamera(): Added safety measure to send EOS event before StopGrabbing(), which prevents need-data signals from appsrc during StopGrabbing(). StopGrabbing clears grab engine buffers, which renders the ptrGrabResult pointer invalid (aka no grab data referenced error in retrieve_image().
2017-09-10 05:32:47 UTC
Matthew B
pushed fe1677c73999c441920e9b80b2f45647b16346c9
pylongstreamer.cpp: corrected recommended order of operations - shutdown pipeline before stopping camera to avoid requests for image during a StopGrabbing().
2017-09-10 05:17:32 UTC
Matthew B
pushed aaddb9b0799fd4a9a00678f18457e7108b875ec2
pylongstreamer demo app: fixed stupid mistake, forgot to use proper name for rescaler option (-rescale)
2017-09-09 03:54:54 UTC
Matthew B
pushed 826977c6993b3262ae02ddb9ef4068dc410296a8
pylongstreamer demo application: added support for new features (defaulting and rescaling). Added -aoi and -window console option (-width/-height/-display still available but deprecated) Cleaned up code and comments.
2017-09-09 03:40:14 UTC
Matthew B
pushed 26711a456734026d2ebbc8cf05b028f26b13ca96
CPipelineHelper: Added option to rescale the image when creating the pipelinehelper
2017-09-09 03:37:12 UTC
Matthew B
pushed b3e59168ffac6ba7dda3f3491901db76f3db84d4
CInstantCameraAppSrc: added ability to default camera to max aoi and framerate by passing arguments of -1. Fixed order-of-operations by setting framerate after aoi.
2017-09-09 03:34:17 UTC
Matthew B
pushed e8e5669e9d8d699e1986eb1291cd34aa5a20306a
Added original code in zip file
2017-09-05 20:15:59 UTC
Matthew B
pushed a7ac50c9a4fd5f6570fa7c043e04d0023ead2da4
Merge pull request #1 from MattsProjects/wraps_gst
2017-09-05 19:40:33 UTC
Matt B
pushed 0ce25d85e4eed07db975558b378caf573bb8854b
Corrected makefile string - CInstantCameraForAppSrc --> CInstantCameraAppSrc
2017-09-04 21:45:07 UTC
MattB
pushed 1bc3ba83b5d95edf8210730b6490625800620ae3
(api break from master branch). This new version wraps a lot of the code found in the implementation into the InstantCameraAppSrc class.
2017-09-01 19:47:35 UTC
Matt
pushed d8dfc92d8e2a6b18fab7f0f8055b96b230a7eff7
Bringing everything about the source element (setup, callback handler, pushing buffers, etc.) into CInstantCameraApp.
2017-09-01 05:55:43 UTC
MattB
pushed 1ff125a14fc2e72a618f4d7cf54fb1eedc637975
License change to Apache 2.0.
2017-08-30 20:31:33 UTC
MattB
pushed a83304ca3bf2be99bb84b5a709a6834d8a40459b
Now using int instead of int64_t for GetWidth/Height (int64_t had problems on one 32bit arm platform).
2017-08-30 20:14:19 UTC
mattbreit
pushed 401b29add43b276b88a2b6d996b5ac18e6cf3ff8
for bcon support: removed migration mode and will manage SFNC3 names manually.
2017-08-29 00:01:43 UTC
MattB
pushed 1290ee35ddd5c5a295ef80f675319f326a3f9ab0
more error message details in bus_call()
2017-08-28 21:20:14 UTC
Matthew B
pushed c0a1daffe421e58f9c70632183707fbc6da69fba
Update README.md
2017-08-28 15:47:11 UTC
MattB
pushed 24c4bd0cde3528469f17309a0d74a490cc2696f7
First code commit.
2017-08-28 14:02:41 UTC
Matthew B
pushed f4395d6019019e40ae1d751927569e4fec4f1b3e
Update README.md
2017-08-28 14:01:29 UTC
Matthew B
pushed 9a5a213ac37776744beacc031c7a0fa820da71ef
Initial commit
2017-08-28 14:01:10 UTC
Title Description Format
v0.3-beta pylon_gstreamer-0.3-beta.zip zip
Task Owner Creation Date
Add code to automatically check for missing plugins on system
mattb
2017-12-05

Comments

mattb report abuse

Streaming video to browser?

Would anyone like an additional pipeline built which would allow browser-based access to a camera's video stream?
If so, do you have a preference on which webserver should be used as part of this reference sample?
(Browser access requires sinking the pipeline to a webserver on the device with the camera. This could be Apache, Icecast, etc.)

Let me know your thoughts!

- Matt