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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?