[gstreamer] goption

■ The GOption interface:

goption.c

 1 #include <gst/gst.h>
 2 #include <stdio.h>
 3 int
 4 main (int   argc,
 5       char *argv[])
 6 {
 7   gboolean silent = FALSE;
 8   gchar *savefile = NULL;
 9   GOptionContext *ctx;
10   GError *err = NULL;
11   GOptionEntry entries[] = {
12     { "silent", 's', 0, G_OPTION_ARG_NONE, &silent,
13       "do not output status information", NULL },
14     { "output", 'o', 0, G_OPTION_ARG_STRING, &savefile,
15       "save xml representation of pipeline to FILE and exit", "FILE" },
16     { NULL }
17   };
18 
19   ctx = g_option_context_new ("- Your application");
20   g_option_context_add_main_entries (ctx, entries, NULL);
21   g_option_context_add_group (ctx, gst_init_get_option_group ());
22   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
23     g_print ("Failed to initialize: %s\n", err->message);
24     g_clear_error (&err);
25     g_option_context_free (ctx);
26     return 1;
27   }
28   g_option_context_free (ctx);
29 
30   printf ("Run me with --help to see the Application options appended.\n");
31   printf ("silent = %d savefile=%s.\n", silent, savefile);
32 
33   return 0;
34 }

■ 编译

gcc goption.c -o goption `pkg-config --cflags --libs gstreamer-1.0`

■ 运行结果

renhl@renhl:~/share/1/goption$ ./goption -o test.txt
Run me with --help to see the Application options appended.
silent = 0 savefile=test.txt.
renhl@renhl:~/share/1/goption$ ./goption -s 1  -o test.txt
Run me with --help to see the Application options appended.
silent = 1 savefile=test.txt.
renhl@renhl:~/share/1/goption$ vim goption.c

■ 参考

https://developer.gnome.org/glib/stable/glib-Commandline-option-parser.html

https://gstreamer.freedesktop.org/documentation/application-development/basics/init.html#the-goption-interface

猜你喜欢

转载自www.cnblogs.com/renhl/p/10743760.html