ffmpeg

ffmpeg avformat_open_input() failed to open a dshow device url containing Chinese Characters


The USB Webcam is OK, but the device I want to use is a "virtual camera" named "无他伴侣(竖屏)", whose video is from the smart phone like Android or iOS. Connect the phone to PC, run an app on the phone, then run a PC client application, which can preview the video. The phone app is called "无他相机", and the PC app is called "无他伴侣", its website is https://www.wuta-cam.com/.

I run FFmpeg at the Windows Commandline with the command ffmpeg -list_devices true -f dshow -i dummy, it's OK to list the devices.(in order to display Chinese correctly, run chcp 65001 in advance.)

Run the command ffplay -f dshow -i video="无他伴侣(竖屏)", it's OK to play the video.(of course you need to comfirm its PC client previewing fine in advance.)

Now I want to get the decoded frames from that virtual camera in my program, I call avformat_open_input() with video=无他伴侣(竖屏), it failed, the return value is -5, I/O error.

Anyone knows the reason?

Below is my code snippet.

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

Solution

  • FFmpeg may not process Chinese characters directly. If the device name contains Chinese chatacters, FFmpeg will report that cannot find the device with the given name. I tried the Windows API function WideCharToMultiByte(), it works.