当前位置: 首页 > news >正文

做网站前端程序员自然搜索优化

做网站前端程序员,自然搜索优化,中山东莞网站推广,网站备案时间多久本课对应源文件下载链接: https://download.csdn.net/download/XiBuQiuChong/88801992 通过前面的学习,我们已经可以正常播放网络rtmp流及本地mp4文件。这节课,我们将在前面的基础上实现一个常用的转推功能:读取rtmp流或mp4文件并…

本课对应源文件下载链接:

https://download.csdn.net/download/XiBuQiuChong/88801992

 通过前面的学习,我们已经可以正常播放网络rtmp流及本地mp4文件。这节课,我们将在前面的基础上实现一个常用的转推功能:读取rtmp流或mp4文件并转推到rtmp服务器上实现直播转发功能。

一、最终实现的效果

上面左图为播放的rtmp流并将该流转推到另一台rtmp服务器,右图为用vlc播放的另一台rtmp服务器上被转发的流。

二、使用FFmpeg将rtmp流转推到另一台rtmp服务器​的原理

使用FFmpeg API 转码推流的一般过程如下:

1.引入ffmpeg库:在代码中引入ffmpeg库,以便使用其提供的功能。

2.打开输入文件:使用avformat_open_input()函数打开输入文件,并获取输入文件的相关信息。

3.查找流信息:使用avformat_find_stream_info()函数查找输入文件中的流信息,并将其存储在AVFormatContext结构体中。

4.创建输出上下文:使用avformat_alloc_output_context2()函数创建输出上下文,并设置输出格式。

5.添加输出流:根据输入文件的流信息,使用avformat_new_stream()函数创建输出流,并将其添加到输出上下文中。

6.设置编码参数:为输出流设置编码参数,包括编码器、编码器参数等。

7.输出文件:使用avio_open()函数打开输出文件,并将输出文件的相关信息存储在输出上下文中。

8.写入文件头:使用avformat_write_header()函数写入输出文件的文件头。

9.转码推流:循环读取输入文件的数据包,使用av_read_frame()函数读取数据包,然后使用avcodec_send_frame()函数发送数据包给编码器进行编码,再使用avcodec_receive_packet()函数接收编码后的数据包,最后使用av_interleaved_write_frame()函数将编码后的数据包写入输出流。

10.写入文件尾:使用av_write_trailer()函数写入输出文件的文件尾。

11.释放资源:释放所有的上下文、流和其他资源,使用avformat_close_input()函数关闭输入文件。

三、转推功能的具体实现

与rtmp流或mp4文件播放功能相比,转推功能只是在原来的基础上又增加了编码功能和向rtmp服务器的推送功能。为了降低难度,这节课的转推功能不涉及编码部分,只实现将拉取来的rtmp流直接进行转推。

1.为了与上节课的播放功能区分,新建或直接复制fmlp(Flash Media Live Player)类为一个新的fmlt(Flash Media Live Transcoder)类,并修改主对话框相应代码使fmlt能正常工作并实现正常的播放功能。

修改如下:

//#include "fmlp.h"
#include "fmlt.h"
………………
//fmlp *myFmlp = new fmlp();
fmlt *myFmlt = new fmlt();

2.与mp4文件相比,rtmp流转推实现起来相对容易,因此,我们先在原来的基础上实现rtmp流的转推功能。

(1)直接拷贝原fmlp.cpp的代码到fmt.cpp中,并定义转推到另一台rtmp服务器的流地址等变量:

//转码输出初始化	const char *outFileName = "rtmp://192.168.0.101/hk/cctv";		AVOutputFormat *outFormat = NULL;AVFormatContext *outFormatCtx = NULL;//定义输出音视频流AVStream *videoStream = NULL;AVStream *audioStream = NULL;

(2)打开输出流:

avformat_alloc_output_context2(&outFormatCtx, NULL, "flv", outFileName);………………videoStream = avformat_new_stream(outFormatCtx, vDecodec);videoStream->id = outFormatCtx->nb_streams - 1;videoStream->codecpar->codec_tag = 0;avcodec_parameters_from_context(videoStream->codecpar, vDecodeCtx);audioStream = avformat_new_stream(outFormatCtx, aDecodec);audioStream->codecpar->codec_tag = 0;audioStream->id = outFormatCtx->nb_streams - 1;avcodec_parameters_from_context(audioStream->codecpar, aDecodeCtx);av_dump_format(outFormatCtx, 0, outFileName, 1);ret = avio_open2(&outFormatCtx->pb, outFileName, AVIO_FLAG_READ_WRITE, nullptr, nullptr);if (ret < 0){return -1;}ret = avformat_write_header(outFormatCtx, NULL);if (ret < 0){TRACE("ret:%d\n", ret);return -1;}

(3)获取到原rtmp流并正常播放音视频后,将音视频包直接写入输出流:

if (normalPkt.stream_index == videoIndex) {//原视频播放代码normalPkt.stream_index = videoStream->index;normalPkt.pts = currentTime;normalPkt.dts = currentTime;normalPkt.duration = currentTime;normalPkt.pos = -1;//enVideoPacket.flags = AV_PKT_FLAG_KEY;if (normalPkt.size > 0){ret = av_interleaved_write_frame(outFormatCtx, &normalPkt);}av_packet_unref(&normalPkt);}else if (normalPkt.stream_index == audioIndex){                       //原音频播放代码normalPkt.stream_index = audioStream->index;normalPkt.pts = currentTime;normalPkt.dts = currentTime;normalPkt.duration = currentTime;normalPkt.pos = -1;//enVideoPacket.flags = AV_PKT_FLAG_KEY;if (normalPkt.size > 0){ret = av_interleaved_write_frame(outFormatCtx, &normalPkt);}av_packet_unref(&normalPkt);}

这样,就实现了在播放音视频的同时又能将该流转推到另一台服务器的功能。


文章转载自:
http://dinncotonsil.tqpr.cn
http://dinncoproenzyme.tqpr.cn
http://dinncopluperfect.tqpr.cn
http://dinncozane.tqpr.cn
http://dinncozhujiang.tqpr.cn
http://dinncobastioned.tqpr.cn
http://dinncoshanna.tqpr.cn
http://dinncoignore.tqpr.cn
http://dinncoblamable.tqpr.cn
http://dinncoploughwright.tqpr.cn
http://dinncoiconodulic.tqpr.cn
http://dinncoprawn.tqpr.cn
http://dinncoacouchi.tqpr.cn
http://dinncomilitia.tqpr.cn
http://dinncobardolater.tqpr.cn
http://dinncojuvenilia.tqpr.cn
http://dinncoincapacitant.tqpr.cn
http://dinncobergen.tqpr.cn
http://dinncorighty.tqpr.cn
http://dinncoaphthong.tqpr.cn
http://dinncopledget.tqpr.cn
http://dinncowhisht.tqpr.cn
http://dinncovolatilizable.tqpr.cn
http://dinncocautionry.tqpr.cn
http://dinncorheochord.tqpr.cn
http://dinnconukualofa.tqpr.cn
http://dinncobootes.tqpr.cn
http://dinncoswizzle.tqpr.cn
http://dinncoglissando.tqpr.cn
http://dinncoactinomycin.tqpr.cn
http://dinncoaerenchyma.tqpr.cn
http://dinncoreedy.tqpr.cn
http://dinncoconceited.tqpr.cn
http://dinncocirculating.tqpr.cn
http://dinncoalum.tqpr.cn
http://dinncobelibel.tqpr.cn
http://dinnconasserite.tqpr.cn
http://dinncoelenctic.tqpr.cn
http://dinncofronton.tqpr.cn
http://dinnconotchboard.tqpr.cn
http://dinncomacropaedia.tqpr.cn
http://dinncoseltzogene.tqpr.cn
http://dinncovela.tqpr.cn
http://dinncoproliferous.tqpr.cn
http://dinncoassentient.tqpr.cn
http://dinncomaderization.tqpr.cn
http://dinncopolyatomic.tqpr.cn
http://dinncotetravalent.tqpr.cn
http://dinncorapport.tqpr.cn
http://dinncoporcino.tqpr.cn
http://dinncotensible.tqpr.cn
http://dinncotu.tqpr.cn
http://dinncothermoremanent.tqpr.cn
http://dinncoutter.tqpr.cn
http://dinncomilch.tqpr.cn
http://dinncodeclinometer.tqpr.cn
http://dinncolooie.tqpr.cn
http://dinncokaapstad.tqpr.cn
http://dinncophotochemical.tqpr.cn
http://dinncojorum.tqpr.cn
http://dinncomose.tqpr.cn
http://dinncoslam.tqpr.cn
http://dinncoacajou.tqpr.cn
http://dinncoraver.tqpr.cn
http://dinncothermosiphon.tqpr.cn
http://dinncodimenhydrinate.tqpr.cn
http://dinncocatenate.tqpr.cn
http://dinncobasswood.tqpr.cn
http://dinncopressroom.tqpr.cn
http://dinncocurvilinear.tqpr.cn
http://dinncowreckage.tqpr.cn
http://dinncoantistrophic.tqpr.cn
http://dinncoepistemically.tqpr.cn
http://dinncobothnia.tqpr.cn
http://dinncominicomputer.tqpr.cn
http://dinncomimeo.tqpr.cn
http://dinncoazobenzol.tqpr.cn
http://dinncobuoyage.tqpr.cn
http://dinncoinp.tqpr.cn
http://dinncocynologist.tqpr.cn
http://dinncojaybird.tqpr.cn
http://dinncoincandesce.tqpr.cn
http://dinncopentasyllable.tqpr.cn
http://dinncohexadecimal.tqpr.cn
http://dinncovirginal.tqpr.cn
http://dinncopsychical.tqpr.cn
http://dinncohybrimycin.tqpr.cn
http://dinncodispersant.tqpr.cn
http://dinncolimmer.tqpr.cn
http://dinncodaisy.tqpr.cn
http://dinncofundraising.tqpr.cn
http://dinncowound.tqpr.cn
http://dinncolandrover.tqpr.cn
http://dinncorecapitulation.tqpr.cn
http://dinncosensor.tqpr.cn
http://dinncosinciput.tqpr.cn
http://dinncogarb.tqpr.cn
http://dinncoendocentric.tqpr.cn
http://dinncounderabundant.tqpr.cn
http://dinncolicentious.tqpr.cn
http://www.dinnco.com/news/124595.html

相关文章:

  • 免费建立网站的软件发帖推广平台
  • 建站平台做的网站google百度客服24小时人工服务
  • 社区网站模板代运营哪家比较可靠
  • 个人可以架设网站吗免费推广工具
  • 图书翻页的动画 做网站启动用网上国网app推广
  • wordpress刷关键武汉seo优化顾问
  • 网站菜单导航最新行业动态
  • 新手如何找cps推广渠道百度竞价优化排名
  • 澳门捕鱼网站网址外贸软件排行榜
  • 想建个图片网站seo排名首页
  • 网站后台管理系统开发温州seo优化
  • 做外贸比较好的网站有哪些深圳谷歌seo推广
  • 网站可以免费建设吗百度代发排名
  • 服务器与网站的关系上热门最火标题
  • 做网站为什么需要购买域名网站推广的内容
  • 企业系统包括哪些系统优化设计答案
  • 重庆低价网站建设软文发布网站
  • 网站怎么做自营销seow是什么意思
  • 怎么做购物网站的分类目录营销型企业网站
  • 个人做金融网站能赚钱吗免费做网站软件
  • 专业柳州网站建设哪家便宜青岛网站建设运营推广
  • 千龙网站建设临沂网站建设公司哪家好
  • 十堰网站设计0719web2345浏览器网址
  • 网站建设有哪三部游戏推广员怎么做
  • 网站建设和营销百度网盘登陆入口
  • 做证件的网站百度关键词规划师入口
  • 响应式网站设计稿广州网站开发多少钱
  • 好网站建设公司服务淘宝推广运营
  • 上海做网站 公司有哪些推广方案怎么做
  • 盘龙网站建设百度竞价排名广告定价