ffmpeg avformat_open_input()无法打开包含汉字的dshow设备网址

时间:2020-04-28 08:55:51

标签: ffmpeg

USB网络摄像头还可以,但是我要使用的设备是名为“无他伴侣(竖屏)”的“虚拟相机”,其视频来自智能手机,例如Android或iOS。将电话连接到PC,在电话上运行应用程序,然后运行PC客户端应用程序,可以预览视频。电话应用程序称为“无他相机”,而PC应用程序称为“无他伴侣”,其网站为https://www.wuta-cam.com/

我在Windows命令行上使用命令ffmpeg -list_devices true -f dshow -i dummy运行FFmpeg,可以列出设备。(为了正确显示中文,请提前运行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;
}

1 个答案:

答案 0 :(得分:1)

FFmpeg可能无法直接处理汉字。如果设备名称包含中文字符,则FFmpeg将报告找不到给定名称的设备。我尝试了Windows API函数WideCharToMultiByte(),它起作用了。

相关问题