主要学习的是ffmpeg官方demo里的doc/examples/filtering_audio.c
ffmpeg混流的主要流程
- 初始化filter
- 读取aac数据,解码后将数据压入filter buffer中
- 从buffer中取出数据编码成aac数据
1、初始化filter
首先定义需要使用到的变量:
static const char *filter_desc =
"aresample=48000,aformat=sample_fmts=fltp:channel_layouts=stereo";
/** An instance of a filter */
AVFilterContext *buffersink_ctx; //sink filter实例(输出)
AVFilterContext *buffersrc_ctx; //src filter实例(输入)
AVFilterGraph *filter_graph;
char args[512];
int ret = 0;
/**
* Filter definition. This defines the pads a filter contains, and all the
* callback functions used to interact with the filter.
*/
const AVFilter *abuffersrc = avfilter_get_by_name("abuffer"); //有多少个输入就创建多少个,当输入输出为一的时候相当于直接重采样
const AVFilter *abuffersink = avfilter_get_by_name("abuffersink"); //有多少个输出就创建多少个
/**
* A linked-list of the inputs/outputs of the filter chain.
*
* This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
* where it is used to communicate open (unlinked) inputs and outputs from and
* to the caller.
* This struct specifies, per each not connected pad contained in the graph,
* the filter context and the pad index required for establishing a link.
*/
AVFilterInOut *outputs = avfilter_inout_alloc(); //输入filter chain
AVFilterInOut *inputs = avfilter_inout_alloc(); //输出filter chain
static const enum AVSampleFormat out_sample_fmts[] = {
AV_SAMPLE_FMT_FLTP, (enum AVSampleFormat) - 1}; //输出sample_fmt
static const int64_t out_channel_layouts[] = {
3, -1};//输出channel_layouts
static const int out_sample_rates[] = {
48000, -1}; //输出sample_rates
const AVFilterLink *outlink;
AVRational time_base = fmt_ctx->streams[audio_stream_index]->

最低0.47元/天 解锁文章
581

被折叠的 条评论
为什么被折叠?



