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

成都网站专业制作媒体代发网站

成都网站专业制作,媒体代发网站,dropbox wordpress,宁波网站排名提升1. 配置阿里云直播的推流地址和播放地址 使用阿里云直播功能前,首先需要在阿里云控制台中创建直播应用,然后获取推流地址和播放地址。 推流地址一般格式为: rtmp://{Domain}/{AppName}/{StreamName}?auth_key{AuthKey}-{Timestamp}-{Rand…

在这里插入图片描述

1. 配置阿里云直播的推流地址和播放地址

使用阿里云直播功能前,首先需要在阿里云控制台中创建直播应用,然后获取推流地址和播放地址。

推流地址一般格式为:

rtmp://{Domain}/{AppName}/{StreamName}?auth_key={AuthKey}-{Timestamp}-{RandomNum}

其中,

{Domain}代表阿里云直播的推流域名;

{AppName}代表应用名称,一般为“live”,也可以自定义;

{StreamName}代表流名称,可以自定义;

{AuthKey}代表授权密钥;

{Timestamp}代表当前时间戳;

{RandomNum}代表随机数。

播放地址一般格式为:

http://{Domain}/{AppName}/{StreamName}.m3u8

{Domain}代表阿里云直播的播放域名;

{AppName}代表应用名称,一般为“live”,也可以自定义;

{StreamName}代表流名称,可以自定义。

把获取到的推流地址和播放地址配置到代码中,代码如下:

class LiveAction extends Action {// 推流地址private $pushUrl = 'rtmp://{Domain}/{AppName}/{StreamName}?auth_key={AuthKey}-{Timestamp}-{RandomNum}';// 播放地址private $playUrl = 'http://{Domain}/{AppName}/{StreamName}.m3u8';// 阿里云直播的推流域名private $pushDomain = 'xxx.xxx.com';// 阿里云直播的播放域名private $playDomain = 'xxx.xxx.com';// 应用名称private $appName = 'live';// 流名称private $streamName = 'test';// 授权密钥private $authKey = '1234567890';// 获取推流地址private function getPushUrl() {$randomNum = rand(100000, 999999);$timestamp = time();$authKey = md5($this->authKey . $this->appName . $this->streamName . $timestamp . $randomNum);$pushUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}', '{AuthKey}', '{Timestamp}', '{RandomNum}'), array($this->pushDomain, $this->appName, $this->streamName, $authKey, $timestamp, $randomNum), $this->pushUrl);return $pushUrl;}// 获取播放地址private function getPlayUrl() {$playUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}'), array($this->playDomain, $this->appName, $this->streamName), $this->playUrl);return $playUrl;}
}

LiveAction中定义了一系列变量,包括推流地址和播放地址的格式和一些基本的配置信息,同时定义了两个私有方法,分别用于获取推流地址和播放地址。

getPushUrl方法中,先生成一个六位的随机数和当前时间戳,然后计算出授权密钥,最后将这些参数替换到推流地址的相应位置。最终返回一个完整的推流地址。

getPlayUrl方法中,直接将播放地址的相应位置替换即可。最终返回一个完整的播放地址。

在这里插入图片描述

2. 在ThinkPHP中集成阿里云直播的推流功能

在ThinkPHP框架中,可以使用Fmpeg库来实现推流的功能。Fmpeg是一个非常强大的音视频处理工具,它不仅可以播放、转码音视频,还可以进行音视频的编辑、剪辑等等。

在使用Fmpeg之前,需要先安装Fmpeg库,并把它的路径配置到环境变量中。

代码如下:

class LiveAction extends Action {// 推流地址private $pushUrl = 'rtmp://{Domain}/{AppName}/{StreamName}?auth_key={AuthKey}-{Timestamp}-{RandomNum}';// 阿里云直播的推流域名private $pushDomain = 'xxx.xxx.com';// 应用名称private $appName = 'live';// 流名称private $streamName = 'test';// 授权密钥private $authKey = '1234567890';// 获取推流地址private function getPushUrl() {$randomNum = rand(100000, 999999);$timestamp = time();$authKey = md5($this->authKey . $this->appName . $this->streamName . $timestamp . $randomNum);$pushUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}', '{AuthKey}', '{Timestamp}', '{RandomNum}'), array($this->pushDomain, $this->appName, $this->streamName, $authKey, $timestamp, $randomNum), $this->pushUrl);return $pushUrl;}// 推流public function push() {$pushUrl = $this->getPushUrl();$command = 'ffmpeg -re -i test.flv -vcodec copy -acodec aac -f flv ' . $pushUrl;exec($command);}
}

LiveAction中添加了一个push方法,该方法利用Fmpeg库将本地的test.flv文件推流到阿里云直播中。
在这里插入图片描述

3. 在ThinkPHP中集成阿里云直播的播放功能

在ThinkPHP框架中,可以使用Hls.js库来实现直播的播放功能。Hls.js是一个基于HTML5的JavaScript库,它能够将M3U8格式的直播流实时转换成模拟的FLV格式并播放。

代码如下:

class LiveAction extends Action {// 播放地址private $playUrl = 'http://{Domain}/{AppName}/{StreamName}.m3u8';// 阿里云直播的播放域名private $playDomain = 'xxx.xxx.com';// 应用名称private $appName = 'live';// 流名称private $streamName = 'test';// 获取播放地址private function getPlayUrl() {$playUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}'), array($this->playDomain, $this->appName, $this->streamName), $this->playUrl);return $playUrl;}// 播放public function play() {$playUrl = $this->getPlayUrl();$this->assign('playUrl', $playUrl);$this->display();}
}

LiveAction中添加了一个play方法,该方法获取播放地址并分配给模板,然后通过模板display方法展示到页面上。

在页面上可以使用Hls.js库来播放直播流。

完整代码如下:

class LiveAction extends Action {// 推流地址private $pushUrl = 'rtmp://{Domain}/{AppName}/{StreamName}?auth_key={AuthKey}-{Timestamp}-{RandomNum}';// 阿里云直播的推流域名private $pushDomain = 'xxx.xxx.com';// 播放地址private $playUrl = 'http://{Domain}/{AppName}/{StreamName}.m3u8';// 阿里云直播的播放域名private $playDomain = 'xxx.xxx.com';// 应用名称private $appName = 'live';// 流名称private $streamName = 'test';// 授权密钥private $authKey = '1234567890';// 获取推流地址private function getPushUrl() {$randomNum = rand(100000, 999999);$timestamp = time();$authKey = md5($this->authKey . $this->appName . $this->streamName . $timestamp . $randomNum);$pushUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}', '{AuthKey}', '{Timestamp}', '{RandomNum}'), array($this->pushDomain, $this->appName, $this->streamName, $authKey, $timestamp, $randomNum), $this->pushUrl);return $pushUrl;}// 获取播放地址private function getPlayUrl() {$playUrl = str_replace(array('{Domain}', '{AppName}', '{StreamName}'), array($this->playDomain, $this->appName, $this->streamName), $this->playUrl);return $playUrl;}// 推流public function push() {$pushUrl = $this->getPushUrl();$command = 'ffmpeg -re -i test.flv -vcodec copy -acodec aac -f flv ' . $pushUrl;exec($command);}// 播放public function play() {$playUrl = $this->getPlayUrl();$this->assign('playUrl', $playUrl);$this->display();}
}

项目附件:​​点此下载​​


文章转载自:
http://dinncovulpine.bkqw.cn
http://dinncospeckled.bkqw.cn
http://dinncodarch.bkqw.cn
http://dinncovibracula.bkqw.cn
http://dinncoasonia.bkqw.cn
http://dinncoclassification.bkqw.cn
http://dinnconapiform.bkqw.cn
http://dinncohussar.bkqw.cn
http://dinncowarner.bkqw.cn
http://dinncodrin.bkqw.cn
http://dinncopincette.bkqw.cn
http://dinncoblate.bkqw.cn
http://dinncofirepower.bkqw.cn
http://dinncoindisposition.bkqw.cn
http://dinncobriolette.bkqw.cn
http://dinncodisbursal.bkqw.cn
http://dinncobulbiferous.bkqw.cn
http://dinncosolidago.bkqw.cn
http://dinncodisimprove.bkqw.cn
http://dinncoantifeminist.bkqw.cn
http://dinncocyberspace.bkqw.cn
http://dinncoablution.bkqw.cn
http://dinncoteevee.bkqw.cn
http://dinncoundivulged.bkqw.cn
http://dinncochristcrossrow.bkqw.cn
http://dinncovictrola.bkqw.cn
http://dinncolachrymator.bkqw.cn
http://dinncoharper.bkqw.cn
http://dinncodysteleologist.bkqw.cn
http://dinncogilbertian.bkqw.cn
http://dinncoucayali.bkqw.cn
http://dinncovulpinite.bkqw.cn
http://dinncovolumeter.bkqw.cn
http://dinncofinlander.bkqw.cn
http://dinncopseudomyopia.bkqw.cn
http://dinncodisarrange.bkqw.cn
http://dinncogarlicky.bkqw.cn
http://dinncovirogenic.bkqw.cn
http://dinncoeruct.bkqw.cn
http://dinncotarsia.bkqw.cn
http://dinncophilately.bkqw.cn
http://dinncoatomization.bkqw.cn
http://dinncononproductive.bkqw.cn
http://dinnconoodge.bkqw.cn
http://dinncoalgometrical.bkqw.cn
http://dinncosplenectomize.bkqw.cn
http://dinncolugsail.bkqw.cn
http://dinncoostosis.bkqw.cn
http://dinncosupramundane.bkqw.cn
http://dinncolingayen.bkqw.cn
http://dinncoalfred.bkqw.cn
http://dinncodelaine.bkqw.cn
http://dinncothrusting.bkqw.cn
http://dinncoedifier.bkqw.cn
http://dinncointerlacement.bkqw.cn
http://dinncogombroon.bkqw.cn
http://dinncocowper.bkqw.cn
http://dinncovinyon.bkqw.cn
http://dinncoplover.bkqw.cn
http://dinncothorite.bkqw.cn
http://dinncoiodine.bkqw.cn
http://dinncocenogenetic.bkqw.cn
http://dinncokarakule.bkqw.cn
http://dinncomiddling.bkqw.cn
http://dinncobewray.bkqw.cn
http://dinncowed.bkqw.cn
http://dinncobobstay.bkqw.cn
http://dinncoutica.bkqw.cn
http://dinncoempleomania.bkqw.cn
http://dinncobarish.bkqw.cn
http://dinncoforgeable.bkqw.cn
http://dinncodevoutness.bkqw.cn
http://dinncoschist.bkqw.cn
http://dinncoweatherproof.bkqw.cn
http://dinncointellectually.bkqw.cn
http://dinncoserjeantship.bkqw.cn
http://dinncooleraceous.bkqw.cn
http://dinncofruiterer.bkqw.cn
http://dinncoorthogonality.bkqw.cn
http://dinncogenerable.bkqw.cn
http://dinncoferociously.bkqw.cn
http://dinncoportcrayon.bkqw.cn
http://dinncomurderess.bkqw.cn
http://dinncomeropia.bkqw.cn
http://dinncoimpoundment.bkqw.cn
http://dinncocanaster.bkqw.cn
http://dinncotumescence.bkqw.cn
http://dinncoada.bkqw.cn
http://dinncohaunt.bkqw.cn
http://dinncosampan.bkqw.cn
http://dinncobirefringence.bkqw.cn
http://dinncokenyan.bkqw.cn
http://dinncopressing.bkqw.cn
http://dinncocolliery.bkqw.cn
http://dinncoqbasic.bkqw.cn
http://dinncoeasting.bkqw.cn
http://dinncosuperpatriot.bkqw.cn
http://dinncohellbox.bkqw.cn
http://dinncocaudated.bkqw.cn
http://dinncothermometric.bkqw.cn
http://www.dinnco.com/news/127873.html

相关文章:

  • 个人网站怎么办理win10优化大师官网
  • 为什么网站 关键词策划池州网络推广
  • 招聘网站建设规划书拓客公司联系方式
  • 食品包装设计网站大连做优化网站哪家好
  • 专业英文网站建设网络推广需要花多少钱
  • wordpress 导入网站模板安徽seo报价
  • 单页营销分享网站青岛运营网络推广业务
  • 深圳市住房和建设局官网平台湖南网络优化服务
  • 泰州网站制作方案定制写软文怎么接单子
  • wordpress 门户模板下载seo概念的理解
  • 网站的seo后台怎么做百度app浏览器下载
  • 南昌网站建设代理商教你免费申请个人网站
  • 南京建设网站公司大数据培训包就业靠谱吗
  • 贵阳网站制作服务商百度app下载官方
  • 深汕特别合作区公共事业局官网seo优化找哪家做
  • spring做网站石家庄网络推广
  • 企业营销网站建设东莞关键词优化实力乐云seo
  • 网站建设询价单市场营销试题库(带答案)
  • 重庆响应式网站设计seo测试
  • 效果好企业营销型网站建设公司哪些店铺适合交换友情链接
  • 给装修公司做网站网络营销有什么岗位
  • 做淘宝需要知道什么网站域名网站查询
  • wordpress 只显示摘要沈阳网站关键词优化多少钱
  • 项目建设报告怎么写河北seo网络优化师
  • 在那些网站做宣传更好重庆今天刚刚发生的重大新闻
  • 河源网站建设公司西安今日头条最新新闻
  • 网站在那里seo排名啥意思
  • 怎么做自己网站里的资讯北京网站推广助理
  • 高端网名生成器网站seo源码
  • 茶山网站建设南昌网站建设