ffmpeg api接口实现rtmp推流的两种方式

FFmpeg 版本

version 4.0.2

搭建Rtmp服务

具体可以参考一下其它文章,本文主要讲的是如何使用FFmpeg api接口实现推流功能

推流flv文件

    av_register_all();

    AVFormatContext *ictx = NULL;

    //打开文件,解封文件头
    int re = avformat_open_input(&ictx, inUrl, 0, 0);
    if (re != 0)
    {
        return ff_Error(re);
    }

    cout << "open file " << inUrl << " success..." << endl;

    //获取音频视频流信息
    re = avformat_find_stream_info(ictx, 0);
    if (re != 0)
    {
        return ff_Error(re);
    }

    cout << "打印输入文件信息" << endl;
    av_dump_format(ictx, 0, inUrl, 0);

    //创建输出流上下文
    AVFormatContext *octx = NULL;
    re = avformat_alloc_output_context2(&octx, 0, "flv", outUrl);
    if (!octx)
    {
        return ff_Error(re);
    }

    cout << "输出上下文创建成功" << endl;

    //配置输出流
    //遍历输入的AVStream
    for (int i = 0; i < ictx->nb_streams; i++)
    {
        //创建输出流
        AVStream *out = avformat_new_stream(octx, ictx->streams[i]->codec->codec);
        if (!out)
        {
            return ff_Error(0);
        }
        //复制配置信息
        AVCodecParameters *codecpar = ictx->streams[i]->codecpar;
        re = avcodec_parameters_copy(out->codecpar, codecpar);

        out->codec->codec_tag = 0;
    }

    cout << "打印输出流信息" << endl;
    av_dump_format(octx, 0, outUrl, 1);

    //rtmp推流
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值