当前位置: 首页 > news >正文

GStreamer —— 2.17、Windows下Qt加载GStreamer库后运行 - “播放教程 5:色彩平衡“(附:完整源码)

运行效果

在这里插入图片描述

介绍

     亮度、对比度、色相和饱和度是常见的视频调整, 在 GStreamer 中统称为 Color Balance 设置。 本教程展示了:

          • 如何找出可用的色彩平衡通道

          • 如何更改它们

     允许访问颜色平衡设置。如果 元素支持这个接口,只需将其转发给应用程序,否则会有一个 colorbalance 元素插入到管道中。

GStreamer相关运行库
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/gstreamer-1.0/gst
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/gstreamer-1.0
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/glib-2.0
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/lib/glib-2.0/include

LIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/gstreamer-1.0.lib
LIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/glib-2.0.lib
LIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/gobject-2.0.lib

源码
#include <string.h>
#include <stdio.h>
#include <gst/gst.h>
#include <gst/video/colorbalance.h>

typedef struct _CustomData
{
    GstElement *pipeline;
    GMainLoop *loop;
} CustomData;

/* 处理色彩平衡命令 */
static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb)
{
    GstColorBalanceChannel *channel = NULL;

    /* 检索频道列表并找到所请求的频道 */
    const GList *channels = gst_color_balance_list_channels (cb);
    for (const GList *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;}

    /* 更改通道值 */
    gdouble step = 0.1 * (channel->max_value - channel->min_value);
    gint 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 = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
    for (const GList *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");
}

/* 处理键盘输入 */
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; }

    switch (g_ascii_tolower (str[0]))
    {
    case 'c':
        update_color_channel ("CONTRAST", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
        break;
    case 'b':
        update_color_channel ("BRIGHTNESS", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
        break;
    case 'h':
        update_color_channel ("HUE", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
        break;
    case 's':
        update_color_channel ("SATURATION", g_ascii_isupper (str[0]), 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, char *argv[])
{
    /* 初始化GStreamer */
    gst_init (&argc, &argv);

    /* 初始化数据结构 */
    CustomData data;
    memset (&data, 0, sizeof (data));

    /* 打印按键功能 */
    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");

    /* 构建管道 */
    data.pipeline = gst_parse_launch ("playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm", NULL);

    /* 添加键盘监视器,以便我们收到按键通知 */
#ifdef G_OS_WIN32
    GIOChannel *io_stdin = g_io_channel_win32_new_fd (fileno (stdin));
#else
    GIOChannel *io_stdin = g_io_channel_unix_new (fileno (stdin));
#endif
    g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc)handle_keyboard, &data);

    /* 开始播放 */
    GstStateChangeReturn 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);
        return -1;
    }
    print_current_values (data.pipeline);

    /* 创建GLib主循环 */
    data.loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (data.loop);

    /* 释放资源 */
    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);
    return 0;
}

关注

笔者 - jxd

相关文章:

  • 基于Debian12的SVN和Trac自动安装部署脚本
  • upload-labs-master通关攻略(17~19)
  • RSA算法:开启现代密码学的数学之钥
  • SpringMVC中有关请求参数的问题(映射路径,传递不同的参数)
  • 前端小食堂 | Day13 - Vue.js 进阶烹饪术
  • RISC-V特权模式与寄存器
  • 计网面试准备
  • Vue的生命周期
  • Ubuntu 下 nginx-1.24.0 源码分析 - ngx_conf_param
  • FreeRTOS(7)队列集
  • Redis 主从复制详解:实现高可用与数据备份
  • 【MySQL - 表的内外连接】
  • 【13】单片机编程核心技巧:乘法运算
  • 《Python全栈开发》第2课:HTML骨架搭建 - 从零编写个人简历页面
  • 数字IC后端设计实现教程 |Innovus ICC2 Routing Pin Access Setting设置方法
  • 第十五届蓝桥杯大学B组(握手问题、小球反弹、好数)
  • ChatGPT课件分享(37页PPT)
  • 【亲测有效】Mac系统升级或降级Node.js版本,Mac系统调整node.js版本
  • 【3D视觉学习笔记1】针孔相机模型与坐标系变换
  • 【Azure 架构师学习笔记】- Azure Databricks (17) --Delta Live Table和Delta Table
  • 外卖员投资失败负疚离家流浪,经民警劝回后泣不成声给父母下跪
  • 圆桌丨中俄权威专家详解:两国携手维护战后国际秩序,捍卫国际公平正义
  • 习近平向“和平薪火 时代新章——纪念中国人民抗日战争和苏联伟大卫国战争胜利80周年中俄人文交流活动”致贺信
  • 中科院院士魏辅文已卸任江西农业大学校长
  • 印方称若巴方决定升级局势,印方已做好反击准备
  • 央行:增加支农支小再贷款额度3000亿元