This time I’d like to share some piece of code I find very useful when experimenting with GStreamer. This includes writing some small tests to understand some features and all sort of debugging of specific cases after distilling them from larger applications.
The thing is that I don’t want to start over and over again with the common
stuff whenever I want to quickly hack a GStreamer application. This is mostly
about writing the
main() function and some bits and pieces:
- parse command line options
- initialise GStreamer
- create the pipeline
- optionally add a probe
- optionally send EOS
At the same time I want to keep it simple and not turn it into some versatile utility which would obfuscate the main idea. Plain simple. I know there’s gst-template project but as I understand it’s more GStreamer plugin oriented and helps with some GLib/GObject boilerplate.
The goal for this “template” is to be reusable but mostly for some throw-away prototypes or tests. But still I wanted to keep the quality as high as possible, include proper error checking etc. as in practice a lot of prototype code ends up in production.
The cool thing about it is that it reads the pipeline description from the
command line which is very useful when experimenting/debugging. It also offers
sending EOS event upon SIGINT (-e), adding probe on a pad (-p) and verbose
output (-v) if e.g. one wants see the output of a identity element. There are
few gaps to fill in, all marked with
TODO, e.g. the type of probe and probe
return value. As I said I didn’t want to over-complicate this so I left it to
edit in the code.
Building and running
And a couple of tests: