Linux(麒麟系统)多显示器屏幕录制
Linux桌面设备在接入多显示器的情况下,有些只录主显示器,有些场景要单独录制每个显示器,X Window System支持多显示器配置和显示器列表获取,需要XRandR 1.5及以上版本,查看RandR version 命令:
xrandr --version
使用xrandr查看显示器列表:
xrandr --listactivemonitors
" --listactivemonitors" 详细说明:
libXrandr提供了获取显示器列表的接口(Xrandr.h):
/** Copyright © 2000 Compaq Computer Corporation, Inc.* Copyright © 2002 Hewlett-Packard Company, Inc.* Copyright © 2006 Intel Corporation* Copyright © 2008 Red Hat, Inc.** Permission to use, copy, modify, distribute, and sell this software and its* documentation for any purpose is hereby granted without fee, provided that* the above copyright notice appear in all copies and that both that copyright* notice and this permission notice appear in supporting documentation, and* that the name of the copyright holders not be used in advertising or* publicity pertaining to distribution of the software without specific,* written prior permission. The copyright holders make no representations* about the suitability of this software for any purpose. It is provided "as* is" without express or implied warranty.** THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE* OF THIS SOFTWARE.** Author: Jim Gettys, HP Labs, Hewlett-Packard, Inc.* Keith Packard, Intel Corporation*/#ifndef _XRANDR_H_
#define _XRANDR_H_#include <X11/extensions/randr.h>
#include <X11/extensions/Xrender.h>#include <X11/Xfuncproto.h>_XFUNCPROTOBEGINtypedef struct _XRRMonitorInfo {Atom name;Bool primary;Bool automatic;int noutput;int x;int y;int width;int height;int mwidth;int mheight;RROutput *outputs;
} XRRMonitorInfo;XRRMonitorInfo *
XRRAllocateMonitor(Display *dpy, int noutput);XRRMonitorInfo *
XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors);void
XRRSetMonitor(Display *dpy, Window window, XRRMonitorInfo *monitor);void
XRRDeleteMonitor(Display *dpy, Window window, Atom name);void
XRRFreeMonitors(XRRMonitorInfo *monitors);_XFUNCPROTOEND#endif /* _XRANDR_H_ */
为方便集成调用,SDK提供了获取显示器列表和选择采集显示器的接口:
/** Copyright (C) 1130758427@qq.com. All rights reserved. * 问题沟通微信:ldxevt*//** 获取active XRR-Monitor列表, X RandR 1.5及以上版本支持(用:"xrandr --version"查看版本)* x_display_name:传入实际使用的名称或者NULL,调用XOpenDisplay时使用.* monitors: 预分配的XRR-Monitor数组* monitors_array_size: 预分配的XRR-Monitor数组长度* out_count: 返回实际的XRR-Monitor数量* 成功返回:NT_ERC_OK, 如果返回值是:NT_ERC_MORE_DATA, 说明预分配的数组长度不够, 请分配更大的数组再尝试.*/NT_UINT32 NT_API NT_PB_GetXRRMonitors(NT_PCSTR x_display_name, NT_PB_XRR_MonitorBaseInfo* monitors, NT_INT32 monitors_array_size, NT_INT32* out_count);/** 设置要采集的XRRMonitor id, 采集X屏幕时使用* xrr_monitor_id: -1:采集所有屏幕, SDK默认为-1.*/NT_UINT32 NT_API NT_PB_SetCaptureXRRMonitor(NT_HANDLE handle, NT_INT64 xrr_monitor_id);
上述接口可以实现只采集主显示器, 或选择要采集的显示器. 对于监控场景支持每个显示器分别采集录制,然后输出RTSP或RTMP流; 另外考虑到网络带宽和设备性能等限制, 支持屏幕采集后缩放, 然后再编码输出.如有其他问题请联系qq: 1130758427, 微信: ldxevt .