ffmpeg获取摄像头支持列表

  1.  的libavdevice类库最简单的例子。通过该例子,可以学习FFmpeg中 
  2.  * libavdevice类库的使用方法。 
  3.  * 本程序在Windows下可以使用2种方式读取摄像头数据: 
  4.  *  1.VFW: Video for Windows 屏幕捕捉设备。注意输入URL是设备的序号, 
  5.  *          从0至9。 
  6.  *  2.dshow: 使用Directshow。注意作者机器上的摄像头设备名称是 
  7.  *         “Integrated Camera”,使用的时候需要改成自己电脑上摄像头设 
  8.  *          备的名称。 
  9.  * 在Linux下可以使用video4linux2读取摄像头设备。 
  10.  * 在MacOS下可以使用avfoundation读取摄像头设备。 

qt 

工程文件pro:

SOURCES += \
    ffmpeg_libavdevice.cpp

INCLUDEPATH += $$PWD/ffmpeg/include

LIBS += $$PWD/ffmpeg/lib/avcodec.lib \
        $$PWD/ffmpeg/lib/avdevice.lib \
        $$PWD/ffmpeg/lib/avfilter.lib \
        $$PWD/ffmpeg/lib/avformat.lib \
        $$PWD/ffmpeg/lib/avutil.lib \
        $$PWD/ffmpeg/lib/postproc.lib \
        $$PWD/ffmpeg/lib/swresample.lib \
        $$PWD/ffmpeg/lib/swscale.lib


INCLUDEPATH += $$PWD/ffmpeg/include


源文件

ffmpeg_libavdevice.cpp


extern "C"
{
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"
    #include "libavutil/pixfmt.h"
    #include "libswscale/swscale.h"
    #include "libavdevice/avdevice.h"
}
//Show 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()
{
    //注册
    av_register_all();


    avdevice_register_all();
    
    show_dshow_device();
}

你可能感兴趣的:(ffmpeg)