【GStreamer开发】GStreamer播放教程05——色彩平衡
目标
亮度,对比度,色度和饱和度都是常见的视频调节参数,也是GStreamer里面设置色彩平衡的参数。本教程将展示:
如何发现可用的色彩平衡通道
如何改变它们
介绍
《GStreamer基础教程05——集成GUI工具》里面已经解释了GObject接口:应用通过它们来获得特定功能,而不用去管具体的element的实现。
playbin2实现了色彩平衡的接口(gstcolorbalance),这就可以设置色彩平衡了。如果playbin2里面的任何一个element支持了这个接口,playbin2就仅仅简单地把应用的设置传给element,否则就会在pipeline中增加一个色彩平衡的element。
这个接口允许查询可用的色彩平衡通道(gstcolorbalancechannel),包括它们的名字和值得有效区间,然后调整当前的值。
色彩平衡例子
- #include <string.h>
- #include <gst/gst.h>
- #include <gst/interfaces/colorbalance.h>
- typedef struct _CustomData {
- GstElement *pipeline;
- GMainLoop *loop;
- } CustomData;
- /* Process a color balance command */
- static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {
- gdouble step;
- gint value;
- GstColorBalanceChannel *channel = NULL;
- const GList *channels, *l;
- /* Retrieve the list of channels and locate the requested one */
- channels = gst_color_balance_list_channels (cb);
- for (l = channels; l != NULL; l = l->next) {
- GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;
- if (g_strrstr (tmp->label, channel_name)) {
- channel = tmp;
- break;
- }
- }
- if (!channel)
- return;
- /* Change the channel's value */
- .1 * (channel->max_value - channel->min_value);
- value = gst_color_balance_get_value (cb, channel);
- if (increase) {
- value = (gint)(value + step);
- if (value > channel->max_value)
- value = channel->max_value;
- } else {
- value = (gint)(value - step);
- if (value < channel->min_value)
- value = channel->min_value;
- }
- gst_color_balance_set_value (cb, channel, value);
- }
- /* Output the current values of all Color Balance channels */
- static void print_current_values (GstElement *pipeline) {
- const GList *channels, *l;
- /* Output Color Balance values */
- channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
- for (l = channels; l != NULL; l = l->next) {
- GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;
- gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);
- g_print ("%s: %3d%% ", channel->label,
- 100 * (value - channel->min_value) / (channel->max_value - channel->min_value));
- }
- g_print ("\n");
- }
- /* Process keyboard input */
- static gboolean handle_keyboard (GIOChannel *source, GIOCondition cond, CustomData *data) {
- gchar *str = NULL;
- if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL) {
- return TRUE;
- }
- ])) {
- case 'c':
- ]), GST_COLOR_BALANCE (data->pipeline));
- break;
- case 'b':
- ]), GST_COLOR_BALANCE (data->pipeline));
- break;
- case 'h':
- ]), GST_COLOR_BALANCE (data->pipeline));
- break;
- case 's':
- ]), GST_COLOR_BALANCE (data->pipeline));
- break;
- case 'q':
- g_main_loop_quit (data->loop);
- break;
- default:
- break;
- }
- g_free (str);
- print_current_values (data->pipeline);
- return TRUE;
- }
- int main(int argc, charchar *argv[]) {
- CustomData data;
- GstStateChangeReturn ret;
- GIOChannel *io_stdin;
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
- /* Initialize our data structure */
- , sizeof (data));
- /* Print usage map */
- g_print (
- "USAGE: Choose one of the following options, then press enter:\n"
- " 'C' to increase contrast, 'c' to decrease contrast\n"
- " 'B' to increase brightness, 'b' to decrease brightness\n"
- " 'H' to increase hue, 'h' to decrease hue\n"
- " 'S' to increase saturation, 's' to decrease saturation\n"
- " 'Q' to quit\n");
- /* Build the pipeline */
- data.pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);
- /* Add a keyboard watch so we get notified of keystrokes */
- #ifdef _WIN32
- 2_new_fd (fileno (stdin));
- #else
- io_stdin = g_io_channel_unix_new (fileno (stdin));
- #endif
- g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc)handle_keyboard, &data);
- /* Start playing */
- ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state.\n");
- gst_object_unref (data.pipeline);
- ;
- }
- print_current_values (data.pipeline);
- /* Create a GLib Main Loop and set it to run */
- data.loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (data.loop);
- /* Free resources */
- g_main_loop_unref (data.loop);
- g_io_channel_unref (io_stdin);
- gst_element_set_state (data.pipeline, GST_STATE_NULL);
- gst_object_unref (data.pipeline);
- ;
- }
工作流程
main()函数非常的简单。用一个playbin2的建立pipeline,注册一个键盘处理函数来监控按键。
- /* Output the current values of all Color Balance channels */
- static void print_current_values (GstElement *pipeline) {
- const GList *channels, *l;
- /* Output Color Balance values */
- channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
- for (l = channels; l != NULL; l = l->next) {
- GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;
- gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);
- g_print ("%s: %3d%% ", channel->label,
- 100 * (value - channel->min_value) / (channel->max_value - channel->min_value));
- }
- g_print ("\n");
- }
这个方法展示了如何获得通道的列表并打印所有通道当前的值。这是通过gst_color_balance_list_channels()方法来实现的,它会返回一个GList结构,我们遍历这个结构即可。
在这个列表里面的每一个element都是GstColorBalanceChannel结构,包括通道名,最小值和最大值。然后就可以在每个通道调用gst_color_balance_get_value()方法来获得当前值。
在这个例子中,当前值常常用占最大值的百分比来显示。
- /* Process a color balance command */
- static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {
- gdouble step;
- gint value;
- GstColorBalanceChannel *channel = NULL;
- const GList *channels, *l;
- /* Retrieve the list of channels and locate the requested one */
- channels = gst_color_balance_list_channels (cb);
- for (l = channels; l != NULL; l = l->next) {
- GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;
- if (g_strrstr (tmp->label, channel_name)) {
- channel = tmp;
- break;
- }
- }
- if (!channel)
- return;
这个方法通过指定通道名来确定通道,然后根据操作增加或者减少值。另外,通道列表的获得后是根据指定的名字来解析获得通道的。很显然,这个列表只应该解析一次,指向通道的指针需要保持在比一个字符串更高效的数据结构中。
- /* Change the channel's value */
- .1 * (channel->max_value - channel->min_value);
- value = gst_color_balance_get_value (cb, channel);
- if (increase) {
- value = (gint)(value + step);
- if (value > channel->max_value)
- value = channel->max_value;
- } else {
- value = (gint)(value - step);
- if (value < channel->min_value)
- value = channel->min_value;
- }
- gst_color_balance_set_value (cb, channel, value);
然后就获得当前通道的值,修改它但确保它的值有效,使用gst_color_balance_set_value()来设置。
其它没有什么了。运行一下这个程序实际看一下效果。
【GStreamer开发】GStreamer播放教程05——色彩平衡的更多相关文章
- gstreamer应用开发(播放器)之旅
GStreamer开发,主要分为两块:应用开发.插件开发. 插件开发人员,通常是编解码库的作者(做出了编解码库后,希望gstreamer能用起来这个库,因此增加这个适配层).芯片原厂人员(将自家的hw ...
- 安装gstreamer开发环境
ubuntu中安装gstreamer开发环境: * 安装gstreamer基本库,工具,以及插件 sudo apt--dev gstreamer-tools gstreamer0.-tools gst ...
- 【转】一步一步教你在Ubuntu12.04搭建gstreamer开发环境
原文网址:http://blog.csdn.net/xsl1990/article/details/8333062 闲得蛋疼 无聊寂寞冷 随便写写弄弄 看到网上蛮多搭建gstreamer开 ...
- 开发快平台(M302I小e开发板系列教程)
开发快平台(M302I小e开发板系列教程) 开发块平台ESP8266模块相关理解 一. M302I小e开发板源码注释,源码基于:v1.4.0.8-u34.zip 1. user_main.c /*** ...
- Apple Watch开发快速入门教程
Apple Watch开发快速入门教程 试读下载地址:http://pan.baidu.com/s/1eQ8JdR0 介绍:苹果为Watch提供全新的开发框架WatchKit.本教程是国内第一本A ...
- C#开发Unity游戏教程循环遍历做出判断及Unity游戏示例
C#开发Unity游戏教程循环遍历做出判断及Unity游戏示例 Unity中循环遍历每个数据,并做出判断 很多时候,游戏在玩家做出判断以后,游戏程序会遍历玩家身上大量的所需数据,然后做出判断,即首先判 ...
- C#开发Unity游戏教程之判断语句
C#开发Unity游戏教程之判断语句 游戏执行路径的选择——判断 玩家在游戏时,无时无刻不在通过判断做出选择.例如,正是因为玩家做出的选择不同,才导致游戏朝着不同的剧情发展,因此一个玩家可以对一个游戏 ...
- C#开发Unity游戏教程之游戏对象的行为逻辑方法
C#开发Unity游戏教程之游戏对象的行为逻辑方法 游戏对象的行为逻辑——方法 方法(method),读者在第1章新建脚本时就见过了,而且在第2章对脚本做整体上的介绍时也介绍过,那么上一章呢,尽管主要 ...
- C#开发Unity游戏教程之使用脚本变量
C#开发Unity游戏教程之使用脚本变量 使用脚本变量 本章前面说了那么多关于变量的知识,那么在脚本中要如何编写关于变量的代码,有规章可循吗?答案是有的.本节会依次讲解变量的声明.初始化.赋值和运算. ...
随机推荐
- zabbix 内置key说明
原文参考:https://blog.csdn.net/whs_321/article/details/52939263 一.简介 Zabbix 内置了很多丰富的key,使得我们在添加linux os模 ...
- HDU-盐水的故事
http://acm.hdu.edu.cn/showproblem.php?pid=1408 这是一道高精度问题: 在自己错了数十遍之后找到了不少规律: 首先是Output limit exceede ...
- 关于nginx反代jenkins报错 反向代理设置有误
官方文档地址: https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+behind+Nginx 直接解决的配置文件吧. 这是使用子域名,不使用 ...
- 列出5个python标准库
os:提供了不少与操作系统相关联的函数 sys: 通常用于命令行参数 re: 正则匹配 math: 数学运算 datetime:处理日期时间
- C语言的柔性数组的实现及应用
c编程的时候数组长度一般都是固定好的,实际上c还能实现变长数组.其实c99中确实是有变长数组的说法,C99中通过允许结构体中的最后一个成员是长度未知的数组实现变长数组,其定义格式如下: typedef ...
- 值得H5前端学习的60个JS插件(含DEMO演示)
下面也可以说是H5前端学习的js插件大全.基本包含了大部分的前端最前沿的js插件和库. 布局 SuperEmbed.js- 是一个Javascript库,可检测出网页上的内嵌视频并使他们能够变成响应式 ...
- Perl看完这个,再不敢说自己会玩贪吃蛇
某天闲逛时看见一副动图: 真的是非常贪吃,各种拐弯各种吃,感觉十分有趣. 用Perl来实现自动吃满,蓄谋已久,之前的字符贪吃蛇.深度优先算法.A*算法,都是为此篇做铺垫. 那么,怎样让蛇不吃到自己呢? ...
- IdHTTPServer允许跨域访问
IdHTTPServer允许跨域访问 procedure TMain.idHttpServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTT ...
- Jar hell问题以及解放方法
当一个类或一个资源文件存在多个jar中,就好存在jar hell问题 可以通过以下代码来诊断问题:
- (转)设置了RemoveIPC=yes 的RHEL7.2 会crash掉Oracle asm 实例和Oracle database实例
设置了RemoveIPC=yes 的RHEL7.2 会crash掉Oracle asm 实例和Oracle database实例,该问题也会在使用Shared Memory Segment (SHM ...