Windows平台RTMP推送|轻量级RTSP服务录像模块如何支持中文路径?

简介: Windows平台RTMP推送|轻量级RTSP服务录像模块如何支持中文路径?

技术背景

我们在做Windows平台RTMP推送、轻量级RTSP服务录像模块的时候,部分开发者抱怨路径无法设置中文,只能设置为英文。

image.gif编辑

以C#的接口为例,早期的设计如下:

/** 设置本地录像目录, 必须是英文目录,否则会失败*/    [DllImport(@"SmartPublisherSDK.dll")]
publicstaticexternUInt32NT_PB_SetRecorderDirectory(IntPtrhandle, [MarshalAs(UnmanagedType.LPStr)] Stringdir, IntPtrpReserve);

image.gif

考虑到一些场景的特殊性,可能需要中文路径,我们设计的接口如下:

/** 设置本地录像目录, 支持中文目录, 需要设置宽字符,比如L"D:\\xxx\\gg"*/        [DllImport(@"SmartPublisherSDK.dll")]
publicstaticexternUInt32NT_PB_SetRecorderDirectoryW(IntPtrhandle, [MarshalAs(UnmanagedType.LPWStr)]Stringdir, IntPtrpReserve);

image.gif

调用如下,以调用开始录像、暂停录像、停止录像为例,调用逻辑如下,可以看到除了中文路径诉求,录像模块还可以添加前缀、添加文字、水印:

publicboolStartRecorder()
        {
if (is_empty_handle() ||is_recording())
returnfalse;
//string edit_rec_dir = "D:\\dntest";stringedit_rec_dir="D:\\推送端录像";
if (String.IsNullOrEmpty(edit_rec_dir))
            {
Console.WriteLine("请设置录像目录");
returnfalse;
            }
uintret=NTSmartPublisherSDK.NT_PB_SetRecorderDirectoryW(handle_, edit_rec_dir, IntPtr.Zero);
if (NTBaseCodeDefine.NT_ERC_OK!=ret)
            {
try_close_handle();
returnfalse;
            }
uintrec_max_file_size=512*1024;
NTSmartPublisherSDK.NT_PB_SetRecorderFileMaxSize(handle_, rec_max_file_size);
NT_PB_RecorderFileNameRulerrec_name_ruler=newNT_PB_RecorderFileNameRuler();
Stringrec_file_name_prefix_="transcode-rec";
rec_name_ruler.file_name_prefix_=rec_file_name_prefix_.ToString();
rec_name_ruler.append_date_=1;
rec_name_ruler.append_time_=1;
NTSmartPublisherSDK.NT_PB_SetRecorderFileNameRuler(handle_, refrec_name_ruler);
if (NTBaseCodeDefine.NT_ERC_OK!=NTSmartPublisherSDK.NT_PB_StartRecorder(handle_, IntPtr.Zero))
            {
try_close_handle();
returnfalse;
            }
shared_lock_.EnterWriteLock();
try            {
handle_reference_count_++;
is_recording_=true;
            }
finally            {
shared_lock_.ExitWriteLock();
            }
returntrue;
        }
publicUInt32PauseRecorder(boolis_pause)
        {
if (is_empty_handle() ||!is_recording())
returnNTBaseCodeDefine.NT_ERC_FAILED;
UInt32ret=NTBaseCodeDefine.NT_ERC_OK;
if (is_pause)
            {
ret=NTSmartPublisherSDK.NT_PB_PauseRecorder(handle_, 1);
if ((UInt32)NT.NTSmartPublisherDefine.NT_PB_E_ERROR_CODE.NT_ERC_PB_NEED_RETRY==ret)
                {
Console.WriteLine("暂停录像失败, 请重新尝试!");
returnret;
                }
elseif (NTBaseCodeDefine.NT_ERC_OK==ret)
                {
//btn_pause_rec.Text = "恢复录像";                }
            }
else            {
ret=NTSmartPublisherSDK.NT_PB_PauseRecorder(handle_, 0);
if ((UInt32)NT.NTSmartPublisherDefine.NT_PB_E_ERROR_CODE.NT_ERC_PB_NEED_RETRY==ret)
                {
Console.WriteLine("恢复录像失败, 请重新尝试!");
returnret;
                }
elseif (NTBaseCodeDefine.NT_ERC_OK==ret)
                {
//btn_pause_rec.Text = "暂停录像";                }
            }
returnret;
        }
publicvoidStopRecorder()
        {
if (is_empty_handle() ||!is_recording())
return;
shared_lock_.EnterWriteLock();
try            {
is_recording_=false;
handle_reference_count_--;
            }
finally            {
shared_lock_.ExitWriteLock();
            }
NTSmartPublisherSDK.NT_PB_StopRecorder(handle_);
try_close_handle();
        }

image.gif

开始录像和录像完成后,提示如下:

privatevoidPbEventCallBack(UInt32event_id,
Int64param1,
Int64param2,
UInt64param3,
UInt64param4,
            [MarshalAs(UnmanagedType.LPStr)] Stringparam5,
            [MarshalAs(UnmanagedType.LPStr)] Stringparam6,
IntPtrparam7)
        {
Stringevent_log="";
switch (event_id)
            {
                ......
case (uint)NTSmartPublisherDefine.NT_PB_E_EVENT_ID.NT_PB_E_EVENT_ID_RECORDER_START_NEW_FILE:
event_log=" start new recorder file";
byte[] utf8_bytes=Encoding.Default.GetBytes(param5);
byte[] default_bytes=Encoding.Convert(Encoding.UTF8, Encoding.Default, utf8_bytes);
Stringfile_name=Encoding.Default.GetString(default_bytes);
if (!String.IsNullOrEmpty(file_name))
                    {
event_log=event_log+" file name:"+file_name;
                    }
break;
case (uint)NTSmartPublisherDefine.NT_PB_E_EVENT_ID.NT_PB_E_EVENT_ID_ONE_RECORDER_FILE_FINISHED:
event_log=" finish recorder file";
byte[] finished_utf8_bytes=Encoding.Default.GetBytes(param5);
byte[] finished_default_bytes=Encoding.Convert(Encoding.UTF8, Encoding.Default, finished_utf8_bytes);
Stringfinished_file_name=Encoding.Default.GetString(finished_default_bytes);
if (!String.IsNullOrEmpty(finished_file_name))
                    {
event_log=event_log+" file name:"+finished_file_name;
                    }
break;
                .......
default:
break;
            }
EventGetPublisherEventMsg(event_log);
        }

image.gif

总结

Windows平台RTMP推送、轻量级RTSP服务配套的录像模块,除了设置录像保存路径外、还可以设置录像文件前缀、是不是添加日期、时间等,还有就是单个录像文件大小,超过这个大小后,会自动切换到下个文件,需要测试交流的,可以跟我联系。

相关文章
|
28天前
|
开发框架 监控 安全
Windows Defender 导致 Web IIS 服务异常停止排查
某日凌晨IIS服务异常停止,经查为Windows Defender安全补丁KB2267602触发引擎更新,导致系统资源波动,进而引发应用池回收。确认非人为操作,系统无重启。通过分析日志与监控,定位原因为Defender更新后扫描加重负载。解决方案:将IIS及.NET相关路径添加至Defender排除列表,避免业务影响。
273 116
|
1月前
|
监控 编译器 Windows
Qt5实现Windows平台串口通信
Qt5实现Windows平台串口通信
|
1月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
303 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
1月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
169 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
2月前
|
安全 Linux API
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.31 (macOS, Linux, Windows) - 逆向工程平台
145 0
|
3月前
|
Unix Linux 编译器
解决在Windows平台上运行Golang程序时出现的syscall.SIGUSR1未定义错误。
通过这种结构,你的代码既可以在支持 SIGUSR1 信号的系统上正常工作,又可以在不支持这些信号的 Windows 系统上编译通过,确保跨平台的兼容性和功能的完整性。
168 0
|
Unix Linux iOS开发
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
103 0
|
6月前
|
安全 前端开发 Linux
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
200 3
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
|
8月前
|
固态存储 C++ 计算机视觉
Windows平台GIMP 2.10下载教程:零基础入门高级图像编辑
GIMP(GNU Image Manipulation Program)是一款开源跨平台图像编辑工具,支持图层管理、高级修图、色彩校正等功能,广泛应用于平面设计和照片修复。其优势包括全功能免费、插件生态丰富(600+扩展插件)、硬件要求低(1GB内存即可流畅运行)。本文详细介绍GIMP的软件定位、安装流程、首次配置及常见问题解答,帮助用户快速上手并充分利用其强大功能。
|
8月前
|
Linux iOS开发 MacOS
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务
231 0
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务