在对接腾讯的trtc中,使用官方的直播自动截图功能出现了以下问题

  1. 因为自动截图和鉴黄是针对 直播 模块进行的
  2. ``
  3. 腾讯的trtc实时音视频模块不能直接进行使用

提交腾讯云工单想咨询一下这个功能,被工作人员拽过来一个链接`

  1. TRTC 旁路流实现截图鉴黄
  2. https://www.rtcgeek.com/?/article/69

安装腾讯的扩展 composer.json

  1. "tencentcloud/tencentcloud-sdk-php": "v3.0.595",

重写两个类

在项目app下创建 /Plugins/Live/Models/

创建文件: CreateSnapshotTemplateRequest.php

  1. php
  2. ``
  3. namespace TencentCloud\Live\V20180801\Models;
  4. use TencentCloud\Common\AbstractModel;
  5. /**
  6. * CreateLiveSnapshotTemplate请求参数结构体
  7. *
  8. * @method string getTemplateName() 获取模板名称。
  9. 长度上限:255字节。
  10. 仅支持中文、英文、数字、_、-。
  11. * @method void setTemplateName(string $TemplateName) 设置模板名称。
  12. 长度上限:255字节。
  13. 仅支持中文、英文、数字、_、-。
  14. * @method integer getCosAppId() 获取Cos 应用 ID。
  15. * @method void setCosAppId(integer $CosAppId) 设置Cos 应用 ID。
  16. * @method string getCosBucket() 获取Cos Bucket名称。
  17. 注:CosBucket参数值不能包含-[appid] 部分。
  18. * @method void setCosBucket(string $CosBucket) 设置Cos Bucket名称。
  19. 注:CosBucket参数值不能包含-[appid] 部分。
  20. * @method string getCosRegion() 获取Cos地区。
  21. * @method void setCosRegion(string $CosRegion) 设置Cos地区。
  22. * @method string getDescription() 获取描述信息。
  23. 长度上限:1024字节。
  24. 仅支持中文、英文、数字、_、-。
  25. * @method void setDescription(string $Description) 设置描述信息。
  26. 长度上限:1024字节。
  27. 仅支持中文、英文、数字、_、-。
  28. * @method integer getSnapshotInterval() 获取截图间隔,单位s,默认10s。
  29. 范围: 2s ~ 300s。
  30. * @method void setSnapshotInterval(integer $SnapshotInterval) 设置截图间隔,单位s,默认10s。
  31. 范围: 2s ~ 300s。
  32. * @method integer getWidth() 获取截图宽度。默认:0(原始宽)。
  33. 范围:0-3000 。
  34. * @method void setWidth(integer $Width) 设置截图宽度。默认:0(原始宽)。
  35. 范围:0-3000 。
  36. * @method integer getHeight() 获取截图高度。默认:0(原始高)。
  37. 范围:0-2000 。
  38. * @method void setHeight(integer $Height) 设置截图高度。默认:0(原始高)。
  39. 范围:0-2000 。
  40. * @method integer getPornFlag() 获取是否开启鉴黄,0:不开启,1:开启。默认:0。
  41. * @method void setPornFlag(integer $PornFlag) 设置是否开启鉴黄,0:不开启,1:开启。默认:0。
  42. * @method string getCosPrefix() 获取Cos Bucket文件夹前缀。
  43. 如不传,实际按默认值
  44. /{Year}-{Month}-{Day}
  45. 生效
  46. * @method void setCosPrefix(string $CosPrefix) 设置Cos Bucket文件夹前缀。
  47. 如不传,实际按默认值
  48. /{Year}-{Month}-{Day}
  49. 生效
  50. * @method string getCosFileName() 获取Cos 文件名称。
  51. 如不传,实际按默认值
  52. {StreamID}-screenshot-{Hour}-{Minute}-{Second}-{Width}x{Height}{Ext}
  53. 生效
  54. * @method void setCosFileName(string $CosFileName) 设置Cos 文件名称。
  55. 如不传,实际按默认值
  56. {StreamID}-screenshot-{Hour}-{Minute}-{Second}-{Width}x{Height}{Ext}
  57. 生效
  58. */
  59. class CreateSnapshotTemplateRequest extends AbstractModel
  60. {
  61. /**
  62. * @var string 模板名称。
  63. 长度上限:255字节。
  64. 仅支持中文、英文、数字、_、-。
  65. */
  66. public $TemplateName;
  67. /**
  68. * @var integer Cos 应用 ID。
  69. */
  70. public $CosAppId;
  71. /**
  72. * @var string Cos Bucket名称。
  73. 注:CosBucket参数值不能包含-[appid] 部分。
  74. */
  75. public $CosBucket;
  76. /**
  77. * @var string Cos地区。
  78. */
  79. public $CosRegion;
  80. /**
  81. * @var string 描述信息。
  82. 长度上限:1024字节。
  83. 仅支持中文、英文、数字、_、-。
  84. */
  85. public $Description;
  86. /**
  87. * @var string 创建TRTC截图模版专用参数。
  88. */
  89. public $ProductName;
  90. /**
  91. * @var integer 截图间隔,单位s,默认10s。
  92. 范围: 2s ~ 300s。
  93. */
  94. public $SnapshotInterval;
  95. /**
  96. * @var integer 截图宽度。默认:0(原始宽)。
  97. 范围:0-3000 。
  98. */
  99. public $Width;
  100. /**
  101. * @var integer 截图高度。默认:0(原始高)。
  102. 范围:0-2000 。
  103. */
  104. public $Height;
  105. /**
  106. * @var integer 是否开启鉴黄,0:不开启,1:开启。默认:0。
  107. */
  108. public $PornFlag;
  109. /**
  110. * @var string Cos Bucket文件夹前缀。
  111. 如不传,实际按默认值
  112. /{Year}-{Month}-{Day}
  113. 生效
  114. */
  115. public $CosPrefix;
  116. /**
  117. * @var string Cos 文件名称。
  118. 如不传,实际按默认值
  119. {StreamID}-screenshot-{Hour}-{Minute}-{Second}-{Width}x{Height}{Ext}
  120. 生效
  121. */
  122. public $CosFileName;
  123. /**
  124. * @param string $TemplateName 模板名称。
  125. 长度上限:255字节。
  126. 仅支持中文、英文、数字、_、-。
  127. * @param integer $CosAppId Cos 应用 ID。
  128. * @param string $CosBucket Cos Bucket名称。
  129. 注:CosBucket参数值不能包含-[appid] 部分。
  130. * @param string $CosRegion Cos地区。
  131. * @param string $Description 描述信息。
  132. * @param string $ProductName 创建TRTC截图模版专用参数。
  133. 长度上限:1024字节。
  134. 仅支持中文、英文、数字、_、-。
  135. * @param integer $SnapshotInterval 截图间隔,单位s,默认10s。
  136. 范围: 2s ~ 300s。
  137. * @param integer $Width 截图宽度。默认:0(原始宽)。
  138. 范围:0-3000 。
  139. * @param integer $Height 截图高度。默认:0(原始高)。
  140. 范围:0-2000 。
  141. * @param integer $PornFlag 是否开启鉴黄,0:不开启,1:开启。默认:0。
  142. * @param string $CosPrefix Cos Bucket文件夹前缀。
  143. 如不传,实际按默认值
  144. /{Year}-{Month}-{Day}
  145. 生效
  146. * @param string $CosFileName Cos 文件名称。
  147. 如不传,实际按默认值
  148. {StreamID}-screenshot-{Hour}-{Minute}-{Second}-{Width}x{Height}{Ext}
  149. 生效
  150. */
  151. function __construct()
  152. {
  153. }
  154. /**
  155. * For internal only. DO NOT USE IT.
  156. */
  157. public function deserialize($param)
  158. {
  159. if ($param === null) {
  160. return;
  161. }
  162. if (array_key_exists("TemplateName",$param) and $param["TemplateName"] !== null) {
  163. $this->TemplateName = $param["TemplateName"];
  164. }
  165. if (array_key_exists("CosAppId",$param) and $param["CosAppId"] !== null) {
  166. $this->CosAppId = $param["CosAppId"];
  167. }
  168. if (array_key_exists("CosBucket",$param) and $param["CosBucket"] !== null) {
  169. $this->CosBucket = $param["CosBucket"];
  170. }
  171. if (array_key_exists("CosRegion",$param) and $param["CosRegion"] !== null) {
  172. $this->CosRegion = $param["CosRegion"];
  173. }
  174. if (array_key_exists("Description",$param) and $param["Description"] !== null) {
  175. $this->Description = $param["Description"];
  176. }
  177. if (array_key_exists("ProductName",$param) and $param["ProductName"] !== null) {
  178. $this->ProductName = $param["ProductName"];
  179. }
  180. if (array_key_exists("SnapshotInterval",$param) and $param["SnapshotInterval"] !== null) {
  181. $this->SnapshotInterval = $param["SnapshotInterval"];
  182. }
  183. if (array_key_exists("Width",$param) and $param["Width"] !== null) {
  184. $this->Width = $param["Width"];
  185. }
  186. if (array_key_exists("Height",$param) and $param["Height"] !== null) {
  187. $this->Height = $param["Height"];
  188. }
  189. if (array_key_exists("PornFlag",$param) and $param["PornFlag"] !== null) {
  190. $this->PornFlag = $param["PornFlag"];
  191. }
  192. if (array_key_exists("CosPrefix",$param) and $param["CosPrefix"] !== null) {
  193. $this->CosPrefix = $param["CosPrefix"];
  194. }
  195. if (array_key_exists("CosFileName",$param) and $param["CosFileName"] !== null) {
  196. $this->CosFileName = $param["CosFileName"];
  197. }
  198. }
  199. }

创建文件: CreateSnapshotTemplateResponse.php``

  1. php
  2. /*
  3. * Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace TencentCloud\Live\V20180801\Models;
  18. use TencentCloud\Common\AbstractModel;
  19. ``
  20. /**
  21. * CreateLiveSnapshotTemplate返回参数结构体
  22. *
  23. * @method integer getTemplateId() 获取模板Id。
  24. * @method void setTemplateId(integer $TemplateId) 设置模板Id。
  25. * @method string getRequestId() 获取唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
  26. * @method void setRequestId(string $RequestId) 设置唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
  27. */
  28. class CreateSnapshotTemplateResponse extends AbstractModel
  29. {
  30. /**
  31. * @var integer 模板Id。
  32. */
  33. public $TemplateId;
  34. /**
  35. * @var string 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
  36. */
  37. public $RequestId;
  38. /**
  39. * @param integer $TemplateId 模板Id。
  40. * @param string $RequestId 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
  41. */
  42. function __construct()
  43. {
  44. }
  45. /**
  46. * For internal only. DO NOT USE IT.
  47. */
  48. public function deserialize($param)
  49. {
  50. if ($param === null) {
  51. return;
  52. }
  53. if (array_key_exists("TemplateId",$param) and $param["TemplateId"] !== null) {
  54. $this->TemplateId = $param["TemplateId"];
  55. }
  56. if (array_key_exists("RequestId",$param) and $param["RequestId"] !== null) {
  57. $this->RequestId = $param["RequestId"];
  58. }
  59. }
  60. }

``

项目composer.php加载该自定义autoload.php 加载器: ``

``

  1. "autoload": {
  2. "psr-4": {
  3. "app\\": "application"
  4. },
  5. "files": [ //以下是自己添加的两个类
  6. "app/Plugins/Live/Models/CreateSnapshotTemplateRequest.php",
  7. "app/Plugins/Live/Models/CreateSnapshotTemplateResponse.php"
  8. ]
  9. },

修改了composer.php的autoload的配置后,我们需要重新生成整个项目最终autoload.php,在项目路径执行命令:

  1. composer dump-autoload

Last modification:October 14, 2022
如果觉得我的文章对你有用,请随意赞赏