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,772評論 0 3
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,923評論 18 139
  • 圖片轉視頻 為什么想將圖片轉視頻? 是這樣的,我打造的任性動圖軟件,在編輯制作GIF動圖方面,已經基本完善。現在想...
    古典小說閱讀 1,637評論 1 0
  • 有很長一段時間,我的微博QQ昵稱叫做“嫌疑人X”。 這部作品源自東野圭吾的一部作品《嫌疑人X的獻身》。故事講了一個...
    南默mo閱讀 358評論 2 0
  • 經常聽到有人在微信上面抱怨哎呀昨晚又沒有睡好,今天工作效率不高,又得加班了太累了太累了,是該好好休息了,所以...
    七賢莊閱讀 708評論 2 3