FFmpeg-rtmp推流例子(着重解析函数,剖析FFmpeg流程)

致敬雷霄骅师兄,感谢他的引领入门,以下都是他的笔记的个人补充。

本文,记录在根据雷霄骅的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->
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值