java mix audio_audiomix混合多路音频为一路音频

这个博客介绍了一种使用ffmpeg库的C++实现,通过`amix`过滤器将两个或多个音频文件(如Beyond1.mp3和Beyond2.mp3)混合成一个音频文件(a.mp3)。它涉及了avformat、avcodec、avfilter等库的使用,包括打开输入文件、找到音频流、初始化过滤器和创建混合音频的流程。
摘要由CSDN通过智能技术生成

//20150514

//#include "StdAfx.h"

//#include

#include

#include

#include

#include "libavutil/opt.h"

//#include

#include "avfilter.h"

#include "avformat.h"

#include "avcodec.h"

#include "buffersink.h"

#include "frame.h"

#include "buffersrc.h"

#include "avutil.h"

#define LOG_ERR(var,...)\

do{ \

fprintf(stderr,"\033[31m[ERROR:%s->%s:%d] " var "\033[0m", __FILE__, \

__func__,__LINE__, ##__VA_ARGS__); \

}while(0);

const char *filter_descr = "amix=inputs=2,asetnsamples=n=1024";

typedef void* LPVOID;

void getMixAudio();

FILE * f;

//FILE* f1;

//ffmpeg -i 1.mp3 -i 2.mp3 -filter_complex amix=inputs=2:duration=longest:dropout_transition=2 a.mp3

//ffmpeg -i 1.mp3  -i 2.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f mp3 a.mp3

static AVFormatContext *fmt_ctx1;

static AVFormatContext *fmt_ctx2;

static AVFormatContext *fmt_ctx3;

static AVCodecContext *dec_ctx1;

static AVCodecContext *dec_ctx2;

static AVCodecContext *dec_ctx3;

AVFilterContext *buffersink_ctx;

AVFilterContext *buffersrc_ctx1;

AVFilterContext *buffersrc_ctx2;

AVFilterContext *buffersrc_ctx3;

AVFilterGraph *filter_graph;

static int audio_stream_index = -1;

AVFrame* frame1;

AVFrame* frame2;

AVFrame* frame3;

//CRITICAL_SECTION crt;

//CRITICAL_SECTION crt_mix;

pthread_mutex_t crt;

pthread_mutex_t crt_mix;

static int open_input_file(const char *filename, AVFormatContext* fmt_ctx, AVCodecContext* dec_ctx)

{

int ret;

AVCodec *dec;

LOG_ERR("TTTTTTTTTTTT\n");

if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) {

av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");

return ret;

}

LOG_ERR("TTTTTTTTTTTT\n");

if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {

av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");

return ret;

}

LOG_ERR("TTTTTTTTTTTT\n");

/* select the audio stream */

ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &dec, 0);

if (ret < 0) {

av_log(NULL, AV_LO

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这些文件是与音频处理相关的代码文件,属于Android系统中的音频相关模块。下面简单介绍一下每个文件的作用: - alsa_config_parameters.c:alsa驱动的配置参数管理。 - alsa_manager.c:alsa驱动的管理,包括打开、关闭、读写等操作。 - aml_audio_delay.c:音频延迟的处理。 - aml_audio_dev2mix_process.c:音频设备到混音器的音频数据处理。 - aml_audio_ease.c:音频的平滑处理。 - aml_audio_hal_avsync.c:音频硬件同步的处理。 - aml_audio_mixer.c、amlAudioMixer.c、sub_mixing_factory.c:音频混音的处理。 - aml_audio_ms12_bypass.c、aml_audio_ms12_render.c、aml_audio_ms12_sync.c:Dolby MS12音频的处理。 - aml_audio_nonms12_render.c:非Dolby MS12音频的处理。 - aml_audio_scaletempo.c:音频的变速变调处理。 - aml_audio_spdifout.c:SPDIF音频输出的处理。 - aml_audio_stream.c:音频流的处理。 - aml_audio_timer.c:音频定时器的处理。 - aml_avsync_tuning.c:音视频同步的调节。 - aml_config_data.c、aml_config_parser.c:音频相关配置数据的处理。 - aml_dtvsync.c:DTV同步的处理。 - aml_hfp.c:音频头戴式设备的处理。 - aml_mmap_audio.c:音频内存映射的处理。 - aml_vad_wakeup.c:语音唤醒的处理。 - audio_aec.c:音频回声消除的处理。 - audio_bt_sco.c:蓝牙SCO音频的处理。 - audio_dtv_utils.c:DTV音频的处理。 - audio_format_parse.c:音频格式解析的处理。 - audio_hdmi_util.c:HDMI音频的处理。 - audio_hw.c、audio_hw_dtv.c、audio_hw_ms12.c、audio_hw_ms12_common.c、audio_hw_ms12_v2.c、audio_hw_profile.c:音频硬件相关的处理。 - audio_hwsync.c、audio_hwsync_wrap.c:音频硬件同步的处理。 - audio_hw_utils.c:音频硬件工具类的处理。 - audio_kara.c:卡拉OK音频的处理。 - audio_mediasync_wrap.c:媒体同步的处理。 - audio_policy.c:音频策略的处理。 - audio_port.c:音频端口的管理。 - audio_post_process.c:音频后处理的处理。 - audio_tsync_wrap.c:时间同步的处理。 - audio_usb_hal.c:USB音频的处理。 - audio_virtual_buf.c:虚拟音频缓冲的处理。 - dolby_lib_api.c:Dolby音频库的API。 - earc_utils.c:EARC音频的处理。 - hw_avsync.c、hw_avsync_callbacks.c:硬件音视频同步的处理。 - karaoke_manager.c:卡拉OK管理的处理。 - spdif_encoder_api.c:SPDIF编码的API。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值