2 title: Initializing GStreamer
5 # Initializing GStreamer
7 When writing a GStreamer application, you can simply include `gst/gst.h`
8 to get access to the library functions. Besides that, you will also need
9 to initialize the GStreamer library.
11 ## Simple initialization
13 Before the GStreamer libraries can be used, `gst_init` has to be called
14 from the main application. This call will perform the necessary
15 initialization of the library as well as parse the GStreamer-specific
18 A typical program \[1\] would have code to initialize GStreamer that
30 const gchar *nano_str;
31 guint major, minor, micro, nano;
33 gst_init (&argc, &argv);
35 gst_version (&major, &minor, µ, &nano);
40 nano_str = "(Prerelease)";
44 printf ("This program is linked against GStreamer %d.%d.%d %s\n",
45 major, minor, micro, nano_str);
53 Use the `GST_VERSION_MAJOR`, `GST_VERSION_MINOR` and `GST_VERSION_MICRO`
54 macros to get the GStreamer version you are building against, or use the
55 function `gst_version` to get the version your application is linked
56 against. GStreamer currently uses a scheme where versions with the same
57 major and minor versions are API-/ and ABI-compatible.
59 It is also possible to call the `gst_init` function with two `NULL`
60 arguments, in which case no command line options will be parsed by
63 ## The GOption interface
65 You can also use a GOption table to initialize your own parameters as
66 shown in the next example:
76 gboolean silent = FALSE;
77 gchar *savefile = NULL;
80 GOptionEntry entries[] = {
81 { "silent", 's', 0, G_OPTION_ARG_NONE, &silent,
82 "do not output status information", NULL },
83 { "output", 'o', 0, G_OPTION_ARG_STRING, &savefile,
84 "save xml representation of pipeline to FILE and exit", "FILE" },
88 ctx = g_option_context_new ("- Your application");
89 g_option_context_add_main_entries (ctx, entries, NULL);
90 g_option_context_add_group (ctx, gst_init_get_option_group ());
91 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
92 g_print ("Failed to initialize: %s\n", err->message);
94 g_option_context_free (ctx);
97 g_option_context_free (ctx);
99 printf ("Run me with --help to see the Application options appended.\n");
107 As shown in this fragment, you can use a
108 [GOption](http://developer.gnome.org/glib/stable/glib-Commandline-option-parser.html)
109 table to define your application-specific command line options, and pass
110 this table to the GLib initialization function along with the option
111 group returned from the function `gst_init_get_option_group`. Your
112 application options will be parsed in addition to the standard GStreamer
115 1. The code for this example is automatically extracted from the
116 documentation and built under `tests/examples/manual` in the