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
- parse command line options
- initialise GStreamer
- create the pipeline
- optionally add a probe
- optionally send EOS
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
Building and running
libtool --mode=link \ gcc -O2 \ $(pkg-config --cflags --libs gstreamer-1.0) \ gst-test-app.c \ -o /tmp/testAnd a couple of tests:
[kris@lenovo-x1 master]$ /tmp/test -e fakesrc ! fakesink ** Message: Running... ^C** Message: Handling interrupt: forcing EOS on the pipeline ** Message: End of stream ** Message: Returned, stopping playback
[kris@lenovo-x1 master]$ /tmp/test -e -p "sink:sink" videotestsrc num-buffers=5 ! fakesink name=sink ** Message: Successfully installed probe on 'sink:sink' ** Message: Running... Got event: stream-start ** (lt-test:27135): WARNING **: TODO: Implement me!!! Got event: caps ** (lt-test:27135): WARNING **: TODO: Implement me!!! Got event: segment ** (lt-test:27135): WARNING **: TODO: Implement me!!! Got event: eos ** (lt-test:27135): WARNING **: TODO: Implement me!!! ** Message: End of stream ** Message: Returned, stopping playbackVoilà! Enjoy!