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

  • 相关阅读:
    windows下端口映射(端口转发)
    SQLServer 2008 复制同步(发布、订阅)的几个问题
    SqlServer:此数据库处于单用户模式,导致数据库无法删除的处理
    jQuery函数的等价原生函数【转载】
    JavaScript学习第三天
    持续集成工具hudson【转载】
    linux-unzip命令【转载】
    javascript学习第一天
    java.util.Properties
    Eclipse快捷键【转载】
  • 原文地址:https://www.cnblogs.com/renhl/p/10743760.html
Copyright © 2011-2022 走看看