Unfortunately I need to skip how to install GStreamer library in this article, which is the most tricky step. It is because GStreamer-1.0 is not yet included in the Rasbian package system. I wrote another article about how to install GStreamer-1.0 manually on Raspberry Pi but your mileage may vary.
- initialize GStreamer with gst_init().
- check the version of GStreamer; the version has to be 1.0 or above.
- creates loop and pipeline.
- assign a call back function, my_bus_callback, to the bus that came from the pipeline.
- create bunch of elements: uridecodebin, omxh264enc, h264parse, lamemp3enc, matroskamux, filesink, videoconvert and audioconvert.
- set the source location and destination location; source in this case is the foscam camera URL and the destination is a MKV file name.
- set an call back function, cb_newpad, to the uridecodebin; this step has to be dynamic because uridecodebin will not know what file type it is going to take from the URL at compile time.
- link the rest of the elements; there is no dynamic linking needed for those.
- let GStreamer running in loop.
- clean up once the program is done running, which wouldn't happen in this case because the camera will never have end of stream.
One thing that I learned is that I couldn't change the target-bitrate or anything about omxh264enc. I complains that the version is mismatching. I think it is a kind of bug in the encoder; of course your mileage may vary on this as well.
Note that the Makefile now has CFLAGS with GStreamer compile flags. It comes with an external utility, pkg-config. pkg-config will return the compile flag for GStreamer-1.0.