zoukankan      html  css  js  c++  java
  • [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
    ", 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.
    ");
    31   printf ("silent = %d savefile=%s.
    ", 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

  • 相关阅读:
    java+opencv实现图像灰度化
    java实现高斯平滑
    hdu 3415 单调队列
    POJ 3368 Frequent values 线段树区间合并
    UVA 11795 Mega Man's Mission 状态DP
    UVA 11552 Fewest Flops DP
    UVA 10534 Wavio Sequence DP LIS
    UVA 1424 uvalive 4256 Salesmen 简单DP
    UVA 1099 uvalive 4794 Sharing Chocolate 状态DP
    UVA 1169uvalive 3983 Robotruck 单调队列优化DP
  • 原文地址:https://www.cnblogs.com/renhl/p/10743760.html
Copyright © 2011-2022 走看看