test.c 找不到设备

来源:6-7 Mac App中引入ffmpeg库

weixin_慕勒4383646

2023-01-14

李老师:
学生编写了test.c后执行报错如下:Failed to open audio device, [-1330794744]Protocol not found,好像是找不到音频设备
但webrtc能找到。麻烦李老师指点一下问题出在哪里?
学生的test.C代码如下:

 #include "test.h"
 void haha(){

        int ret = 0;
        char errors[1024] = {0,};
        AVFormatContext *fmt_ctx = NULL;
        AVDictionary *options = NULL;

        char *devicename = "hw:0,0";

        avdevice_register_all();

        AVInputFormat *iformat = av_find_input_format("alsa");
        ret =  avformat_open_input(&fmt_ctx,devicename,iformat,&options);
        if(ret < 0){
                av_strerror(ret,errors,1024);
                printf("Failed to open audio device, [%d]%s\n", ret, errors);
                return;
        }
        av_log_set_level(AV_LOG_DEBUG);
        av_log(NULL,AV_LOG_DEBUG,"Hello World!\n");
        return;
}
int main(int argc,char* argv[]){
        haha();
        return 0;
}

test.h 代码如下:

#ifndef test_h
#define test_h

#include <stdio.h>
#include "libavutil/avutil.h"
#include "libavdevice/avdevice.h"
#include "libavformat/avformat.h"


void haha(void);


#endif

编译如下:
gcc -g -o test test.c -I /usr/local/ffmpeg/include -L /usr/local/ffmpeg/lib -lavutil -lavdevice -lavformat
编译成功了 test 执行文件

写回答

1回答

李超

2023-01-14

你用ffmpeg命令可以找到设备吗?

1
3
weixin_慕勒4383646
ffmpeg 已成功找到alsa,谢谢李老师指点
2023-01-16
共3条回复

音视频小白系统入门课 音视频基础+ffmpeg原理

掌握音视频采集、编解码、RTMP传输协议等核心基础

2318 学习 · 813 问题

查看课程