如何查询ffmpeg中的所有设备?

时间:2015-08-14 08:38:29

标签: ffmpeg v4l2

如何使用libavdevice正确查询系统中的所有视频设备? 使用int err = avformat_open_input(&context, NULL, fmt, NULL);打开输入失败,因为未提供设备名称(第二个参数是设备名称,如果提供"/dev/video0",例如它只找到该设备):

    avcodec_register_all();
    avdevice_register_all();
    AVFormatContext* context = avformat_alloc_context();
    AVInputFormat *fmt = av_find_input_format("video4linux");
    printf("trying to open input");
    int err = avformat_open_input(&context, "/dev/video0", fmt, NULL);
    if(err != 0){
        fprintf(stderr, "ffmpeg failed to open input");
    }
    static struct AVDeviceInfoList* devices_list;
    avdevice_list_devices(context, &devices_list);
    int devices_count = devices_list->nb_devices;
    for(int i = 0; i < devices_count; i++){
        printf("Checking device nr. %d \n", i);
        AVDeviceInfo* current_device_info = devices_list->devices[i];

       printf("Find Device: %s", current_device_info->device_description);
    }

    avformat_free_context(context);

如何初始化AVFormatContext以查找所有v4l2设备?我想如果上下文部分初始化(假设所有v4l2设备)它应该正确查询所有内容。当上下文与avformat_open_input一起运行时,必须事先提供确切的设备名称。

0 个答案:

没有答案