致敬雷霄骅师兄,感谢他的引领入门,以下都是他的笔记的个人补充。
本文,记录在根据雷霄骅的RTMP推流demo源码,学习FFmpeg的执行流程。
记录如下:
1. 首先是记录demo并做一点修改,同时推送audio和video至rtmp-server。
2.对此代码的关键函数执行流程进行分析,或者说是关键结构体的赋值与复制的执行过程。
3.rtmp推流的简单流程图
rtmp-demo代码
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libavutil/mathematics.h>
#include <libavutil/time.h>
#include <libavcodec/avcodec.h>
int main(int argc, char* argv[])
{
AVOutputFormat *ofmt = NULL;
//输入对应一个AVFormatContext,输出对应一个AVFormatContext
//(Input AVFormatContext and Output AVFormatContext)
AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
AVPacket pkt,pkt1;
const char *in_filename, *out_filename;
int ret, i;
int videoindex=-1;
int audioindex=-1;
int frame_index=0;
int64_t start_time=0;
in_filename = "test.h264";//输入URL(Input file URL)
out_filename = "rtmp://192.168.1.190/live/livestream";//输出 URL(Output URL)[RTMP]
av_register_all();
//Network
avformat_network_init();
//输入(Input)
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
printf( "Could not open input file.");
goto end;
}
if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
printf( "Failed to retrieve input stream information");
goto end;
}
for(i=0; i<ifmt_ctx->