腾讯云直播、生成腾讯推拉流 2022-11-12 02:31 199阅读 0赞 ### 一、背景 ### 最近公司用到推拉流,经过一番比较后决定使用腾讯云。但是腾讯云的文档确实有点一言难尽,去网上搜索一下例子,结果就是把腾讯云的demo粘贴过去,还必须得是会员才能看,坑啊!!所以老周也把自己做的小demo贴出来,帮助感兴趣的童鞋更快的了解腾讯云直播。不多说上干货 ### 二、代码实现 ### public static void main(String[] args) { //时间戳有效期默认到未来的24小时 long nows = (System.currentTimeMillis() + 86400000) /1000; System.out.println(nows); //获得鉴权key String apiKey = "ef7b9ea9ef7b9ea9ef7b9ea9ef7b9ea9"; // 这个是推流网址中生成的apikey String txrtmp = getSafeUrl(apiKey , "test", nows); System.out.println(txrtmp); //生成推流地址 String pushUrl = "push.tencent.com"; // 推流的网址,需要在腾讯云直播进行配置 initPush(pushUrl, "live", "test", txrtmp); //生成播流地址 String pullUrl = "pull.tencent.com"; // 播流的网址,需要在腾讯云直播进行配置 initPull(pullUrl, "live", "test"); } /** * 生成推流地址 * @param domain 推流地址 * @param AppName 应用名称 默认为live * @param StreamName 流标识 同一推流地址中的唯一标识 * @param key 鉴权key */ public static void initPush(String domain, String AppName, String StreamName, String key){ //获取推流地址 System.out.println("===================获取推流地址===================="); String obsPush = "rtmp://"+domain+"/"+AppName+"/"; System.out.println("obs推流地址:"+obsPush); String obsPushName = StreamName+"?"+key; System.out.println("obs推流名称:"+obsPushName); String rtmpPush = obsPush + obsPushName; System.out.println("推流地址:"+rtmpPush); } /** * 生成播流地址 * @param domain 播流地址 * @param AppName 应用名称 默认为live * @param StreamName 流标识 同一播流地址中的唯一标识 */ public static void initPull(String domain, String AppName, String StreamName){ //获取播流地址 System.out.println("====================获取播流地址==================="); //rtmp协议播流地址 String rtmpPull = "rtmp://"+domain+"/"+AppName+"/"+StreamName; System.out.println(rtmpPull); String hlsPull = "http://"+domain+"/"+AppName+"/"+StreamName+".m3u8"; System.out.println(hlsPull); String flvPull = "http://"+domain+"/"+AppName+"/"+StreamName+".flv"; System.out.println(flvPull); } /** *下面是腾讯云直播自己的demo,老周研究发现主要用户生成鉴权key */ private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; /* * KEY+ streamName + txTime */ private static String getSafeUrl(String key, String streamName, long txTime) { String input = new StringBuilder(). append(key). append(streamName). append(Long.toHexString(txTime).toUpperCase()).toString(); String txSecret = null; try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); txSecret = byteArrayToHexString( messageDigest.digest(input.getBytes("UTF-8"))); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return txSecret == null ? "" : new StringBuilder(). append("txSecret="). append(txSecret). append("&"). append("txTime="). append(Long.toHexString(txTime).toUpperCase()). toString(); } private static String byteArrayToHexString(byte[] data) { char[] out = new char[data.length << 1]; for (int i = 0, j = 0; i < data.length; i++) { out[j++] = DIGITS_LOWER[(0xF0 & data[i]) >>> 4]; out[j++] = DIGITS_LOWER[0x0F & data[i]]; } return new String(out); }
相关 腾讯云移动推送TPNS怎么样? 腾讯云移动推送TPNS怎么样?移动推送 TPNS(Tencent Push Notification Service) 为APP开发者及运营人员提供接入简单、推送稳定、快速、高 墨蓝/ 2022年12月24日 12:53/ 0 赞/ 55 阅读
相关 腾讯云直播、生成腾讯推拉流 一、背景 最近公司用到推拉流,经过一番比较后决定使用腾讯云。但是腾讯云的文档确实有点一言难尽,去网上搜索一下例子,结果就是把腾讯云的demo粘贴过去,还必须得是会员才能看 淡淡的烟草味﹌/ 2022年11月12日 02:31/ 0 赞/ 200 阅读
相关 走近腾讯 走进腾讯 走近腾讯 走进腾讯 -――谨以此文献给所有找工的战友 (一位同乡师兄的经验) 整理:Acharlix 前言 本人是03计A一学生,一个普通的潮州男生。我热爱我的专 雨点打透心脏的1/2处/ 2022年09月19日 12:19/ 0 赞/ 282 阅读
相关 腾讯云直播 延迟排查 正常情况下,使用 RTMP 协议推流并通过 FLV 协议播放,延迟在2秒 - 3秒左右,如果太长一般是有问题的。如果您发现直播延迟时间特别长,可以按照如下思路来排查。 St 蔚落/ 2022年09月03日 14:22/ 0 赞/ 141 阅读
相关 腾讯云配置tomcat 在服务器上部署tomcat 1.安装tomcat 去官网下载好,解压安装,网上有很多教程,这里就不多写了 2.tomcat默认是启用8 以你之姓@/ 2022年05月29日 12:53/ 0 赞/ 236 阅读
相关 腾讯云开启端口 腾讯云服务器如何开启端口: 1.首先进入云主机-控制台 ![20180324105258926][] 2.点击配置安全组 今天药忘吃喽~/ 2022年05月29日 12:47/ 0 赞/ 221 阅读
相关 Android腾讯云小直播直播页面报错:拉取直播推流地址失败,Error:-1 业务服务器如何看log 我们主要关心业务服务器的2种log: nginx的log:如果遇到http返回的错误码(如404,500等),请查看nginx的error 古城微笑少年丶/ 2022年05月10日 06:34/ 0 赞/ 158 阅读
相关 腾讯云服务器好不好?腾讯云服务器测评 腾讯云服务器,简称 CVM 是通过高性能服务器虚拟化的云服务器、拥有专业团队打造资源隔离、数据安全、密码安全、安全加固等多达 20 种安全防护手段。其实就是和阿里云(ECS)差 た 入场券/ 2022年02月02日 05:27/ 0 赞/ 528 阅读
相关 腾讯云服务器 ![腾讯云服务器][1240] 腾讯云服务器 点击添加纪录,红色框框里面填写自己的公网IP即可。 ![image][] ![image.png][] 阿里云上搭建ph 待我称王封你为后i/ 2021年09月19日 01:40/ 0 赞/ 462 阅读
相关 腾讯云通讯IM 后台php static private $private_key_string = <<<'EOT' -----BEGIN PRIVATE KEY----- 一时失言乱红尘/ 2021年09月18日 08:26/ 0 赞/ 511 阅读
还没有评论,来说两句吧...