用 Gstreamer 将摄像头实时视频保存至文件
#include <gst/gst.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
GstElement *pipeline, *v4l2src, *encoder, *muxer, *filesink;
gst_init(&argc, &argv);
gchar *launch = g_strdup_printf ("v4l2src ! videoconvert ! x264enc threads=4 sliced-threads=TRUE tune=zerolatency ! matroskamux ! filesink location = output.mp4");
pipeline = gst_parse_launch (launch, NULL);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
while (gst_bin_iterate_elements (GST_BIN (pipeline)));
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
exit (0);
}