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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,830评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,992评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,875评论 0 331
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,837评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,734评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,091评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,550评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,217评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,368评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,298评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,350评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,027评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,623评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,706评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,940评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,349评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,936评论 2 341

推荐阅读更多精彩内容

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