59 | | To capture an image from an app a **system** call could be used to perform the above command line. However, it would be better to use the gstreamer library within the code. An example of this will be added to this page at a later date. |
| 59 | To capture an image from an app a **system** call could be used to perform the above command line. However, it is better to use the gstreamer library within the code. An example function to capture an image follows: |
| 60 | |
| 61 | {{{ |
| 62 | void WebCamCapture(const char* writePath) |
| 63 | { |
| 64 | char cmd[200]; |
| 65 | GstElement* pipeline; |
| 66 | GstBus* bus; |
| 67 | GstMessage* msg; |
| 68 | |
| 69 | snprintf(cmd, sizeof(cmd), "v4l2src device=/dev/video2 num-buffers=1 ! jpegenc ! filesink location=%s", writePath); |
| 70 | pipeline = gst_parse_launch(cmd, NULL); |
| 71 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
| 72 | |
| 73 | /* Wait until error or EOS */ |
| 74 | bus = gst_element_get_bus(pipeline); |
| 75 | msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); |
| 76 | if(msg != NULL) { |
| 77 | gst_message_unref(msg); |
| 78 | } |
| 79 | gst_object_unref(bus); |
| 80 | gst_element_set_state(pipeline, GST_STATE_NULL); |
| 81 | gst_object_unref(pipeline); |
| 82 | } |
| 83 | }}} |