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.
The program above is modified from an example in the PDF document; Chapter 20 has an example program related to "decodebin". This program does the following:
- 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.
The callback function, cb_newpad, is also modified from an example from the PDF document. The original code was implemented only for audio but I added video pad linking as well. I am not sure if it has to un-reference GstStructure but the original code didn't.
The callback function, my_bus_callback, is also from the PDF document. It is to interact with GStreamer on various events.
You will need to change the URL as your setting; IP address, user id and password.
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.
The screenshot above shows how to compile and execute. It generates the movie file. I had to ^C to stop it because the program is not ready for a proper shutdown. lol. I think I can shutdown properly with the "loop" but it will be for another article.
To make sure it is H.264 encoded, I opened it from Windows version of VLC.
No comments:
Post a Comment