#include <stdio.h>
#include <iostream>
extern "C" {
#include <libavutil/avutil.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
#include <Windows.h>
int main() {
AVFormatContext* fmt_ctx = nullptr;
const char* devicename = "audio=@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\\wave_{45047AF6-023E-47A2-A5CA-0308DA9AAAE3}";
avdevice_register_all();
const AVInputFormat* iformat = av_find_input_format("dshow");
AVDictionary* options = nullptr;
int ret = avformat_open_input(&fmt_ctx, devicename, iformat, &options);
char errors[2024];
if (ret < 0) {
av_strerror(ret, errors, 1024);
}
FILE *outfile = fopen("D:\videoStudy\tryFile\try.pcm", "wb+");
AVPacket pkt;
int count = 0;
while ((ret = av_read_frame(fmt_ctx, &pkt)) == 0 && count ++ < 400) {
ret = av_read_frame(fmt_ctx, &pkt);
fwrite(pkt.data, pkt.size, 1, outfile);
fflush(outfile);
av_packet_unref(&pkt);
}
fclose(outfile);
avformat_close_input(&fmt_ctx);
return 0;
}
我是这样写的,应该取走了吧,太长了,去掉avlog了