目标

亮度,对比度,色度和饱和度都是常见的视频调节参数,也是GStreamer里面设置色彩平衡的参数。本教程将展示:

如何发现可用的色彩平衡通道

如何改变它们

介绍

GStreamer基础教程05——集成GUI工具》里面已经解释了GObject接口:应用通过它们来获得特定功能,而不用去管具体的element的实现。

playbin2实现了色彩平衡的接口(gstcolorbalance),这就可以设置色彩平衡了。如果playbin2里面的任何一个element支持了这个接口,playbin2就仅仅简单地把应用的设置传给element,否则就会在pipeline中增加一个色彩平衡的element。

这个接口允许查询可用的色彩平衡通道(gstcolorbalancechannel),包括它们的名字和值得有效区间,然后调整当前的值。

色彩平衡例子

[objc] view
plain
 copy

  1. #include <string.h>
  2. #include <gst/gst.h>
  3. #include <gst/interfaces/colorbalance.h>
  4. typedef struct _CustomData {
  5. GstElement *pipeline;
  6. GMainLoop *loop;
  7. } CustomData;
  8. /* Process a color balance command */
  9. static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {
  10. gdouble step;
  11. gint value;
  12. GstColorBalanceChannel *channel = NULL;
  13. const GList *channels, *l;
  14. /* Retrieve the list of channels and locate the requested one */
  15. channels = gst_color_balance_list_channels (cb);
  16. for (l = channels; l != NULL; l = l->next) {
  17. GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;
  18. if (g_strrstr (tmp->label, channel_name)) {
  19. channel = tmp;
  20. break;
  21. }
  22. }
  23. if (!channel)
  24. return;
  25. /* Change the channel's value */
  26. .1 * (channel->max_value - channel->min_value);
  27. value = gst_color_balance_get_value (cb, channel);
  28. if (increase) {
  29. value = (gint)(value + step);
  30. if (value > channel->max_value)
  31. value = channel->max_value;
  32. } else {
  33. value = (gint)(value - step);
  34. if (value < channel->min_value)
  35. value = channel->min_value;
  36. }
  37. gst_color_balance_set_value (cb, channel, value);
  38. }
  39. /* Output the current values of all Color Balance channels */
  40. static void print_current_values (GstElement *pipeline) {
  41. const GList *channels, *l;
  42. /* Output Color Balance values */
  43. channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
  44. for (l = channels; l != NULL; l = l->next) {
  45. GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;
  46. gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);
  47. g_print ("%s: %3d%% ", channel->label,
  48. 100 * (value - channel->min_value) / (channel->max_value - channel->min_value));
  49. }
  50. g_print ("\n");
  51. }
  52. /* Process keyboard input */
  53. static gboolean handle_keyboard (GIOChannel *source, GIOCondition cond, CustomData *data) {
  54. gchar *str = NULL;
  55. if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL) {
  56. return TRUE;
  57. }
  58. ])) {
  59. case 'c':
  60. ]), GST_COLOR_BALANCE (data->pipeline));
  61. break;
  62. case 'b':
  63. ]), GST_COLOR_BALANCE (data->pipeline));
  64. break;
  65. case 'h':
  66. ]), GST_COLOR_BALANCE (data->pipeline));
  67. break;
  68. case 's':
  69. ]), GST_COLOR_BALANCE (data->pipeline));
  70. break;
  71. case 'q':
  72. g_main_loop_quit (data->loop);
  73. break;
  74. default:
  75. break;
  76. }
  77. g_free (str);
  78. print_current_values (data->pipeline);
  79. return TRUE;
  80. }
  81. int main(int argc, charchar *argv[]) {
  82. CustomData data;
  83. GstStateChangeReturn ret;
  84. GIOChannel *io_stdin;
  85. /* Initialize GStreamer */
  86. gst_init (&argc, &argv);
  87. /* Initialize our data structure */
  88. , sizeof (data));
  89. /* Print usage map */
  90. g_print (
  91. "USAGE: Choose one of the following options, then press enter:\n"
  92. " 'C' to increase contrast, 'c' to decrease contrast\n"
  93. " 'B' to increase brightness, 'b' to decrease brightness\n"
  94. " 'H' to increase hue, 'h' to decrease hue\n"
  95. " 'S' to increase saturation, 's' to decrease saturation\n"
  96. " 'Q' to quit\n");
  97. /* Build the pipeline */
  98. data.pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);
  99. /* Add a keyboard watch so we get notified of keystrokes */
  100. #ifdef _WIN32
  101. 2_new_fd (fileno (stdin));
  102. #else
  103. io_stdin = g_io_channel_unix_new (fileno (stdin));
  104. #endif
  105. g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc)handle_keyboard, &data);
  106. /* Start playing */
  107. ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
  108. if (ret == GST_STATE_CHANGE_FAILURE) {
  109. g_printerr ("Unable to set the pipeline to the playing state.\n");
  110. gst_object_unref (data.pipeline);
  111. ;
  112. }
  113. print_current_values (data.pipeline);
  114. /* Create a GLib Main Loop and set it to run */
  115. data.loop = g_main_loop_new (NULL, FALSE);
  116. g_main_loop_run (data.loop);
  117. /* Free resources */
  118. g_main_loop_unref (data.loop);
  119. g_io_channel_unref (io_stdin);
  120. gst_element_set_state (data.pipeline, GST_STATE_NULL);
  121. gst_object_unref (data.pipeline);
  122. ;
  123. }

工作流程

main()函数非常的简单。用一个playbin2的建立pipeline,注册一个键盘处理函数来监控按键。

[objc] view
plain
 copy

  1. /* Output the current values of all Color Balance channels */
  2. static void print_current_values (GstElement *pipeline) {
  3. const GList *channels, *l;
  4. /* Output Color Balance values */
  5. channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
  6. for (l = channels; l != NULL; l = l->next) {
  7. GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;
  8. gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);
  9. g_print ("%s: %3d%% ", channel->label,
  10. 100 * (value - channel->min_value) / (channel->max_value - channel->min_value));
  11. }
  12. g_print ("\n");
  13. }

这个方法展示了如何获得通道的列表并打印所有通道当前的值。这是通过gst_color_balance_list_channels()方法来实现的,它会返回一个GList结构,我们遍历这个结构即可。

在这个列表里面的每一个element都是GstColorBalanceChannel结构,包括通道名,最小值和最大值。然后就可以在每个通道调用gst_color_balance_get_value()方法来获得当前值。

在这个例子中,当前值常常用占最大值的百分比来显示。

[objc] view
plain
 copy

  1. /* Process a color balance command */
  2. static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {
  3. gdouble step;
  4. gint value;
  5. GstColorBalanceChannel *channel = NULL;
  6. const GList *channels, *l;
  7. /* Retrieve the list of channels and locate the requested one */
  8. channels = gst_color_balance_list_channels (cb);
  9. for (l = channels; l != NULL; l = l->next) {
  10. GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;
  11. if (g_strrstr (tmp->label, channel_name)) {
  12. channel = tmp;
  13. break;
  14. }
  15. }
  16. if (!channel)
  17. return;

这个方法通过指定通道名来确定通道,然后根据操作增加或者减少值。另外,通道列表的获得后是根据指定的名字来解析获得通道的。很显然,这个列表只应该解析一次,指向通道的指针需要保持在比一个字符串更高效的数据结构中。

[objc] view
plain
 copy

  1. /* Change the channel's value */
  2. .1 * (channel->max_value - channel->min_value);
  3. value = gst_color_balance_get_value (cb, channel);
  4. if (increase) {
  5. value = (gint)(value + step);
  6. if (value > channel->max_value)
  7. value = channel->max_value;
  8. } else {
  9. value = (gint)(value - step);
  10. if (value < channel->min_value)
  11. value = channel->min_value;
  12. }
  13. gst_color_balance_set_value (cb, channel, value);

然后就获得当前通道的值,修改它但确保它的值有效,使用gst_color_balance_set_value()来设置。

其它没有什么了。运行一下这个程序实际看一下效果。

【GStreamer开发】GStreamer播放教程05——色彩平衡的更多相关文章

  1. gstreamer应用开发(播放器)之旅

    GStreamer开发,主要分为两块:应用开发.插件开发. 插件开发人员,通常是编解码库的作者(做出了编解码库后,希望gstreamer能用起来这个库,因此增加这个适配层).芯片原厂人员(将自家的hw ...

  2. 安装gstreamer开发环境

    ubuntu中安装gstreamer开发环境: * 安装gstreamer基本库,工具,以及插件 sudo apt--dev gstreamer-tools gstreamer0.-tools gst ...

  3. 【转】一步一步教你在Ubuntu12.04搭建gstreamer开发环境

    原文网址:http://blog.csdn.net/xsl1990/article/details/8333062 闲得蛋疼    无聊寂寞冷    随便写写弄弄 看到网上蛮多搭建gstreamer开 ...

  4. 开发快平台(M302I小e开发板系列教程)

    开发快平台(M302I小e开发板系列教程) 开发块平台ESP8266模块相关理解 一. M302I小e开发板源码注释,源码基于:v1.4.0.8-u34.zip 1. user_main.c /*** ...

  5. Apple Watch开发快速入门教程

     Apple Watch开发快速入门教程  试读下载地址:http://pan.baidu.com/s/1eQ8JdR0 介绍:苹果为Watch提供全新的开发框架WatchKit.本教程是国内第一本A ...

  6. C#开发Unity游戏教程循环遍历做出判断及Unity游戏示例

    C#开发Unity游戏教程循环遍历做出判断及Unity游戏示例 Unity中循环遍历每个数据,并做出判断 很多时候,游戏在玩家做出判断以后,游戏程序会遍历玩家身上大量的所需数据,然后做出判断,即首先判 ...

  7. C#开发Unity游戏教程之判断语句

    C#开发Unity游戏教程之判断语句 游戏执行路径的选择——判断 玩家在游戏时,无时无刻不在通过判断做出选择.例如,正是因为玩家做出的选择不同,才导致游戏朝着不同的剧情发展,因此一个玩家可以对一个游戏 ...

  8. C#开发Unity游戏教程之游戏对象的行为逻辑方法

    C#开发Unity游戏教程之游戏对象的行为逻辑方法 游戏对象的行为逻辑——方法 方法(method),读者在第1章新建脚本时就见过了,而且在第2章对脚本做整体上的介绍时也介绍过,那么上一章呢,尽管主要 ...

  9. C#开发Unity游戏教程之使用脚本变量

    C#开发Unity游戏教程之使用脚本变量 使用脚本变量 本章前面说了那么多关于变量的知识,那么在脚本中要如何编写关于变量的代码,有规章可循吗?答案是有的.本节会依次讲解变量的声明.初始化.赋值和运算. ...

随机推荐

  1. RookeyFrame 迁移 线下Model 新增属性 迁移 到数据库

    在类库 Rookey.BusSys.Operate(类库) -> InitOperate.cs(类)  -> App_Start(方法) 添加代码(举例): ToolOperate.Rep ...

  2. C语言函数的定义和使用(2)

    一:无参函数 类型说明符 get(){ //函数体 } 二:无参函数 类型说明符 getname(int a,int b){ //函数体 } 三:类型说明符包括: int ,char,float,do ...

  3. 10分钟手把手教你运用Python实现简单的人脸识别

    欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 前言:让我的电脑认识我 我的电脑只有认识我,才配称之为我的电脑! 今天,我们用Python实现高大上的人脸识别技术! Python里,简单的 ...

  4. Angular惰性加载的特性模块

    一:Angular-CLI建立应用 cmd命令:ng new lazy-app --routing    (创建一个名叫 lazy-app 的应用,而 --routing 标识生成了一个名叫 app- ...

  5. PowerBuilder 这么古老的语言(破解一软件)

     PowerBuilder 这么古老的语言,编辑器用的6.5的好古老的气息,好吧破解木有兴趣了, 不过嘛可以说一下破解思路,这个系统使用的是圣天狗,联网版的. 复制狗(暴力,没技术味道) 模拟狗(也是 ...

  6. 数据结构Java版之二叉查找树(七)

    二叉查找树(BST : BInary Search Tree) 二叉查找树的性质: 1.每一个元素有一个键值 2.左子树的键值都小于根节点的键值 3.右子树的键值都大于根节点的键值 4.左右子树都是二 ...

  7. docker nginx angular 刷新错误,404错误

    主要是router问题,两个解决方案 一个是修改angular项目的router选项,一个是修改Nginx的route 选项 一般情况下项目部署了,不愿意修改angular项目的router选项,所以 ...

  8. flink 读JDQ和写JDQ的流程

    ReadFromJDQ3 1)消费JDQ的必要信息,通过参数传入,有6个参数 2)获取flink JDQ3的鉴权客户端 3)根据鉴权客户端获取消费属性的配置 4)构建应用环境ENV和checkpoin ...

  9. PrivateIpAddresses Array of String 实例主网卡的内网IP列表。 PublicIpAddresses Array of String 实例主网卡的公网IP列表。 注意:此字段可能返回 null,表示取不到有效值。

    https://cloud.tencent.com/document/api/213/15753 浮动 IP 地址 https://cloud.google.com/solutions/best-pr ...

  10. Mini学习之mini.DataGrid使用说明

    参考:http://miniui.com/docs/api/index.html#ui=datagrid mini.DataGrid表格.实现分页加载.自定义列.单元格渲染.行编辑器.锁定列.过滤行. ...