您当前的位置: 首页 > 

令狐掌门

暂无认证

  • 1浏览

    0关注

    513博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ffmpeg rtmp推流代码示例

令狐掌门 发布时间:2020-01-31 21:22:11 ,浏览量:1

     rtmp推流,得有rtmp服务器,可以参考这篇博客搭建rtmp服务器  ===》》》ubuntu搭建rtmp服务器,如果自己有rtmp服务器,可以不用看。

     rtmp推流需要用flv格式, 本篇博客demo是本地flv文件rtmp推流. 主要流程如下:

     代码如下:

#include 

extern "C"
{
#include "libavformat/avformat.h"
#include "libavutil/time.h"
}

using namespace std;

#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"avcodec.lib")

int ff_Error(int errNum)
{
	char buf[1024] = { 0 };
	av_strerror(errNum, buf, sizeof(buf));
	cout time_base;
		pkt.pts = av_rescale_q_rnd(pkt.pts, itime, otime, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_NEAR_INF));
		pkt.dts = av_rescale_q_rnd(pkt.pts, itime, otime, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_NEAR_INF));
		pkt.duration = av_rescale_q_rnd(pkt.duration, itime, otime, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_NEAR_INF));
		pkt.pos = -1;

		//视频帧推送速度
		if (ictx->streams[pkt.stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
		{
			AVRational tb = ictx->streams[pkt.stream_index]->time_base;
			//已经过去的时间
			long long now = av_gettime() - startTime;
			long long dts = 0;
			dts = pkt.dts * (1000 * 1000 * r2d(tb));

			if (dts > now)
				av_usleep(dts - now);
		}
        
        //推送帧数据
		re = av_interleaved_write_frame(octx, &pkt);
		if (re            
关注
打赏
1652240117
查看更多评论
0.0372s