C语言调用ffmepg 获取摄像头设备列表
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
//Show Dshow Device
void show_dshow_device(){
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options,"list_devices","true",0);
AVInputFormat *iformat = av_find_input_format("dshow");
printf("========Device Info=============\n");
avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);
printf("================================\n");
}
int main(int argc, char* argv[])
{
// av_register_all();
// avformat_network_init();
// pFormatCtx = avformat_alloc_context();
//Register Device
avdevice_register_all();
//Show Dshow Device
show_dshow_device();
}
注意,用的版本是ffmpeg4.2
编译方法:
gcc .\device.c -I D:\msys64\home\Administrator\ffmpeg4\include -L D:\msys64\home\Administrator\ffmpeg4\lib -lavformat -lavcodec -lavutil -lavdevice -lswscale
此代码基于雷霄骅 的 改写,感谢大神。