自己写的C++代码,用ffmpeg的“kmsgrab”作为输入设备截屏,avformat_open_input()返回值一直是-22,查了下意思是“Invalid argument”。
代码如下:
AVInputFormat *ifmt = nullptr;
AVFormatContext *m_vFmtCtx = nullptr;
AVDictionary *options = nullptr;
int openInputRet = -1;
ifmt = av_find_input_format("kmsgrab");
if (ifmt){
av_dict_set(&options, "framerate", "30", 0);
//av_dict_set(&options, "format", "bgr0", 0);
//av_dict_set(&options, "format_modifier", "hwdownload", 0);
openInputRet = avformat_open_input(&m_vFmtCtx, "-", ifmt, &options);
printf("avformat_open_input ret: %d\n", openInputRet);//--------------------返回值openInputRet 是 -22
} else {
printf("no kmsgrab!\n");
}
按FFmpeg Devices Documentation中kmsgrab设备的示例指令执行,可以成功,但不知道c代码怎么写,下面是ffmpeg文档中的示例指令:
ffmpeg -f kmsgrab -i - -vf 'hwdownload,format=bgr0' output.mp4
ffmpge Devices Documentation链接:
FFmpeg Devices Documentation
http://ffmpeg.org/ffmpeg-devices.html
恳请指点!多谢!!