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

GStreamer —— 2.18、Windows下Qt加载GStreamer库后运行 - “播放教程 6:音频可视化“(附:完整源码)

运行效果

在这里插入图片描述

介绍

     GStreamer 带有一组将音频转换为视频的元素。他们 可用于科学可视化或为您的音乐增添趣味 player 的本教程展示了:

          • 如何启用音频可视化

          • 如何选择可视化元素

     启用音频可视化实际上非常简单。设置相应的标志,当纯音频流为 found,它将实例化必要的元素来创建和显示可视化。

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 <gst/gst.h>

/* playbin的flag */
typedef enum
{
    GST_PLAY_FLAG_VIS           = (1 << 3) /* 在没有视频流时启用可视化渲染。 */
} GstPlayFlags;

/* 如果这是可视化元素,则返回TRUE */
static gboolean filter_vis_features (GstPluginFeature *feature, gpointer data)
{
    GstElementFactory *factory;

    if (!GST_IS_ELEMENT_FACTORY (feature))
        return FALSE;
    factory = GST_ELEMENT_FACTORY (feature);
    if (!g_strrstr (gst_element_factory_get_klass (factory), "Visualization"))
        return FALSE;

    return TRUE;
}

int main(int argc, char *argv[])
{
    /* d初始化Streamer */
    gst_init (&argc, &argv);

    /* 获取所有可视化插件的列表 */
    GList *list = gst_registry_feature_filter (gst_registry_get (), filter_vis_features, FALSE, NULL);

    /* 打印他们的名字 */
    GstElementFactory *selected_factory = NULL;
    g_print("Available visualization plugins:\n");
    for (GList *walk = list; walk != NULL; walk = g_list_next (walk))
    {
        GstElementFactory *factory = GST_ELEMENT_FACTORY (walk->data);
        const gchar *name = gst_element_factory_get_longname (factory);
        g_print("  %s\n", name);

        if (selected_factory == NULL || g_str_has_prefix (name, "GOOM"))
        {
            selected_factory = factory;
        }
    }
    if (!selected_factory) { g_print ("No visualization plugins found!\n"); return -1; }

    /* 我们现在已经为可视化元素选择了一个工厂 */
    g_print ("Selected '%s'\n", gst_element_factory_get_longname (selected_factory));
    GstElement *vis_plugin = gst_element_factory_create (selected_factory, NULL);
    if (!vis_plugin){return -1;}

    /* 构建管道 */
    GstElement *pipeline = gst_parse_launch ("playbin uri=http://radio.hbr1.com:19800/ambient.ogg", NULL);

    /* 设置可视化标志 */
    guint flags;
    g_object_get (pipeline, "flags", &flags, NULL);
    flags |= GST_PLAY_FLAG_VIS;
    g_object_set (pipeline, "flags", flags, NULL);

    /* 为playbin设置vis插件 */
    g_object_set (pipeline, "vis-plugin", vis_plugin, NULL);

    /* 开始播放 */
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    /* 等待直到错误或结束 */
    GstBus *bus = gst_element_get_bus (pipeline);
    GstMessage *msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));

    /* 释放资源 */
    if (msg != NULL){ gst_message_unref (msg); }
    gst_plugin_feature_list_free (list);
    gst_object_unref (bus);
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    return 0;
}

关注

笔者 - jxd

http://www.dtcms.com/a/62366.html

相关文章:

  • ubuntu挂载新硬盘
  • 5G工业路由器赋能无人码头,港口物流智能化管理
  • 大语言模型-语言模型发展历程
  • 安徽通信施工安全员ABC证备考练习题及答案
  • 项目部署到生产上遇到的网络问题
  • 【鸿蒙开发】MongoDB入门
  • minio数据迁移
  • 利用微软的 HTML 应用程序宿主程序的攻击
  • 【2025】基于python+django的考研自习室预约系统(源码、万字文档、图文修改、调试答疑)
  • 简要分析NETLINK_KOBJECT_UEVENT参数
  • SegMAN模型详解及代码复现
  • 预防痉挛性斜颈的护理方法
  • 华为hcia——Datacom实验指南——以太网帧和IPV4数据包格式(一)
  • DeepSeek-R1 论文阅读总结
  • skywalking部署与应用
  • ES5 vs ES6:JavaScript 演进之路
  • 软件安全分析与应用之综合安全应用 (三)
  • 01_LVGL 对象与盒子模型详解
  • GStreamer —— 2.15、Windows下Qt加载GStreamer库后运行 - “播放教程 1:Playbin 使用“(附:完整源码)
  • Windows批处理脚本入门教程
  • Ceph(2):Ceph简介
  • 自定义Linux网络协议的开发与测试
  • 暑期第一面oωo, TME一面面经
  • 用Python和Docker-py打造高效容器化应用管理利器
  • HTML基础知识
  • 机器视觉条形光源应用解析
  • 【设计模式】设计模式的分类与组织
  • IDEA2024又一坑:连接Docker服务连不上,提示:Cannot run program “docker“: CreateProcess error=2
  • 车载以太网测试-6【数据链路层】
  • 【从零开始学习计算机科学】操作系统(十)操作系统的引导程序 与 系统安全