FFmpeg 混音学习【一】FFmpeg aac音频混流学习及问题记录

主要学习的是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]->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值