You need to enable JavaScript to run this app.
文档中心
复制全文
下载 pdf
PHP SDK
媒体处理任务
复制全文
下载 pdf
媒体处理任务

本文为您提供服务端 PHP SDK 的媒体处理任务相关的 API 调用示例。

初始化

使用前请先完成初始化

提交媒体处理任务

接口请求参数和返回参数详见 OpenAPI:提交媒体处理任务

示例一:根据工作流模板触发任务

<?php

require('../../../vendor/autoload.php');

use Volc\Service\Imp\Imp;
use Volc\Service\Imp\Models\Business\InputPath;
use Volc\Service\Imp\Models\Request\ImpSubmitJobRequest;
use Volc\Service\Imp\Models\Response\ImpSubmitJobResponse;

// call below method if you don't set ak and sk in $HOME/.vcloud/config
$client = Imp::getInstance();
$client->setAccessKey("your ak");
$client->setSecretKey("your sk");

$request = new ImpSubmitJobRequest();

$inputPath = new InputPath();
$inputPath->setType("VOD");
$inputPath->setVodSpaceName("your space name");
$inputPath->setFileId("your file id");

$request->setTemplateId("your template id");
$request->setCallbackArgs("your callback args");
$request->setEnableLowPriority("false"); // true 开启 false 不开启 闲时转码
$request->setInputPath($inputPath);

$response = new ImpSubmitJobResponse();
try {
    $response = $client->SubmitJob($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}

echo $response->serializeToJsonString();
echo "\n";

示例二:单任务触发

<?php

require('../../../vendor/autoload.php');

use Volc\Service\Imp\Imp;
use Volc\Service\Imp\Models\Business\Audio;
use Volc\Service\Imp\Models\Business\InputPath;
use Volc\Service\Imp\Models\Business\Job;
use Volc\Service\Imp\Models\Business\OutputPath;
use Volc\Service\Imp\Models\Business\TranscodeVideoJob;
use Volc\Service\Imp\Models\Business\Video;
use Volc\Service\Imp\Models\Request\ImpSubmitJobRequest;
use Volc\Service\Imp\Models\Response\ImpSubmitJobResponse;

// call below method if you don't set ak and sk in $HOME/.vcloud/config
$client = Imp::getInstance();
$client->setAccessKey("your ak");
$client->setSecretKey("your sk");

$request = new ImpSubmitJobRequest();

$inputPath = new InputPath();
$inputPath->setType("VOD");
$inputPath->setVodSpaceName("your space name");
$inputPath->setFileId("your file id");

$outputPath = new OutputPath();
$outputPath->setType("VOD");
$outputPath->setVodSpaceName("your space name");

$job = new Job();
$transcodeVideo = new TranscodeVideoJob();
$video = new Video();
$video->setCodec("your video codec");
$audio = new Audio();
$audio->setCodec("your audio codec");
$transcodeVideo->setContainer("your container");
$transcodeVideo->setVideo($video);
$transcodeVideo->setAudio($audio);
$job->setTranscodeVideo($transcodeVideo);

$request->setJob($job);
$request->setInputPath($inputPath);
$request->setOutputPath($outputPath);
$request->setCallbackArgs("your callback args");
$request->setEnableLowPriority("false"); // true 开启 false 不开启 闲时转码

$response = new ImpSubmitJobResponse();
try {
    $response = $client->SubmitJob($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}

echo $response->serializeToJsonString();
echo "\n";

查询媒体处理任务

接口请求参数和返回参数详见 OpenAPI:查询媒体处理任务

<?php

require('../../../vendor/autoload.php');

use Volc\Service\Imp\Models\Request\ImpRetrieveJobRequest;
use Volc\Service\Imp\Models\Response\ImpRetrieveJobResponse;
use Volc\Service\Imp\Imp;

// call below method if you don't set ak and sk in $HOME/.vcloud/config
$client = Imp::getInstance();
$client->setAccessKey("your ak");
$client->setSecretKey("your sk");

$request = new ImpRetrieveJobRequest();

$jobIds = ["your job id 1", "your job id 2"];
$request->setJobIds($jobIds);

$response = new ImpRetrieveJobResponse();
try {
    $response = $client->RetrieveJob($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}

echo $response->serializeToJsonString();
echo "\n";

取消媒体处理任务

接口请求参数和返回参数详见 OpenAPI:取消媒体处理任务

<?php

require('../../../vendor/autoload.php');

use Volc\Service\Imp\Models\Request\ImpKillJobRequest;
use Volc\Service\Imp\Models\Response\ImpKillJobResponse;
use Volc\Service\Imp\Imp;

// call below method if you don't set ak and sk in $HOME/.vcloud/config
$client = Imp::getInstance();
$client->setAccessKey("your ak");
$client->setSecretKey("your sk");

$request = new ImpKillJobRequest();

$request->setJobId("your job id");

$response = new ImpKillJobResponse();
try {
    $response = $client->KillJob($request);
} catch (Exception $e) {
    echo $e, "\n";
} catch (Throwable $e) {
    echo $e, "\n";
}
if ($response->getResponseMetadata()->getError() != null) {
    print_r($response->getResponseMetadata()->getError());
}

echo $response->serializeToJsonString();
echo "\n";
最近更新时间:2025.02.18 16:08:35
这个页面对您有帮助吗?
有用
有用
无用
无用