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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 教程一:视频截图(Tutorial 01: Making Screencaps) 首先我们需要了解视频文件的一些基...
    90后的思维阅读 4,859评论 0 3
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,269评论 19 139
  • 图片转视频 为什么想将图片转视频? 是这样的,我打造的任性动图软件,在编辑制作GIF动图方面,已经基本完善。现在想...
    古典小说阅读 1,742评论 1 0
  • 有很长一段时间,我的微博QQ昵称叫做“嫌疑人X”。 这部作品源自东野圭吾的一部作品《嫌疑人X的献身》。故事讲了一个...
    南默mo阅读 368评论 2 0
  • 经常听到有人在微信上面抱怨哎呀昨晚又没有睡好,今天工作效率不高,又得加班了太累了太累了,是该好好休息了,所以...
    七贤庄阅读 714评论 2 3