FFmpeg学习:查看可用设备

获得可用设备列表

【方法一】ffmpeg只能输出可用设备信息,无法直接获得设备列表包括名字。
【方法二】直接利用dshow通过com口获得
获取设备列表

终端命令

#列出可用设备
ffmpeg -list_devices true -f dshow -i dummy 
#查看指定设备可用参数
ffmpeg -list_options true -f dshow -i audio="麦克风 (2- Realtek(R) Audio)"

api函数(stdout打印设备信息)

//Show Dshow Device
void show_dshow_device() {
	AVFormatContext* pFormatCtx = avformat_alloc_context();
	AVDictionary* options = NULL;
	av_dict_set(&options, "list_devices", "true", 0); //0表示不区分大小写
	AVInputFormat* iformat = av_find_input_format("dshow");
	printf("========Device Info=============\n");
	avformat_open_input(&pFormatCtx, "video=dummy", iformat, &options);
	printf("================================\n");
	avformat_free_context(pFormatCtx);
}
//Show Dshow Device Option
void show_dshow_device_option() {
	AVFormatContext* pFormatCtx = avformat_alloc_context();
	AVDictionary* options = NULL;
	av_dict_set(&options, "list_options", "true", 0);
	AVInputFormat* iformat = av_find_input_format("dshow");
	printf("========Device Option Info======\n");
	avformat_open_input(&pFormatCtx, "video=Integrated Camera", iformat, &options);
	printf("================================\n");
	avformat_free_context(pFormatCtx);
}

//Show VFW Device
void show_vfw_device() {
	AVFormatContext* pFormatCtx = avformat_alloc_context();
	AVInputFormat* iformat = av_find_input_format("vfwcap");
	printf("========VFW Device Info======\n");
	avformat_open_input(&pFormatCtx, "list", iformat, NULL);
	printf("=============================\n");
	avformat_close_input(&pFormatCtx);
	avformat_free_context(pFormatCtx);
}

获得设备列表(dshow)

相关api--获取设备的几个api无法使用,内部没有实现

设备输入输出
16个API,4个结构体,2个枚举

整体:
libavdevice说明

结构体:
AVDeviceRect: 图像窗口的起始xy,窗口宽高大小
AVDeviceCapabilitiesQuery: 一个封装的类可继承,包含了封装类,指定编解码、音频采样深度、音频采样率、音频通道数、图像位宽、窗口宽高、帧宽高、帧率
AVDeviceInfo: 设备名字符串,设备描述字符串
AVDeviceInfoList: 设备名、设备总数、默认设备

API:
avdevice_version 获取版本号
avdevice_configuration 获取库编译时的配置
avdevice_license 获取许可证
avdevice_register_all 注册所有输入输出设备
av_input_audio_device_next 迭代获取一项音频输入设备
av_input_video_device_next 迭代获取一项视频输入设备
av_output_audio_device_next 迭代获取一项音频输出设备
av_output_video_device_next 迭代获取一项视频输出设备
avdevice_app_to_dev_control_message 从应用程序向设备发送控制消息
avdevice_dev_to_app_control_message 从设备向应用发送控制消息
avdevice_capabilities_create 获取设备名对应的可用的设备参数信息(不同设备私有)
avdevice_capabilities_free 上一条API使用后进行释放用
avdevice_list_devices 获取可用的设备名和参数(无法使用,ffmpeg内部没有实现)
avdevice_free_list_devices 和上一条配套使用
avdevice_list_input_sources 获取可用的输入设备名和参数
avdevice_list_output_sinks 获取可用的输出设备

posted @ 2022-07-19 15:26  小超不挑食  阅读(2570)  评论(0编辑  收藏  举报