Linux平台屏幕|摄像头采集并实现RTMP推送两种技术方案探究

news2024/9/24 3:29:57

技术背景

随着国产化操作系统的推进,市场对国产化操作系统下的生态构建,需求越来越迫切,特别是音视频这块,今天我们讨论的是如何在linux平台实现屏幕|摄像头采集,并推送至RTMP服务。

我们知道,Linux平台,如果需要采集摄像头,可使用V4L2相关接口,屏幕采集用X相关接口实现,如果是Wayland协议, 用PipeWire相关接口实现采集就好。 麦克风采集使用ALSA或者PulseAudio,采集播放音频用PulseAudio。

FFmpeg VS SmartPublisher

今天我们探讨的是,两种技术选型下的linux平台同屏摄像头RTMP推送实现:

FFmpeg技术方案

在Linux平台上采集屏幕和摄像头内容,并将其推送到RTMP服务器,可结合使用ffmpeg和x11grab(用于屏幕捕获)以及摄像头设备。

1 安装 FFmpeg

首先,确保你的Linux系统上安装了ffmpeg。你可以通过包管理器安装它。例如,在Ubuntu上,你可以使用以下命令:

sudo apt update  
sudo apt install ffmpeg
2 确定摄像头设备

在Linux上,摄像头通常被识别为/dev/videoX设备,其中X是设备的编号(通常是0, 1, 2等)。你可以使用ls /dev/video*来查看所有视频设备。

3 编写FFmpeg命令

使用ffmpeg,你可以同时捕获屏幕和摄像头,并将它们合并到一个RTMP流中。以下是一个基本的命令示例,它假设你的摄像头是/dev/video0,并且你想要捕获整个屏幕:

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
命令解析:
  • -f x11grab:指定输入格式为X11屏幕捕获。
  • -r 30:设置帧率为30fps。
  • -s 1920x1080:设置屏幕捕获的分辨率为1920x1080。
  • -i :0.0+100,200:指定屏幕捕获的起始位置(可选,这里从屏幕左上角向右100像素,向下200像素开始)。
  • -f video4linux2:指定摄像头输入格式。
  • -filter_complex:使用ffmpeg的过滤器图(filtergraph)来合并视频流。这里,它首先将屏幕捕获的视频向右填充640像素(摄像头宽度),然后将摄像头视频覆盖在填充后的屏幕视频的右侧。
  • -map "[out]":选择过滤器图的输出作为最终输出。
  • -c:v libx264:设置视频编码器为libx264。
  • -preset veryfast:设置编码预设以平衡编码速度和压缩率。
  • -maxrate 和 -bufsize:设置比特率和缓冲区大小。
  • -pix_fmt yuv420p:设置像素格式为YUV420P,这是大多数RTMP服务器所需的格式。
  • -f flv:设置输出格式为FLV,适用于RTMP流。
  • rtmp://192.168.0.103:1935/live/streamkey:替换为你的RTMP服务器的URL和流密钥。

SmartPublisher

SmartPublisher是大牛直播SDK旗下SmartMediaKit系列的跨平台的RTMP推送模块,Linux平台已支持x86_64架构和aarch64架构,SDK始于2015年,先后覆盖了Windows、Android、iOS、Linux平台的RTMP|RTSP的音视频推拉流模块。

Linux平台x64_64架构|aarch64架构RTMP直播推送模块功能支持如下:

  • 音频编码:AAC/SPEEX;
  • 视频编码:H.264;
  • 推流协议:RTMP;
  • [音视频]支持纯音频/纯视频/音视频推送;
  • 支持X11屏幕采集;
  • 支持部分V4L2摄像头设备采集;
  • [屏幕/V4L2摄像头]支持帧率、关键帧间隔(GOP)、码率(bit-rate)设置;
  • [V4L2摄像头]支持V4L2摄像头设备选择(设备文件名范围:[/dev/video0, /dev/video63])、分辨率设置、帧率设置;
  • [V4L2摄像头]支持水平反转、垂直反转、0° 90° 180° 270°旋转;
  • [音频]支持基于alsa-lib接口的音频采集;
  • [音频]支持基于libpulse接口采集本机PulseAudio服务音频;
  • [预览]支持推送端实时预览;
  • [对接服务器]支持自建标准RTMP服务器或CDN;
  • 支持断网自动重连、网络状态回调;
  • 屏幕和摄像头合成/多层合成;
  • 支持窗口采集(一般不建议使用);
  • 支持实时快照;
  • 支持降噪处理、自动增益控制、VAD端点检测;
  • 支持扬声器和麦克风混音;
  • 支持外部编码前音视频数据对接;
  • 支持外部编码后音视频数据对接;
  • 支持实时音量调节;
  • 支持扩展录像模块;
  • 支持Unity接口;
  • 支持H.264扩展SEI发送模块;
  • 支持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);

技术实现如下:

/*
 * 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;
		}
	}

}

其中,PushSDKInit()实现如下:

	/*
     * 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;
	}

open_config_instance()实现如下,可以获取摄像头或屏幕数据,并做基础的编码等参数配置,看似复杂,实际和Windows平台相差不大:

	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");
			else
				fprintf(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");
			else
				fprintf(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);  // 平均码率2000kbps
		push_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 high
		push_api->SetVideoEncoderSpeed(push_handle, 3); // 编码速度设置到3

		if (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;
	}

其中,push_api->Open(&push_handle, video_option, auido_option, 0, NULL))时,设置音视频采集类型,相关类型如下:

/*
 * 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, // 已经编码的视频数据,目前支持H264
	NT_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;

推送RTMP流:

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;
}

如果需要本地摄像头或者屏幕预览数据,调研预览接口即可:

	// 开启预览,也可以不开启, 根据需求来
	push_api.SetPreviewXWindow(push_handle, "", sub_wid);
	push_api.StartPreview(push_handle, 0, nullptr);

如需停止:

	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;

总结

FFmpeg是一个开源的多媒体处理工具,支持几乎所有的音视频格式和编码标准,包括常见的H.264、AAC等,这使其在处理不同来源的音视频数据时具有极高的灵活性。并提供了丰富的编解码器选项,用户可根据需求选择合适的编解码器进行音视频数据的压缩和解压,从而优化传输效率和播放质量。大牛直播SDK针对Linux平台x86_64架构和aarch64架构的RTMP推送模块,系SDK,功能更完备,更适合产品化集成,配合自研的SmartPlayer RTMP播放器,延迟可达150-400ms,扩展性更强,以上是二者比较,抛砖引玉,感兴趣的开发者,可以单独跟我沟通。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2110678.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

js模块化 --- commonjs规范 原理详解

什么是commonjs规范 commonjs是一种模块化规范&#xff08;nodejs的默认模块化规范&#xff0c;新版的nodejs已经支持es6的模块化&#xff0c;但它默认任然使用的是commonjs&#xff09;&#xff0c;通俗的说它将代码分割成了一个一个的模块&#xff0c;让不同的模块拥有自己独…

使用“天聚数行”藏头诗生成API:轻松创作个性化诗词

在日常生活中&#xff0c;有时我们需要一些创意的方式来表达情感或增加趣味性。“天聚数行”提供的藏头诗生成API就是一个很好的工具&#xff0c;可以帮助我们轻松创作个性化的诗词。以下是关于如何使用这一API的详细介绍。 API概述 “天聚数行”的藏头诗生成API是上海觉克信息…

别给智能猫砂盆花冤枉钱了!这三款好用智能猫砂盆哪个更好用?

节假日回老家&#xff0c;不方便带猫咪怎么办&#xff1f;而且猫咪这么能拉&#xff0c;猫砂盆里拉满了又怎么办&#xff1f;猫砂盆一满&#xff0c;就会变脏&#xff0c;变脏了小猫就会抗拒上厕所&#xff0c;从而在家里找其他干净的地方排泄&#xff0c;那我们要怎么保证不在…

AIOT边缘计算机助力智慧储能,开启能源管理新时代

智慧储能能源管理正成为实现可持续发展和高效能源利用的关键。而 AIOT&#xff08;人工智能物联网&#xff09;边缘计算机的出现&#xff0c;为智慧储能能源管理带来了全新的机遇和突破。 一、AIOT 边缘计算机的特点 强大的计算能力 AIOT 边缘计算机具备高性能的处理器和充足…

widows安装配置mamba_ssm环境

由于现在mamba大火&#xff0c;所以将mamba_ssm在windows中的环境配置进行介绍&#xff0c;如果你想在windows中进行开发&#xff0c;那么这是你最好的选择&#xff01;&#xff01; 安装步骤 1.anaconda下载 官网下载&#xff1a;https://www.anaconda.com/download 下载好…

Java笔试面试题AI答之JDBC(4)

文章目录 19. 解释JDBC的ResultSet是什么 &#xff1f;20. JDBC编程有哪些不足之处&#xff0c;MyBatis是如何解决这些问题的&#xff1f;JDBC编程的不足之处MyBatis如何解决这些问题 21. 简述JDBC 能否处理 Blob 和 Clob &#xff1f;1. JDBC对Blob和Clob的支持2. 处理Blob和C…

【LeetCode】09.回文数

题目要求 解题思路 主要是提防越界问题 代码实现 class Solution { public:bool isPalindrome(int x) {//处理边界if(x<0) return false;long tempx,ret0;while(temp){retret*10temp%10;temp/10;}return xret;} };

Java并发编程实战 01 | 进程和线程

最早的计算机就像一个新手服务员&#xff0c;只有在接收到每一条指令时才会开始执行。当用户输入指令时&#xff0c;计算机会执行这条指令&#xff0c;然后等待下一条指令。如果用户在思考或者犹豫时&#xff0c;计算机就会乖乖地等待&#xff0c;效率实在是有点低&#xff0c;…

Swagger UI 无法发送 Cookie

文章目录 背景分析解决参考背景 项目中使用 Cookie 传递用户唯一标识,并在 Swagger 中添加 Cookie 作为全局请求参数。 尽管后端配置了 Cookie 请求参数,但在 Swagger UI 中使用 Try it out 发起请求时,发现请求中并没有 Cookie 传递过去。😭 首先,能看到 Curl 上已经有…

高级编程语言翻译例题

编译器的流程 源程序—词法分析—语法分析—语义分析—中间代码生成—代码优化—目标代码生成—目标程序 选项A&#xff1a;先进性词法分析&#xff0c;接着进行语法分析&#xff0c;最后进行语义分析 选项B&#xff1a;语法分析阶段只能发现程序上的语法错误&#xff0c;其…

软考高项通过率最高?!证书价值大吗?什么时候能报考?

近期有省份公布了2024年上半年软考合格人员名单&#xff0c;不少人说软考高项通过率最高&#xff0c;导致一些人十分想报名软考高项&#xff0c;从而拿证书。 那么&#xff0c;软考高项证书价值大吗&#xff1f;什么时候能报考&#xff1f; 1、通过率分析 在浙江公布的2024年…

YOLOv9改进策略【注意力机制篇】| GAM全局注意力机制: 保留信息以增强通道与空间的相互作用

一、本文介绍 本文记录的是基于GAM注意力模块的YOLOv9目标检测改进方法研究。GAM注意力模块通过3D排列和重新设计的子模块&#xff0c;能够在通道和空间方面保留信息&#xff0c;避免了先前方法中由于信息减少和维度分离而导致的全局空间-通道交互丢失的问题。本文利用GAM改进…

UML的图及其他图补充

一、UML图 1.类图 ‌类图‌是统一建模语言&#xff08;UML&#xff09;中的一种静态结构图&#xff0c;主要用于描述软件系统的静态结构。它显示了模型中的类、类的内部结构以及它们与其他类的关系。类图是面向对象建模的主要组成部分&#xff0c;用于对系统的词汇进行建模、对…

android开发---Kotlin语言基础语法

目录 数据打印 变量 函数 程序逻辑控制 if when 循环 数据打印 IDE采用的androidStudio 可自行官网下载 https://developer.android.google.cn/studio/archive?hlzh-cn 新建项目 添加一个main方法&#xff0c;main()函数的左边出现了一个运行标志的小箭头。现在我们只…

LLaMA-Factory仓基础功能架构及NPU/GPU环境实战演练

LLaMA-Factory 基础篇 LLaMA-Factory简介 LLaMA-Factory是一个开源的大规模语言模型微调框架&#xff0c;设计用于简化大模型的训练过程。它提供了一个统一的平台&#xff0c;支持多种大模型的微调&#xff0c;包括LLaMA、BLOOM、Mistral等&#xff0c;旨在帮助用户快速适应和…

数据脱敏处理

有关于数据脱敏处理&#xff0c;小编也是在文章上面看到的&#xff0c;感觉很有意思&#xff0c;那么&#xff0c;便深入研究了一下&#xff0c;首先我们先来看一下数据脱敏之后的结果吧&#xff1f; 用结果说话更能深入人心&#xff01;&#xff01; 下面是数据库中的字段&a…

fantastic-admin前端+django后端,初始化全流程记录

fantastic-admin前端是我目前看到最完善的前端框架&#xff0c;只需要简单的设置就可以快速开始项目。 但是我本人的能力有限&#xff0c;对前端知识一知半解&#xff0c;之前废了九牛二虎之力才跑通了前后端流程&#xff0c;由于新的项目需要&#xff0c;有了开发新后台的想法…

了解PD快充协议和QC快充协议

PD快充协议的实现依赖充电器与设备之间的通信协议&#xff0c;这种通信协议确保了充电器能够提供设备所需要的特定电压和电流。在快充技术中快充协议起到关键角色。 现在市面上最常见的快充协议有PD、QC、华为FCP/SCP、三星AFC协议 、VOOC闪充。PD和QC 协议属于公用协议 。华…

C/C++经典排序问题,sort函数使用

目录 1. 前言 2. 正文 2.1 问题 2.2 解决办法 2.2.1 思路 2.2.2 代码实现 2.2.3 测试结果 3. 备注 1. 前言 大家在学习C语言的时候&#xff0c;是不是经常被排序算法折磨的很难那首&#xff0c;其实都是但是在C中有专门的&#xff0c;排序函数&#xff0c;而且支持自定…

vue系统获取授权平台授权码实现单点登录、注销功能

公司平台需要对接别的平台 实现单点登录 注销。简而言之&#xff0c;不需要在自己公司系统登录 统一在别的平台登录后获取到登录凭证&#xff08;授权码&#xff09; 在本公司系统实现免密登录的功能。 流程&#xff1a; 跳转授权页面和保存授权码的代码&#xff1a; hrefLog…