写一个基于ffmpeg采集usb音频设备后采集的程序代码
时间: 2023-03-13 20:23:20 浏览: 124
ffmpeg 音频数据采集
以下是基于ffmpeg采集usb音频设备后采集的程序代码:#include <stdio.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>int main(int argc, char *argv[]) {
AVFormatContext *fmt_ctx = NULL;
AVDictionary *options = NULL;
int ret = 0; avdevice_register_all(); /* open usb audio device */
ret = avformat_open_input(&fmt_ctx, "usb:", NULL, &options);
if (ret < 0) {
fprintf(stderr, "Failed to open USB audio device: %s\n", av_err2str(ret));
return -1;
} /* read data frames from device */
ret = av_read_frame(fmt_ctx, &pkt);
if (ret < 0) {
fprintf(stderr, "Failed to read data frame from USB audio device: %s\n", av_err2str(ret));
return -1;
} av_packet_unref(&pkt);
avformat_close_input(&fmt_ctx); return 0;
}
阅读全文