首页 > 解决方案 > 使用 ffmpeg,函数 av_find_input_format("avfoundation") 返回 null

问题描述

我在 iPad mini 4(型号 A1538)、iOS 11.2.6 中运行此代码

尝试通过 FFmpeg 录制音频。

av_register_all();
avcodec_register_all();
avdevice_register_all();

AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options,"list_devices","true",0);
AVInputFormat *iformat = av_find_input_format("avfoundation");
printf("==AVFoundation Device Info===\n");
avformat_open_input(&pFormatCtx,"",iformat,&options);
printf("=============================\n");

if(avformat_open_input(&pFormatCtx,"0",iformat,NULL)!=0){
    printf("Couldn't open input stream.\n");
    return;
}

pFormatCtx=NULLiformat= NULL

为什么会发生这种情况,我错过了什么设置吗?

标签: iosffmpegrecord

解决方案


inputContext = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options, "video_size","960x54", 0);
av_dict_set(&options, "r","30", 0);
AVInputFormat *iformat = av_find_input_format("avfoundation");
int ret = avformat_open_input(&inputContext,"0:0", iformat,&options);

AVFoundation 输入设备。AVFoundation 是 Apple 目前推荐的用于在 OSX >= 10.7 以及 iOS 上进行流抓取的框架。输入文件名必须以以下语法给出:-i "[[VIDEO]:[AUDIO]]"


推荐阅读