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

网站制作课程介绍seo推广 课程

网站制作课程介绍,seo推广 课程,wordpress不升级,wordpress 技术背景 随着国产化操作系统的推进&#xff0c;市场对国产化操作系统下的生态构建&#xff0c;需求越来越迫切&#xff0c;特别是音视频这块&#xff0c;今天我们讨论的是如何在linux平台实现屏幕|摄像头采集&#xff0c;并推送至RTMP服务。 我们知道&#xff0c;Linux平台&…<article class="baidu_pl"><div id="article_content" class="article_content clearfix"><div id="content_views" class="htmledit_views"><h3>技术背景</h3> <p>随着国产化操作系统的推进,市场对国产化操作系统下的生态构建,需求越来越迫切,特别是音视频这块,今天我们讨论的是如何在linux平台实现屏幕|摄像头采集,并推送至RTMP服务。</p> <p>我们知道,Linux平台,如果需要采集摄像头,可使用V4L2相关接口,屏幕采集用X相关接口实现,如果是Wayland协议, 用PipeWire相关接口实现采集就好。 麦克风采集使用ALSA或者PulseAudio,采集播放音频用PulseAudio。</p> <h3>FFmpeg VS SmartPublisher</h3> <p>今天我们探讨的是,两种技术选型下的linux平台同屏摄像头RTMP推送实现:</p> <h4>FFmpeg技术方案</h4> <p id="">在Linux平台上采集屏幕和摄像头内容,并将其推送到RTMP服务器,可结合使用ffmpeg和x11grab(用于屏幕捕获)以及摄像头设备。</p> <p style="text-align:center;"><img referrerpolicy="no-referrer" alt="" src="https://i-blog.csdnimg.cn/direct/62565dc3a8df4e2cacd402c7c4c913d7.webp" /></p> <h4>1 安装 FFmpeg</h4> <p id="">首先,确保你的Linux系统上安装了<code>ffmpeg</code>。你可以通过包管理器安装它。例如,在Ubuntu上,你可以使用以下命令:</p> <pre><code class="language-bash">sudo apt update sudo apt install ffmpeg</code></pre> <pre><strong style="color:#4f4f4f;font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;font-size:18px;font-weight:bold;">2 确定摄像头设备</strong> </pre> <p id="">在Linux上,摄像头通常被识别为/dev/videoX设备,其中X是设备的编号(通常是0, 1, 2等)。你可以使用ls /dev/video*来查看所有视频设备。</p> <h4>3 编写FFmpeg命令</h4> <p id="">使用<code>ffmpeg</code>,你可以同时捕获屏幕和摄像头,并将它们合并到一个RTMP流中。以下是一个基本的命令示例,它假设你的摄像头是<code>/dev/video0</code>,并且你想要捕获整个屏幕:</p> <pre><code class="language-bash">ffmpeg \ -f x11grab -r 30 -s 1920x1080 -i :0.0+100,200 \ -f video4linux2 -r 30 -s 640x480 -i /dev/video0 \ -filter_complex "[0:v]pad=iw+640:ih:640:0[main];[main][1:v]overlay=640:0[out]" \ -map "[out]" -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p \ -f flv rtmp://192.168.0.103:1935/live/streamkey</code></pre> <pre><span style="color:#4d4d4d;"><span style="font-size:16px;">命令解析:</span></span></pre> <ul><li><code>-f x11grab</code>:指定输入格式为X11屏幕捕获。</li><li><code>-r 30</code>:设置帧率为30fps。</li><li><code>-s 1920x1080</code>:设置屏幕捕获的分辨率为1920x1080。</li><li><code>-i :0.0+100,200</code>:指定屏幕捕获的起始位置(可选,这里从屏幕左上角向右100像素,向下200像素开始)。</li><li><code>-f video4linux2</code>:指定摄像头输入格式。</li><li><code>-filter_complex</code>:使用<code>ffmpeg</code>的过滤器图(filtergraph)来合并视频流。这里,它首先将屏幕捕获的视频向右填充640像素(摄像头宽度),然后将摄像头视频覆盖在填充后的屏幕视频的右侧。</li><li><code>-map "[out]"</code>:选择过滤器图的输出作为最终输出。</li><li><code>-c:v libx264</code>:设置视频编码器为libx264。</li><li><code>-preset veryfast</code>:设置编码预设以平衡编码速度和压缩率。</li><li><code>-maxrate</code> 和 <code>-bufsize</code>:设置比特率和缓冲区大小。</li><li><code>-pix_fmt yuv420p</code>:设置像素格式为YUV420P,这是大多数RTMP服务器所需的格式。</li><li><code>-f flv</code>:设置输出格式为FLV,适用于RTMP流。</li><li><code>rtmp://192.168.0.103:1935/live/streamkey</code>:替换为你的RTMP服务器的URL和流密钥。</li></ul> <h4 style="background-color:transparent;">SmartPublisher</h4> <p>SmartPublisher是大牛直播SDK旗下SmartMediaKit系列的跨平台的RTMP推送模块,Linux平台已支持x86_64架构和aarch64架构,SDK始于2015年,先后覆盖了Windows、Android、iOS、Linux平台的RTMP|RTSP的音视频推拉流模块。</p> <p style="text-align:center;"><img referrerpolicy="no-referrer" alt="" src="https://i-blog.csdnimg.cn/direct/2435a419d7ac45889b35003947e695c9.png" /></p> <p>Linux平台x64_64架构|aarch64架构RTMP直播推送模块功能支持如下:</p> <ul><li>音频编码:AAC/SPEEX;</li><li>视频编码:H.264;</li><li>推流协议:RTMP;</li><li>[音视频]支持纯音频/纯视频/音视频推送;</li><li>支持X11屏幕采集;</li><li>支持部分V4L2摄像头设备采集;</li><li>[屏幕/V4L2摄像头]支持帧率、关键帧间隔(GOP)、码率(bit-rate)设置;</li><li>[V4L2摄像头]支持V4L2摄像头设备选择(设备文件名范围:[/dev/video0, /dev/video63])、分辨率设置、帧率设置;</li><li>[V4L2摄像头]支持水平反转、垂直反转、0° 90° 180° 270°旋转;</li><li>[音频]支持基于alsa-lib接口的音频采集;</li><li>[音频]支持基于libpulse接口采集本机PulseAudio服务音频;</li><li>[预览]支持推送端实时预览;</li><li>[对接服务器]支持自建标准RTMP服务器或CDN;</li><li>支持断网自动重连、网络状态回调;</li><li>屏幕和摄像头合成/多层合成;</li><li>支持窗口采集(一般不建议使用);</li><li>支持实时快照;</li><li>支持降噪处理、自动增益控制、VAD端点检测;</li><li>支持扬声器和麦克风混音;</li><li>支持外部编码前音视频数据对接;</li><li>支持外部编码后音视频数据对接;</li><li>支持实时音量调节;</li><li>支持扩展录像模块;</li><li>支持Unity接口;</li><li>支持H.264扩展SEI发送模块;</li><li>支持x64_64架构、aarch64架构(需要glibc-2.21及以上版本的Linux系统, 需要libX11.so.6, 需要GLib–2.0, 需安装 libstdc++.so.6.0.21、GLIBCXX_3.4.21、 CXXABI_1.3.9);</li></ul> <p>技术实现如下:</p> <pre><code class="language-cpp">/** publisherdemo.cpp* Author: daniusdk.com* WeChat: xinsheng120*/ int main(int argc, char *argv[]) {struct sigaction act;sigemptyset(&act.sa_mask);act.sa_sigaction = OnSaSigaction;act.sa_flags = SA_SIGINFO;sigaction(SIGINT, &act, NULL);sigaction(SIGFPE, &act, NULL);XInitThreads(); // X支持多线程, 必须调用auto display = XOpenDisplay(nullptr);if (!display){fprintf(stderr, "Cannot connect to X server\n");return 0;}auto screen = DefaultScreen(display);auto root = XRootWindow(display, screen);XWindowAttributes root_win_att;if (!XGetWindowAttributes(display, root, &root_win_att)){fprintf(stderr, "Get Root window attri failed\n");XCloseDisplay(display);return 0;}int main_w = root_win_att.width / 2, main_h = root_win_att.height / 2;auto black_pixel = BlackPixel(display, screen);auto white_pixel = WhitePixel(display, screen);auto main_wid = XCreateSimpleWindow(display, root, 0, 0, main_w, main_h, 0, white_pixel, black_pixel);if (!main_wid){fprintf(stderr, "Cannot Create Main Window\n");XCloseDisplay(display);return 0;}XSelectInput(display, main_wid, StructureNotifyMask | KeyPressMask);auto sub_wid = CreateSubWindow(display, screen, main_wid);if (!sub_wid){fprintf(stderr, "Cannot Create Render Window\n");XDestroyWindow(display, main_wid);XCloseDisplay(display);return 0;}XMapWindow(display, main_wid);XStoreName(display, main_wid, "Video Preview");XMapWindow(display, sub_wid);LogInit();NT_SmartPublisherSDKAPI push_api;if (!PushSDKInit(push_api)){XDestroyWindow(display, sub_wid);XDestroyWindow(display, main_wid);XCloseDisplay(display);return 0;}// auto rtsp_server_handle = start_rtsp_server(&push_api, 8554, "test", "12345");auto rtsp_server_handle = start_rtsp_server(&push_api, 8554, "", "");if (nullptr == rtsp_server_handle) {fprintf(stderr, "start_rtsp_server failed.\n");XDestroyWindow(display, sub_wid);XDestroyWindow(display, main_wid);XCloseDisplay(display);push_api.UnInit();return 0;}auto push_handle = open_config_instance(&push_api, 20);if (nullptr == push_handle) {fprintf(stderr, "open_config_instance failed.\n");XDestroyWindow(display, sub_wid);XDestroyWindow(display, main_wid);XCloseDisplay(display);stop_rtsp_server(&push_api, rtsp_server_handle);push_api.UnInit();return 0;}if (!start_rtsp_stream(&push_api, rtsp_server_handle, push_handle, "stream1")) {fprintf(stderr, "start_rtsp_stream failed.\n");goto _cleanup_;}if (!start_rtmp(&push_api, push_handle, "rtmp://192.168.0.107:1935/live/test1")) {fprintf(stderr, "start_rtmp failed.\n");goto _cleanup_;}// 开启预览,也可以不开启, 根据需求来push_api.SetPreviewXWindow(push_handle, "", sub_wid);push_api.StartPreview(push_handle, 0, nullptr);while (!g_is_exit){while (MY_X11_Pending(display, 10)){XEvent xev;memset(&xev, 0, sizeof(xev));XNextEvent(display, &xev);if (xev.type == ConfigureNotify){if (xev.xconfigure.window == main_wid){if (xev.xconfigure.width != main_w || xev.xconfigure.height != main_h){main_w = xev.xconfigure.width;main_h = xev.xconfigure.height;XMoveResizeWindow(display, sub_wid, 0, 0, main_w - 4, main_h - 4);}}}else if (xev.type == KeyPress){if (xev.xkey.keycode == XKeysymToKeycode(display, XK_Escape)){fprintf(stdout, "ESC Key Press\n");g_is_exit = true;}}if (g_is_exit)break;}}}</code></pre> <p>其中,PushSDKInit()实现如下:</p> <pre><code class="language-cpp"> /** publisherdemo.cpp* Author: daniusdk.com*/bool PushSDKInit(NT_SmartPublisherSDKAPI& push_api){memset(&push_api, 0, sizeof(push_api));NT_GetSmartPublisherSDKAPI(&push_api);auto ret = push_api.Init(0, nullptr);if (NT_ERC_OK != ret){fprintf(stderr, "push_api.Init failed!\n");return false;}else{fprintf(stdout, "push_api.Init ok!\n");}return true;}</code></pre> <p>open_config_instance()实现如下,可以获取摄像头或屏幕数据,并做基础的编码等参数配置,看似复杂,实际和Windows平台相差不大:</p> <pre><code class="language-cpp"> NT_HANDLE open_config_instance(NT_SmartPublisherSDKAPI* push_api, int dst_fps) {NT_INT32 pulse_device_number = 0;if (NT_ERC_OK == push_api->GetAuidoInputDeviceNumber(2, &pulse_device_number)){fprintf(stdout, "[daniusdk.com]Pulse device num:%d\n", pulse_device_number);char device_name[512];for (auto i = 0; i < pulse_device_number; ++i){if (NT_ERC_OK == push_api->GetAuidoInputDeviceName(2, i, device_name, 512)){fprintf(stdout, "[daniusdk.com]index:%d name:%s\n", i, device_name);}}}NT_INT32 alsa_device_number = 0;if (pulse_device_number < 1){if (NT_ERC_OK == push_api->GetAuidoInputDeviceNumber(1, &alsa_device_number)){fprintf(stdout, "Alsa device num:%d\n", alsa_device_number);char device_name[512];for (auto i = 0; i < alsa_device_number; ++i){if (NT_ERC_OK == push_api->GetAuidoInputDeviceName(1, i, device_name, 512)){fprintf(stdout, "[daniusdk.com]index:%d name:%s\n", i, device_name);}}}}NT_INT32 capture_speaker_flag = 0;if (NT_ERC_OK == push_api->IsCanCaptureSpeaker(2, &capture_speaker_flag)){if (capture_speaker_flag)fprintf(stdout, "[daniusdk.com]Support speaker capture\n");elsefprintf(stdout, "[daniusdk.com]UnSupport speaker capture\n");}NT_INT32 is_support_window_capture = 0;if (NT_ERC_OK == push_api->IsCaptureXWindowSupported(NULL, &is_support_window_capture)){if (is_support_window_capture)fprintf(stdout, "[daniusdk.com]Support window capture\n");elsefprintf(stdout, "[daniusdk.com]UnSupport window capture\n");}if (is_support_window_capture){NT_INT32 win_count = 0;if (NT_ERC_OK == push_api->UpdateCaptureXWindowList(NULL, &win_count) && win_count > 0){fprintf(stdout, "X Capture Winows list++\n");for (auto i = 0; i < win_count; ++i){NT_UINT64 wid;char title[512];if (NT_ERC_OK == push_api->GetCaptureXWindowInfo(i, &wid, title, sizeof(title) / sizeof(char))){x_win_list.push_back(wid);fprintf(stdout, "wid:%llu, title:%s\n", wid, title);}}fprintf(stdout, "[daniusdk.com]X Capture Winows list--\n");}}std::vector<CameraInfo> cameras;GetCameraInfo(push_api, cameras);if (!cameras.empty()){fprintf(stdout, "cameras count:%d\n", (int)cameras.size());for (const auto& c : cameras){fprintf(stdout, "camera name:%s, id:%s, cap_num:%d\n", c.name_.c_str(), c.id_.c_str(), (int)c.capabilities_.size());for (const auto& i : c.capabilities_){fprintf(stdout, "[daniusdk.com]cap w:%d, h:%d, fps:%d\n", i.width_, i.height_, i.max_frame_rate_);}}}NT_UINT32 auido_option = NT_PB_E_AUDIO_OPTION_NO_AUDIO;if (pulse_device_number > 0 || alsa_device_number > 0){auido_option = NT_PB_E_AUDIO_OPTION_CAPTURE_MIC;}else if (capture_speaker_flag){auido_option = NT_PB_E_AUDIO_OPTION_CAPTURE_SPEAKER;}//auido_option = NT_PB_E_AUDIO_OPTION_CAPTURE_MIC_SPEAKER_MIXER;NT_UINT32 video_option = NT_PB_E_VIDEO_OPTION_SCREEN;if (!cameras.empty()){video_option = NT_PB_E_VIDEO_OPTION_CAMERA;}else if (is_support_window_capture){video_option = NT_PB_E_VIDEO_OPTION_WINDOW;}// video_option = NT_PB_E_VIDEO_OPTION_LAYER;//video_option = NT_PB_E_VIDEO_OPTION_NO_VIDEO;NT_HANDLE push_handle = nullptr;//if (NT_ERC_OK != push_api->Open(&push_handle, NT_PB_E_VIDEO_OPTION_LAYER, NT_PB_E_AUDIO_OPTION_CAPTURE_SPEAKER, 0, NULL))if (NT_ERC_OK != push_api->Open(&push_handle, video_option, auido_option, 0, NULL)){return nullptr;}push_api->SetEventCallBack(push_handle, nullptr, OnSDKEventHandle);//push_api->SetXDisplayName(push_handle, ":0");//push_api->SetXDisplayName(push_handle, NULL);// 视频层配置方式if (NT_PB_E_VIDEO_OPTION_LAYER == video_option){std::vector<std::shared_ptr<nt_pb_sdk::layer_conf_wrapper_base> > layer_confs;auto index = 0;第0层填充RGBA矩形, 目的是保证帧率, 颜色就填充全黑auto rgba_layer_c0 = std::make_shared<nt_pb_sdk::RGBARectangleLayerConfigWrapper>(index++, true, 0, 0, 1280, 720);rgba_layer_c0->conf_.red_ = 200;rgba_layer_c0->conf_.green_ = 200;rgba_layer_c0->conf_.blue_ = 200;rgba_layer_c0->conf_.alpha_ = 255;layer_confs.push_back(rgba_layer_c0);// 第一层为桌面层//auto screen_layer_c1 = std::make_shared<nt_pb_sdk::ScreenLayerConfigWrapper>(index++, true, 0, 0, 1280, 720);//screen_layer_c1->conf_.scale_filter_mode_ = 3;//layer_confs.push_back(screen_layer_c1);第一层为窗口if (!x_win_list.empty()){auto window_layer_c1 = std::make_shared<nt_pb_sdk::WindowLayerConfigWrapper>(index++, true, 0, 0, 640, 360);window_layer_c1->conf_.xwindow_ = x_win_list.back();layer_confs.push_back(window_layer_c1);}摄像头层if (!cameras.empty()){auto camera_layer_c1 = std::make_shared<nt_pb_sdk::CameraLayerConfigWrapper>(index++, true,640, 0, 640, 360);strcpy(camera_layer_c1->conf_.device_unique_id_, cameras.front().id_.c_str());camera_layer_c1->conf_.is_flip_horizontal_ = 0;camera_layer_c1->conf_.is_flip_vertical_ = 0;camera_layer_c1->conf_.rotate_degress_ = 0;layer_confs.push_back(camera_layer_c1);if (cameras.size() > 1){auto camera_layer_c2 = std::make_shared<nt_pb_sdk::CameraLayerConfigWrapper>(index++, true,640, 0, 320, 240);strcpy(camera_layer_c2->conf_.device_unique_id_, cameras.back().id_.c_str());camera_layer_c2->conf_.is_flip_horizontal_ = 0;camera_layer_c2->conf_.is_flip_vertical_ = 0;camera_layer_c2->conf_.rotate_degress_ = 0;layer_confs.push_back(camera_layer_c2);}}auto image_layer1 = std::make_shared<nt_pb_sdk::ImageLayerConfigWrapper>(index++, true, 650, 120, 324, 300);strcpy(image_layer1->conf_.file_name_utf8_, "./testpng/tca.png");layer_confs.push_back(image_layer1);auto image_layer2 = std::make_shared<nt_pb_sdk::ImageLayerConfigWrapper>(index++, true, 120, 380, 182, 138);strcpy(image_layer2->conf_.file_name_utf8_, "./testpng/t4.png");layer_confs.push_back(image_layer2);std::vector<const NT_PB_LayerBaseConfig* > layer_base_confs;for (const auto& i : layer_confs){layer_base_confs.push_back(i->getBase());}if (NT_ERC_OK != push_api->SetLayersConfig(push_handle, 0, layer_base_confs.data(),layer_base_confs.size(), 0, nullptr)){push_api->Close(push_handle);push_handle = nullptr;return nullptr;}}// push_api->SetScreenClip(push_handle, 0, 0, 1280, 720);if (video_option == NT_PB_E_VIDEO_OPTION_CAMERA){if (!cameras.empty()){push_api->SetVideoCaptureDeviceBaseParameter(push_handle, cameras.front().id_.c_str(),640, 480);//push_api->FlipVerticalCamera(push_handle, 1);//push_api->FlipHorizontalCamera(push_handle, 1);//push_api->RotateCamera(push_handle, 0);}}if (video_option == NT_PB_E_VIDEO_OPTION_WINDOW){if (!x_win_list.empty()){//push_api->SetCaptureXWindow(push_handle, x_win_list[0]);push_api->SetCaptureXWindow(push_handle, x_win_list.back());}}push_api->SetFrameRate(push_handle, dst_fps); // 帧率设置push_api->SetVideoEncoder(push_handle, 0, 1, NT_MEDIA_CODEC_ID_H264, 0);push_api->SetVideoBitRate(push_handle, 2000); // 平均码率2000kbpspush_api->SetVideoQuality(push_handle, 26);push_api->SetVideoMaxBitRate(push_handle, 4000); // 最大码率4000kbps// openh264 配置特定参数push_api->SetVideoEncoderSpecialInt32Option(push_handle, "usage_type", 0); //0是摄像头编码, 1是屏幕编码push_api->SetVideoEncoderSpecialInt32Option(push_handle, "rc_mode", 1); // 0是质量模式, 1是码率模式push_api->SetVideoEncoderSpecialInt32Option(push_handle, "enable_frame_skip", 0); // 0是关闭跳帧, 1是打开跳帧push_api->SetVideoKeyFrameInterval(push_handle, dst_fps * 2); // 关键帧间隔push_api->SetVideoEncoderProfile(push_handle, 3); // H264 highpush_api->SetVideoEncoderSpeed(push_handle, 3); // 编码速度设置到3if (pulse_device_number > 0){push_api->SetAudioInputLayer(push_handle, 2);push_api->SetAuidoInputDeviceId(push_handle, 0);}else if (alsa_device_number > 0){push_api->SetAudioInputLayer(push_handle, 1);push_api->SetAuidoInputDeviceId(push_handle, 0);}push_api->SetEchoCancellation(push_handle, 1, 0);push_api->SetNoiseSuppression(push_handle, 1);push_api->SetAGC(push_handle, 1);push_api->SetVAD(push_handle, 1);push_api->SetInputAudioVolume(push_handle, 0, 1.0);push_api->SetInputAudioVolume(push_handle, 1, 0.2);// 音频配置push_api->SetPublisherAudioCodecType(push_handle, 1);//push_api->SetMute(push_handle, 1);return push_handle;}</code></pre> <p>其中,push_api->Open(&push_handle, video_option, auido_option, 0, NULL))时,设置音视频采集类型,相关类型如下:</p> <pre><code class="language-cpp">/** nt_smart_publisher_define.h* Author: daniusdk.com*/ /*定义Video源选项*/ typedef enum _NT_PB_E_VIDEO_OPTION {NT_PB_E_VIDEO_OPTION_NO_VIDEO = 0x0,NT_PB_E_VIDEO_OPTION_SCREEN = 0x1, // 采集屏幕NT_PB_E_VIDEO_OPTION_CAMERA = 0x2, // 摄像头采集NT_PB_E_VIDEO_OPTION_LAYER = 0x3, // 视频合并,比如桌面叠加摄像头等NT_PB_E_VIDEO_OPTION_ENCODED_DATA = 0x4, // 已经编码的视频数据,目前支持H264NT_PB_E_VIDEO_OPTION_WINDOW = 0x5, // 采集窗口 } NT_PB_E_VIDEO_OPTION;/*定义Auido源选项*/ typedef enum _NT_PB_E_AUDIO_OPTION {NT_PB_E_AUDIO_OPTION_NO_AUDIO = 0x0,NT_PB_E_AUDIO_OPTION_CAPTURE_MIC = 0x1, // 采集麦克风音频NT_PB_E_AUDIO_OPTION_CAPTURE_SPEAKER = 0x2, // 采集扬声器NT_PB_E_AUDIO_OPTION_CAPTURE_MIC_SPEAKER_MIXER = 0x3, // 麦克风扬声器混音NT_PB_E_AUDIO_OPTION_ENCODED_DATA = 0x4, // 编码后的音频数据,目前支持AAC, speex宽带(wideband mode)NT_PB_E_AUDIO_OPTION_EXTERNAL_PCM_DATA = 0x5, /*外部PCM数据*/NT_PB_E_AUDIO_OPTION_MIC_EXTERNAL_PCM_MIXER = 0x6, /* 麦克风和外部PCM数据混音 当前只支持一路外部音频和内置麦克风混音*/NT_PB_E_AUDIO_OPTION_TWO_EXTERNAL_PCM_MIXER = 0x7, /* 两路外部PCM数据混音*/ } NT_PB_E_AUDIO_OPTION;</code></pre> <p>推送RTMP流:</p> <pre><code class="language-cpp">bool start_rtmp(NT_SmartPublisherSDKAPI* push_api, NT_HANDLE handle, const std::string& rtmp_url) {if (NT_ERC_OK != push_api->SetURL(handle, rtmp_url.c_str(), NULL))return false;if (NT_ERC_OK != push_api->StartPublisher(handle, NULL))return false;return true; }</code></pre> <p>如果需要本地摄像头或者屏幕预览数据,调研预览接口即可:</p> <pre><code class="language-cpp"> // 开启预览,也可以不开启, 根据需求来push_api.SetPreviewXWindow(push_handle, "", sub_wid);push_api.StartPreview(push_handle, 0, nullptr);</code></pre> <p>如需停止:</p> <pre><code class="language-cpp"> fprintf(stdout, "Skip run loop, is_exit:%d\n", g_is_exit);fprintf(stdout, "StopRtspStream++\n");push_api.StopRtspStream(push_handle);fprintf(stdout, "StopRtspStream--\n");fprintf(stdout, "stop_rtsp_server++\n");stop_rtsp_server(&push_api, rtsp_server_handle);fprintf(stdout, "stop_rtsp_server--\n");push_api.StopPreview(push_handle);push_api.StopPublisher(push_handle);push_api.Close(push_handle);push_handle = nullptr;XDestroyWindow(display, sub_wid);XDestroyWindow(display, main_wid);XCloseDisplay(display);push_api.UnInit();fprintf(stdout, "SDK UnInit..\n");return 0;</code></pre> <h3 style="background-color:transparent;">总结</h3> <p>FFmpeg是一个开源的多媒体处理工具,支持几乎所有的音视频格式和编码标准,包括常见的H.264、AAC等,这使其在处理不同来源的音视频数据时具有极高的灵活性。并提供了丰富的编解码器选项,用户可根据需求选择合适的编解码器进行音视频数据的压缩和解压,从而优化传输效率和播放质量。大牛直播SDK针对Linux平台x86_64架构和aarch64架构的RTMP推送模块,系SDK,功能更完备,更适合产品化集成,配合自研的SmartPlayer RTMP播放器,延迟可达150-400ms,扩展性更强,以上是二者比较,抛砖引玉,感兴趣的开发者,可以单独跟我沟通。</p> <p></p> <h4></h4></div></div><div id="treeSkill"></div><div id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"></div> <div id="vip"><a class="submit" onclick="showArticle()">查看全文</a></div> <div class="entry-copyright"> <!--<span class="source_url"></span><br>--> <span class="Disclaimers"><a href="http://www.shuangfujiaoyu.com/news/24710.html">http://www.shuangfujiaoyu.com/news/24710.html</a></span> <span class="email"></span> </div> <div class="gkt-entry-xgwz clear" style="margin-bottom:8px;"> <h3>相关文章:</h3> <li> <a href="/news/24708.html">个人网站建设一般流程深圳网络推广系统</a> </li> <li> <a href="/news/24707.html">wordpress数据库加速seo标题优化步骤</a> </li> <li> <a href="/news/24706.html">如何做招聘网站的评估百度资源搜索资源平台</a> </li> <li> <a href="/news/24705.html">最新网站开发价格灰色seo推广</a> </li> <li> <a href="/news/24704.html">广州网站建设首选快优湖人排名最新</a> </li> <li> <a href="/news/24702.html">呼伦贝尔市建设网站小广告怎么能弄干净</a> </li> <li> <a href="/news/24701.html">建筑网站建设企业网络宣传推广方案</a> </li> <li> <a href="/news/24700.html">原来做网站后来跑国外了2023年6月疫情恢复</a> </li> <li> <a href="/news/24699.html">公司开发个网站怎么做企业网上的推广</a> </li> <li> <a href="/news/24698.html">哪些做网站的公司比较好小说百度搜索风云榜</a> </li> <li> <a href="/news/24697.html">网站排版设计欣赏最近发生的热点新闻</a> </li> <li> <a href="/news/24696.html">网站突然没有收录seo综合查询工具</a> </li> <li> <a href="/news/24695.html">一个网站的优势有哪些开发一个网站的步骤流程</a> </li> <li> <a href="/news/24694.html">做ppt网站有哪些投资网站建设方案</a> </li> <li> <a href="/news/24693.html">做三个月网站 广告收入电子商务seo</a> </li> <li> <a href="/news/24692.html">生活中的科技产品有哪些长沙专业竞价优化公司</a> </li> <li> <a href="/news/24691.html">爱站网关键词长尾挖掘工具seo培训课程</a> </li> <li> <a href="/news/24690.html">怎么用代码做网站自动外链网址</a> </li> <li> <a href="/news/24689.html">做网站 接单2021年网络营销考试题及答案</a> </li> <li> <a href="/news/24688.html">承德网站建设百度推广电话销售话术</a> </li> <li> <a href="/news/24687.html">石家庄网站怎么建设信息流投放</a> </li> <li> <a href="/news/24686.html">四川住房和城乡建设厅网站不能进入自动搜索关键词软件</a> </li> <li> <a href="/news/24685.html">模板做图 网站有哪些温州高端网站建设</a> </li> <li> <a href="/news/24684.html">南通市建设局网站马建明郴州网站建设网络推广平台</a> </li> <li> <a href="/news/24683.html">怎么给网站做二维码百度快速收录3元一条</a> </li> <li> <a href="/news/24682.html">优惠券网站做代理怎么样网站推广的要点</a> </li> <li> <a href="/news/24681.html">xml网站地图生成搜索引擎优化主要包括</a> </li> <li> <a href="/news/24680.html">中山做网站联系电话站长工具大全</a> </li> <li> <a href="/news/24678.html">做网站的具体内容网络营销平台名词解释</a> </li> <li> <a href="/news/24676.html">胶州企业网站建设常熟seo关键词优化公司</a> </li> </div> </article> </main> </div> </div> <aside id="secondary" class="widget-area sidebar"> <div class="widget widget_posts_thumbnail" style="margin-top:6px;"> <h2 class="widget-title">最新文章</h2> <ul> <li class="clear"> <a href="/news/24984.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/做企业规划的网站网站访问量" alt=" 做企业规划的网站网站访问量" /> </div> </a> <div class="entry-wrap"> <a href="/news/24984.html" rel="bookmark"> 做企业规划的网站网站访问量</a> <div class="entry-meta">2025/7/19 0:37:51</div></div> </li> <li class="clear"> <a href="/news/24983.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/临清住房建设网站网络推广员招聘" alt=" 临清住房建设网站网络推广员招聘" /> </div> </a> <div class="entry-wrap"> <a href="/news/24983.html" rel="bookmark"> 临清住房建设网站网络推广员招聘</a> <div class="entry-meta">2025/7/19 0:37:20</div></div> </li> <li class="clear"> <a href="/news/24982.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/做六个网站静态页多少钱网站快速优化排名软件" alt=" 做六个网站静态页多少钱网站快速优化排名软件" /> </div> </a> <div class="entry-wrap"> <a href="/news/24982.html" rel="bookmark"> 做六个网站静态页多少钱网站快速优化排名软件</a> <div class="entry-meta">2025/7/19 0:36:50</div></div> </li> <li class="clear"> <a href="/news/24981.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/如何做色情网站沈阳网站建设" alt=" 如何做色情网站沈阳网站建设" /> </div> </a> <div class="entry-wrap"> <a href="/news/24981.html" rel="bookmark"> 如何做色情网站沈阳网站建设</a> <div class="entry-meta">2025/7/19 0:36:20</div></div> </li> <li class="clear"> <a href="/news/24980.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/做网站 工商 非法经营百度关键词搜索指数查询" alt=" 做网站 工商 非法经营百度关键词搜索指数查询" /> </div> </a> <div class="entry-wrap"> <a href="/news/24980.html" rel="bookmark"> 做网站 工商 非法经营百度关键词搜索指数查询</a> <div class="entry-meta">2025/7/19 0:35:50</div></div> </li> <li class="clear"> <a href="/news/24979.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="http://pic.xiahunao.cn/yaotu/珠海网站开发淮北seo" alt=" 珠海网站开发淮北seo" /> </div> </a> <div class="entry-wrap"> <a href="/news/24979.html" rel="bookmark"> 珠海网站开发淮北seo</a> <div class="entry-meta">2025/7/19 0:35:19</div></div> </li> </ul> </div> <div class="leftdiv2"> </div> </aside> </div> <footer id="colophon" class="site-footer"> <div class="clear"></div> <div id="site-bottom" class="clear"> <div class="container"> <div class="menu-m_footer-container"> <ul id="footer-menu" class="footer-nav"> <li> <strong> <a href="/">双福教育介绍</a></strong> </li> <li> <strong> <a href="/">商务合作</a></strong> </li> <li> <strong> <a href="/">免责声明</a></strong> </li> </ul> </div> <div class="site-info"> <p>CopyRight © <a href="/">双福教育</a>版权所有 </p> </div> </div> </div> </footer> </div> <div id="back-top"> <a href="#top" title="返回顶部"> <svg width="38" height="38" viewbox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect width="48" height="48" fill="white" fill-opacity="0.01" /> <path d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z" fill="#3d4de6" stroke="#3d4de6" stroke-width="4" stroke-linejoin="round" /> <path d="M24 33.5V15.5" stroke="#FFF" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" /> <path d="M33 24.5L24 15.5L15 24.5" stroke="#FFF" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" /></svg> </a> </div> <script src='/templates/nzzt/js/common.js'></script> <script> $(function(){ $('.source_url').text('原文地址:https://blog.csdn.net/renhui1112/article/details/141962923'); }); /*$('.source_url').on("click",function() { window.open('https://blog.csdn.net/renhui1112/article/details/141962923', '_blank'); });*/ </script> </body> </html>