最近更新时间:2022-02-18 17:47:03
此 SDK 适用于PHP 5.5 及以上版本。基于直播转码 API 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式调用金山云的直播转码服务。
2.1 ak/sk配置
在金山云控制台获取到ak/sk后创建以下文件:
mkdir ~/.ksyun && vi ~/.ksyun/config
config文件内容
{
"ak":"********************",
"sk":"****************************************"
}
2.2 composer安装
mkdir test && cd test
composer require kscsdk/ksyun_sdk
如果需要使用最新版本,安装完之后,修改composer.json为
{
"require": {
"kscsdk/ksyun_sdk": "dev-master"
}
}
然后再执行更新操作
composer update
2.3 调试demo
cp vendor/kscsdk/ksyun_sdk/examples/demo_Ket.php .
php demo_Ket.php GetPresetList
2.4 调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$response = Ket::getInstance()->request('GetPresetList');
echo $response->getBody();
注:接口的传递的参数及返回值请参考《视频云直播转码接入说明》API接口说明
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$preset = 'preset_demo'; // 模板名
$preset_data = [
'Preset' => $preset,
'App' => $app,
'Description' => 'desc: preset demo',
'Output' => [
[
'format' => [
'output_format' => 256,
'abr' => 60000,
'vbr' => 800000,
'fr' => 25,
'logo_switch' => 1
]
],
[
'format' => [
'output_format' => 257,
'abr' => 70000,
'vbr' => 700000,
'fr' => 23,
'logo_switch' => 0
]
]
],
'Video' => [
'logo' => [
[
'pic' => 'wangshuai9/ksyun.png',
'short_side' => 480,
'disable_scale' => 0,
'offsetX' => 10,
'offsetY' => -20
]
]
]
];
$response = Ket::getInstance()->request('Preset', ['query' => ['Uniqname' => $uniqname], 'json' => $preset_data]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$preset = 'preset_demo'; // 模板名
$preset_data = [
'Preset' => $preset,
'App' => $app,
'Description' => 'desc: preset demo',
'Output' => [
[
'format' => [
'output_format' => 256,
'abr' => 60000,
'vbr' => 800000,
'fr' => 25,
'logo_switch' => 1
]
],
[
'format' => [
'output_format' => 257,
'abr' => 70000,
'vbr' => 700000,
'fr' => 23,
'logo_switch' => 0
]
]
],
'Video' => [
'logo' => [
[
'pic' => 'wangshuai9/ksyun.png',
'short_side' => 480,
'disable_scale' => 0,
'offsetX' => 10,
'offsetY' => -20
]
]
]
];
$response = Ket::getInstance()->request('UpdatePreset', ['query' => ['Uniqname' => $uniqname], 'json' => $preset_data]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$preset = 'preset_demo'; // 模板名
$response = Ket::getInstance()->request('DelPreset', ['query' => ['Uniqname' => $uniqname, 'App' => $app, 'Preset' => $preset]]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$response = Ket::getInstance()->request('GetPresetList', ['query' => ['Uniqname' => $uniqname, 'App' => $app]]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$preset = 'preset_demo'; // 模板名
$response = Ket::getInstance()->request('GetPresetDetail', ['query' => ['Uniqname' => $uniqname, 'App' => $app, 'Preset' => $preset]]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$response = Ket::getInstance()->request('GetStreamTranList', ['query' => ['Uniqname' => $uniqname, 'App' => $app]]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$streamid = 'stream20170101'; // 流名
$outpull_data = [
'App' => $app,
'StreamID' => $streamid,
'SrcUrl' => 'rtmp://test.rtmplive.ks-cdn.com/live/streamdemo',
'Params' => ''
];
$response = Ket::getInstance()->request('StartStreamPull', ['query' => ['Uniqname' => $uniqname], 'json' => $outpull_data ]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$app = 'live'; // 频道名
$uniqname = 'test'; // 用户名
$streamid = 'stream20170101'; // 流名
$response = Ket::getInstance()->request('StopStreamPull', ['query' => ['Uniqname' => $uniqname], 'json' => ['App' => $app, 'StreamID' => $streamid]]);
echo $response->getBody();
调用示例
<?php
require('vendor/autoload.php');
use Ksyun\Service\Ket;
$uniqname = 'test'; // 用户名
$response = Ket::getInstance()->request('GetQuotaUsed', ['query' => ['Uniqname' => $uniqname]]);
echo $response->getBody();
纯净模式
鼠标选中内容,快速反馈问题