一、下载和安装NDI工具和SDK
下载和安装:
1.NDI 6 SDK (https://ndi.video/for-developers/ndi-sdk/)
2.NDI 6 Tools(选装) (https://ndi.video/)
3.NDI SDK for Unreal Engine v3.8 (https://ndi.video/for-developers/ndi-unreal-engine-sdk/)
二、Qt程序使用NDI发送视频流
1.新增SDK到工程目录下 \HDD\NDISDK
2.XXX.pro 文件加入:
1 2 3
| #NDI INCLUDEPATH += $$PWD/NDISDK/include LIBS += -L$$PWD/NDISDK/lib -lProcessing.NDI.Lib.x64
|
3.mainform.h文件:
1 2 3 4 5 6 7 8
| #include "Processing.NDI.Lib.h"
private: NDIlib_send_instance_t m_pNDI_send; QTimer* m_pTimer; void captureAndSendFrame();
|
4.mainform.cpp文件:
(1)构造函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
if (!NDIlib_initialize()) { return ; }
NDIlib_send_create_t NDI_send_create_desc; NDI_send_create_desc.p_ndi_name = "HDD1"; NDI_send_create_desc.p_groups = nullptr; NDI_send_create_desc.clock_video = false; NDI_send_create_desc.clock_audio = false;
m_pNDI_send = NDIlib_send_create(&NDI_send_create_desc); if (!m_pNDI_send) { return ; }
m_pTimer = new QTimer(this); connect(m_pTimer, &QTimer::timeout, this, &MainForm::captureAndSendFrame); m_pTimer->start(33);
|
(2)析构函数:
1 2 3 4 5 6 7 8 9 10 11
| m_pTimer->stop(); delete m_pTimer;
if (m_pNDI_send) { NDIlib_send_destroy(m_pNDI_send); }
NDIlib_destroy();
|
(3)captureAndSendFrame函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| void MainForm::captureAndSendFrame() { QPixmap pixmap = this->grab();
QImage image = pixmap.toImage().convertToFormat(QImage::Format_RGBA8888);
NDIlib_video_frame_v2_t video_frame; video_frame.xres = image.width(); video_frame.yres = image.height(); video_frame.FourCC = NDIlib_FourCC_type_RGBA; video_frame.frame_rate_N = 30000; video_frame.frame_rate_D = 1001; video_frame.picture_aspect_ratio = static_cast<float>(image.width()) / static_cast<float>(image.height()); video_frame.frame_format_type = NDIlib_frame_format_type_progressive; video_frame.timecode = NDIlib_send_timecode_synthesize; video_frame.p_data = const_cast<uint8_t*>(image.bits()); video_frame.line_stride_in_bytes = image.bytesPerLine();
NDIlib_send_send_video_v2(m_pNDI_send, &video_frame); }
|
以上执行后,可用NDI tools工具测试是否正常send视频流
三、使用UE5接收视频流并播放
1.添加NDI Receive Actor播放实体

2.添加NDI Media Receiver,用来接收视频流

3.设置创建的NDIMediaReceiver,将Connection选择为Qt程序中的SourceName、MachineName、StreamName

4.设置NDI Receive Actor的视频源为创建的NDIMediaReceiver

以上,可在UE5中正常播放Qt程序截图