Windows平台RTSP|RTMP播放器如何叠加OSD文字

简介: 做Windows平台RTSP|RTMP播放器的时候,特别是多路播放场景下,开发者希望可以给每一路RTSP或RTMP流添加个额外的OSD台标,以区分不同的设备信息(比如添加摄像头所在位置),本文主要探讨,如何动态添加OSD台标。

技术背景

我们在做Windows平台RTSP|RTMP播放器的时候,特别是多路播放场景下,开发者希望可以给每一路RTSP或RTMP流添加个额外的OSD台标,以区分不同的设备信息(比如添加摄像头所在位置),本文主要探讨,如何动态添加OSD台标。

技术实现

以大牛直播SDK的C#的RTSP|RTMP播放demo为例,分享下设计实现流程。选中“设置台标”复选框,在player窗口左上角显示“叠加字符展示”,具体内容、坐标可自定义,如果需要关闭台标,可以随时关闭:

image.gif

实现代码如下:

/*
 * SmartPlayerForm.cs
 * Created by daniusdk.com on 2017/04/19.
 * WeChat: xinsheng120
 */
private void DrawOSD(string draw_text)
{
    // gdi 绘制的话,文本请自己绘制
    if (is_gdi_render_)
        return;
    if (player_handle_ == IntPtr.Zero)
        return;
    if (draw_text == null || draw_text.Length < 1)
    {
        NTSmartPlayerSDK.NT_SP_SetRenderARGBLogo(player_handle_, IntPtr.Zero, 0, 0, 0, 0, 0, 0, 0);
        return;
    }
    Graphics graphics = this.CreateGraphics();
    SolidBrush solid_brush = new SolidBrush(Color.FromArgb(255, 255, 255));
    graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    SizeF text_size = new SizeF();
    text_size = graphics.MeasureString(draw_text, this.Font);
    int image_w = (int)text_size.Width + 4;
    int image_h = (int)text_size.Height + 4;
    image_w = (int)ByteAlign((UInt32)image_w, 4);
    image_h = (int)ByteAlign((UInt32)image_h, 4);
    Bitmap bmp = new Bitmap(image_w, image_h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    Graphics g = Graphics.FromImage(bmp);
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
    float left = image_w / 2 - text_size.Width / 2;
    float top = image_h / 2 - text_size.Height / 2;
    g.DrawString(draw_text, this.Font, solid_brush, left, top);
    Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    System.Drawing.Imaging.BitmapData bmp_data = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);
    IntPtr ptr = bmp_data.Scan0;
    int strdie = Math.Abs(bmp_data.Stride);
    NTSmartPlayerSDK.NT_SP_SetRenderARGBLogo(player_handle_, ptr, strdie, bmp_data.Width,
        bmp_data.Height, 6, 6, bmp_data.Width, bmp_data.Height);
    // Unlock the bits.
    bmp.UnlockBits(bmp_data);
}
}

image.gif

总结

Windows平台RTSP|RTMP播放器动态添加OSD文字台标,在实时监控场景下,非常实用,特别是多路场景,以上是大概的实现思路,可能还有开发者说,如果是添加的OSD文字台标,想录制下来,怎么办?实际上,我们也有分享过,可以把播放端解码后的YUV数据回调上来,投递到推送模块,然后,OSD文字水印,以图层的形式添加进去,录像即可,感兴趣的开发者,可以单独跟我沟通探讨。

相关文章
|
6月前
|
监控 编译器 Windows
Qt5实现Windows平台串口通信
Qt5实现Windows平台串口通信
|
6月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
641 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
6月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
506 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
7月前
|
安全 Linux API
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
261 0
|
6月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
1762 2
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
|
6月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
758 0
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
|
6月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
994 0
|
7月前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
578 1
|
7月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
5302 3
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
|
7月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
1984 2

热门文章

最新文章