usb摄像头的名称,window下,可以通过命令查看ffmpeg -list_devices true -f dshow -i dummy
也可以直接在 设备管理器 中查看,例如:
代码如下:
avdevice_register_all(); //这个不能少,否则会打开失败。
AVFormatContext *pFormatCtx=nullptr;//如果不初始化为nullptr,程序会异常。
AVInputFormat *iformat =av_find_input_format("dshow");
if (avformat_open_input(&pFormatCtx, "video=LRCP USB2.0", iformat, NULL) != 0)
{
printf("Couldn't open input stream.\n");
return -1;
}