ffmpeg-amix.c学习笔记

先从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);

你可能感兴趣的:(ffmpeg-amix.c学习笔记)