遍历设备列表.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. extern "C"
  2. {
  3. #include "libavcodec/avcodec.h"
  4. #include "libavformat/avformat.h"
  5. #include "libswscale/swscale.h"
  6. #include "libavdevice/avdevice.h"
  7. }
  8. //'1' Use Dshow
  9. //'0' Use VFW
  10. #define USE_DSHOW 0
  11. //Show Dshow Device
  12. void show_dshow_device()
  13. {
  14. AVFormatContext *pFormatCtx = avformat_alloc_context();
  15. AVDictionary* options = nullptr;
  16. av_dict_set(&options,"list_devices","true",0);
  17. AVInputFormat *iformat = av_find_input_format("dshow");
  18. printf("========Device Info=============\n");
  19. avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);
  20. printf("================================\n");
  21. }
  22. //Show Dshow Device Option
  23. void show_dshow_device_option()
  24. {
  25. AVFormatContext *pFormatCtx = avformat_alloc_context();
  26. AVDictionary* options = nullptr;
  27. av_dict_set(&options,"list_options","true",0);
  28. AVInputFormat *iformat = av_find_input_format("dshow");
  29. printf("========Device Option Info======\n");
  30. avformat_open_input(&pFormatCtx,"video=Integrated Camera",iformat,&options);
  31. printf("================================\n");
  32. }
  33. //Show VFW Device
  34. void show_vfw_device()
  35. {
  36. AVFormatContext *pFormatCtx = avformat_alloc_context();
  37. AVInputFormat *iformat = av_find_input_format("vfwcap");
  38. printf("========VFW Device Info======\n");
  39. avformat_open_input(&pFormatCtx,"list",iformat,nullptr);
  40. printf("=============================\n");
  41. }
  42. //Show AVFoundation Device
  43. void show_avfoundation_device()
  44. {
  45. AVFormatContext *pFormatCtx = avformat_alloc_context();
  46. AVDictionary* options = nullptr;
  47. av_dict_set(&options,"list_devices","true",0);
  48. AVInputFormat *iformat = av_find_input_format("avfoundation");
  49. printf("==AVFoundation Device Info===\n");
  50. avformat_open_input(&pFormatCtx, "",iformat, &options);
  51. printf("=============================\n");
  52. }
  53. void getDeviceList()
  54. {
  55. av_register_all();
  56. avformat_network_init();
  57. avdevice_register_all();
  58. //Show Dshow Device
  59. show_dshow_device();
  60. //Show Device Options
  61. show_dshow_device_option();
  62. //Show VFW Options
  63. show_vfw_device();
  64. }