资源简介
一个简单的混音demo
代码片段和文件信息
/*
*一个简单的混音demo,把文件a和文件b的音频混为一个音频流输出并存为文件,只处理每个文件的第一个音频流
*源代码是网友Larry_Liang(1085803139)写的,我帮其调试通过
*MK(821486004@qq.com)
*/
extern “C“
{
#include “libavcodec/avcodec.h“
#include “libavformat/avformat.h“
#include “libavdevice/avdevice.h“
#include “libavfilter/avfilter.h“
#include “libavfilter/avfiltergraph.h“
#include “libavfilter/buffersink.h“
#include “libavfilter/buffersrc.h“
#include “libavutil/audio_fifo.h“
#include “libavutil/avutil.h“
#include “libavutil/fifo.h“
}
#pragma comment(lib “avcodec.lib“)
#pragma comment(lib “avformat.lib“)
#pragma comment(lib “avutil.lib“)
#pragma comment(lib “avdevice.lib“)
#pragma comment(lib “avfilter.lib“)
//#pragma comment(lib “avfilter.lib“)
//#pragma comment(lib “postproc.lib“)
//#pragma comment(lib “swresample.lib“)
#pragma comment(lib “swscale.lib“)
#include
#include
#include
enum CaptureState
{
PREPARED
RUNNING
STOPPED
FINISHED
};
typedef struct BufferSourceContext {
const AVClass *bscclass;
AVFifoBuffer *fifo;
AVRational time_base; ///< time_base to set in the output link
AVRational frame_rate; ///< frame_rate to set in the output link
unsigned nb_failed_requests;
unsigned warning_limit;
/* video only */
int w h;
enum AVPixelFormat pix_fmt;
AVRational pixel_aspect;
char *sws_param;
AVBufferRef *hw_frames_ctx;
/* audio only */
int sample_rate;
enum AVSampleFormat sample_fmt;
int channels;
uint64_t channel_layout;
char *channel_layout_str;
int got_format_from_params;
int eof;
} BufferSourceContext;
AVFormatContext* _fmt_ctx_spk = NULL;
AVFormatContext* _fmt_ctx_mic = NULL;
AVFormatContext* _fmt_ctx_out = NULL;
int _index_spk = -1;
int _index_mic = -1;
int _index_a_out = -1;
AVFilterGraph* _filter_graph = NULL;
AVFilterContext* _filter_ctx_src_spk = NULL;
AVFilterContext* _filter_ctx_src_mic = NULL;
AVFilterContext* _filter_ctx_sink = NULL;
CaptureState _state = CaptureState::PREPARED;
CRITICAL_SECTION _section_spk;
CRITICAL_SECTION _section_mic;
AVAudioFifo* _fifo_spk = NULL;
AVAudioFifo* _fifo_mic = NULL;
void InitRecorder()
{
av_register_all();
avdevice_register_all();
avfilter_register_all();
}
int OpenSpeakerInput(char* inputForamt char* url)
{
AVInputFormat* ifmt = av_find_input_format(inputForamt);
AVDictionary* opt1 = NULL;
av_dict_set(&opt1 “rtbufsize“ “10M“ 0);
int ret = 0;
ret = avformat_open_input(&_fmt_ctx_spk url ifmt &opt1);
if (ret < 0)
{
printf(“Speaker: failed to call avformat_open_input\n“);
return -1;
}
ret = avformat_find_stream_info(_fmt_ctx_spk NULL);
if (ret < 0)
{
printf(“Speaker: failed to call avformat_find_stream_info\n“);
return -1;
}
for (int i = 0; i < _fmt_ctx_spk->nb_streams; i++)
{
if (_fmt_ctx_spk->streams[i]->codec->codec_type =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 44032 2016-11-08 10:54 TestMixAudio\Debug\TestMixAudio.exe
文件 468660 2016-11-08 10:54 TestMixAudio\Debug\TestMixAudio.ilk
文件 683008 2016-11-08 10:54 TestMixAudio\Debug\TestMixAudio.pdb
文件 18936320 2014-05-06 10:08 TestMixAudio\TestMixAudio\avcodec-55.dll
文件 1340928 2014-05-06 10:08 TestMixAudio\TestMixAudio\avdevice-55.dll
文件 2034688 2014-05-06 10:08 TestMixAudio\TestMixAudio\avfilter-4.dll
文件 5342720 2014-05-06 10:08 TestMixAudio\TestMixAudio\avformat-55.dll
文件 418304 2014-05-06 10:08 TestMixAudio\TestMixAudio\avutil-52.dll
文件 682 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\cl.command.1.tlog
文件 21078 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\CL.read.1.tlog
文件 384 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\CL.write.1.tlog
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 2 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 1584 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 3888 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 866 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\li
文件 430 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\mt.command.1.tlog
文件 470 2016-11-08 10:54 TestMixAudio\TestMixAudio\Debug\mt.read.1.tlog
............此处省略140个文件信息
评论
共有 条评论