ffmpeg - ffmpeg avformat_open_input() 无法打开包含中文字符的 dshow 设备 url
问题描述
USB网络摄像头还可以,但我要使用的设备是一个名为“无他伴侣(竖屏)”的“虚拟摄像头”,其视频来自Android或iOS等智能手机。将手机连接到 PC,在手机上运行一个应用程序,然后运行一个 PC 客户端应用程序,它可以预览视频。手机应用名为“无他相机”,PC应用名为“无他伴侣”,网址为https://www.wuta-cam.com/。
我在Windows命令行下用命令运行FFmpeg,ffmpeg -list_devices true -f dshow -i dummy
列出设备就可以了。(为了正确显示中文,请chcp 65001
提前运行。)
运行命令ffplay -f dshow -i video="无他伴侣(竖屏)"
,就可以播放视频了。(当然需要提前确认其PC客户端预览正常。)
现在我想在我的程序中从那个虚拟相机获取解码帧,我avformat_open_input()
用调用video=无他伴侣(竖屏)
,它失败了,返回值为 -5,I/O 错误。
有人知道原因吗?请帮忙。提前致谢。
下面是我的代码片段。
avdevice_register_all();
avcodec_register_all();
//const char * url= "video=Logitech Webcam C930e";// This is fine.
char url[] = "video=无他伴侣(竖屏)";// This is bad.
AVFormatContext *pFmtCtx = avformat_alloc_context();
AVInputFormat *iformat = av_find_input_format("dshow");
int nRet = 0;
nRet = avformat_open_input(&pFmtCtx, url, iformat, NULL);
if (nRet)
{
const size_t buffer_size = 256;
char err_description[buffer_size];
av_strerror(nRet, err_description, buffer_size);
printf("%s.\n", err_description);// --> I/O error.
printf("FAILED to open input.(Line:%d,%d)\n", __LINE__, nRet);
return -1;
}
解决方案
FFmpeg 可能无法直接处理汉字。如果设备名称中包含中文字符,FFmpeg 会报找不到给定名称的设备。我尝试了 Windows API 函数WideCharToMultiByte()
,它可以工作。
推荐阅读
- python - PyCharm 调试变量视图:禁用变量地址
- database - “必须”或“可以”一词表示完全参与
- c - 从C中的数字中提取值
- javascript - 无法在 xhtml 页面中执行 primefaces javascript
- java - 以编程方式在相对布局中创建线性布局
- c# - 在第二个 DataGridView 中显示剩余值
- sql - 从绑定到特定主键的不同行中添加值
- vb.net - 在 VB.net 中合并多个 Word 文档时,如何防止“应用程序正忙”错误?
- c# - 具有作为基类 ActionFilterAttribute 的类的问题
- c# - 在不需要线程池时处理 async/await