先從main函數開始:
int main(int argc, const char * argv[])
{
av_log_set_level(AV_LOG_VERBOSE);
int err;
av_register_all();
avfilter_register_all();
char* audio1Path = "audio10.wav";
if (open_input_file(audio1Path, &input_format_context_0, &input_codec_context_0) < 0){
av_log(NULL, AV_LOG_ERROR, "Error while opening file 1\n");
exit(1);
}
av_dump_format(input_format_context_0, 0, audio1Path, 0);
char* audio2Path = "audio20.wav";
if (open_input_file(audio2Path, &input_format_context_1, &input_codec_context_1) < 0){
av_log(NULL, AV_LOG_ERROR, "Error while opening file 2\n");
exit(1);
}
av_dump_format(input_format_context_1, 0, audio2Path, 0);
/* Set up the filtergraph. */
err = init_filter_graph(&graph, &src0, &src1, &sink);
printf("Init err = %d\n", err);
char* outputFile = "output.wav";
remove(outputFile);
av_log(NULL, AV_LOG_INFO, "Output file : %s\n", outputFile);
err = open_output_file(outputFile, input_codec_context_0, &output_format_context, &output_codec_context);
printf("open output file err : %d\n", err);
av_dump_format(output_format_context, 0, outputFile, 1);
if(write_output_file_header(output_format_context) < 0){
av_log(NULL, AV_LOG_ERROR, "Error while writing header outputfile\n");
exit(1);
}
process_all();
if(write_output_file_trailer(output_format_context) < 0){
av_log(NULL, AV_LOG_ERROR, "Error while writing header outputfile\n");
exit(1);
}
printf("FINISHED\n");
return 0;
}
函數功能:
av_register_all();
初始化libavformat并注冊所有混合器,demuxers和協議。 如果不調用此函數,則可以選擇你具體要支持的格式。
/**
* Initialize libavformat and register all the muxers, demuxers and
* protocols. If you do not call this function, then you can select
* exactly which formats you want to support.
*
* @see av_register_input_format()
* @see av_register_output_format()
*/
void av_register_all(void);
avfilter_register_all();
初始化過濾器系統。 注冊所有內置的過濾器。
/** Initialize the filter system. Register all builtin filters. */
void avfilter_register_all(void);
open_input_file
打開輸入文件和所需的解碼器
/** Open an input file and the required decoder. */
static int open_input_file(const char *filename,
AVFormatContext **input_format_context,
AVCodecContext **input_codec_context)
av_dump_format(input_format_context_0, 0, audio1Path, 0);
av_dump_format:
/**
* Print detailed information about the input or output format, such as
* duration, bitrate, streams, container, programs, metadata, side data,
* codec and time base.
*打印有關輸入或輸出格式的詳細信息,例如持續時間,比特率,流,容器,程序,元數據,站點數據,編解碼器和時基。
* @param ic the context to analyze
* @param index index of the stream to dump information about//存儲信息的流的索引
* @param url the URL to print, such as source or destination file//要打印的URL,例如源文件或目標文件
* @param is_output Select whether the specified context is an input(0) or output(1)//選擇指定的上下文是輸入(0)還是輸出(1)
*/
void av_dump_format(AVFormatContext *ic,
int index,
const char *url,
int is_output);