Облако Alibaba - потоковое видео

Я хочу использовать видео по запросу облачного сервиса Alibaba для потокового видео. видео по запросу создает видео с разным разрешением из загруженных видео для потоковой передачи данных. Для этого я использую https://github.com/aliyun/aliyun-openapi-php-sdk.
Теперь проблема в том, что я не знаю, как загрузить видео в видео по запросу через панель кода. Я зарегистрировался в https://github.com/aliyun/aliyun-openapi-php-sdk/blob/master/aliyun-php-sdk-vod/vod/Request/V20170321/CreateUploadVideoRequest.php но не нашел поля или параметр, который используется для загрузки видео. Если есть какой-либо другой SDK или код, пожалуйста, дайте мне знать. Даже любой документ кода или фрагмента также приветствуется.

3 ответа

Пример фрагмента кода можно найти здесь (хотя на упрощенном китайском): https://help.aliyun.com/document_detail/61069.html

<?php
include_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php'; //source php and aliyun-php-sdk in same directory
use vod\Request\V20170321 as vod;
function init_vod_client($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}
function create_upload_video($client) {
    $request = new vod\CreateUploadVideoRequest();
    $request->setTitle("VideoTitle");               // Video Title (Mandatory)
    $request->setFileName("filename.mov");          // Source document file name with file extension (Mandatory)
    $request->setDescription("Video Description");  // Video Description (Optional)
    $request->setCoverURL("http://img.alicdn.com/tps/XXXXXXXXXXXXXXXXXXXXXXXXXXX-700-700.png"); // Custom video coverpage (Optional)
    $request->setTags("Tag1,Tag2");                 // Video tags, separated by commas (Optional)
    $request->setAcceptFormat('JSON');
    return $client->getAcsResponse($request);
}
try {
    $client = init_vod_client('<AccessKeyId>', '<AccessKeySecret>');
    $uploadInfo = create_upload_video($client);
    var_dump($uploadInfo);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}
?>

Существует также демонстрационная версия использования OSS SDK для загрузки видео, доступная по https://help.aliyun.com/document_detail/61388.html (также на упрощенном китайском)

Надеюсь это поможет.

Пожалуйста, найдите фрагмент кода.

<?php
require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php';    
require_once './aliyun-php-sdk/aliyun-oss-php-sdk-2.2.4/autoload.php';

use vod\Request\V20170321 as vod;
use OSS\OssClient;
use OSS\Core\OssException;


function init_vod_client($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai'; 
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


function create_upload_video($vodClient) {
    $request = new vod\CreateUploadVideoRequest();

    $request->setTitle("Movie");        
    $request->setFileName("elephant.mov"); 

    $request->setDescription("It is about elephant"); 
    $request->setCoverURL("http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"); 
    $request->setTags("forest,elephant"); 

    return $vodClient->getAcsResponse($request);
}

function refresh_upload_video($vodClient, $videoId) {
    $request = new vod\RefreshUploadVideoRequest();
    $request->setVideoId($videoId);
    return $vodClient->getAcsResponse($request);
}

function init_oss_client($uploadAuth, $uploadAddress) {
    $ossClient = new OssClient($uploadAuth['AccessKeyId'], $uploadAuth['AccessKeySecret'], $uploadAddress['Endpoint'], 
        false, $uploadAuth['SecurityToken']);
    $ossClient->setTimeout(86400*7);    
    $ossClient->setConnectTimeout(10);  
    return $ossClient;
}


function upload_local_file($ossClient, $uploadAddress, $localFile) {
    return $ossClient->uploadFile($uploadAddress['Bucket'], $uploadAddress['FileName'], $localFile);
}


function multipart_upload_file($ossClient, $uploadAddress, $localFile) {
    return $ossClient->multiuploadFile($uploadAddress['Bucket'], $uploadAddress['FileName'], $localFile);
}

$accessKeyId = '<AccessKeyId>';
$accessKeySecret = '<AccessKeySecret>';           
$localFile = '/Users/yours/Video/testVideo.flv';   

try {

    $vodClient = init_vod_client($accessKeyId, $accessKeySecret);
    $createRes = create_upload_video($vodClient);

    $videoId = $createRes->VideoId;
    $uploadAddress = json_decode(base64_decode($createRes->UploadAddress), true);
    $uploadAuth = json_decode(base64_decode($createRes->UploadAuth), true);


    $ossClient = init_oss_client($uploadAuth, $uploadAddress);


    //$result = upload_local_file($ossClient, $uploadAddress, $localFile);
    $result = multipart_upload_file($ossClient, $uploadAddress, $localFile);
    printf("Succeed, VideoId: %s", $videoId);

} catch (Exception $e) {
    // var_dump($e);
    printf("Failed, ErrorMessage: %s", $e->getMessage());
}

Для более подробной информации, пожалуйста, ознакомьтесь с официальной документацией

Вот вам самое последнее обновление кода на 202105. ссылка на руководство, как показано ниже:

https://www.alibabacloud.com/help/doc-detail/100976.htm?spm=a2c63.p38356.879954.13.330a12fcc5cLMD#task-1995280

      <? php
/**
 * Created by Aliyun ApsaraVideo VOD.
 */
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'voduploadsdk' . DIRECTORY_SEPARATOR . 'Autoloader.php';
date_default_timezone_set('PRC');
// Test the upload of an on-premises video.
function testUploadLocalVideo($accessKeyId, $accessKeySecret, $filePath)
{
    try {
        $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
        $uploadVideoRequest = new UploadVideoRequest($filePath, 'testUploadLocalVideo via PHP-SDK');
        //$uploadVideoRequest->setCateId(1);
        //$uploadVideoRequest->setCoverURL("http://xxxx.jpg");
        //$uploadVideoRequest->setTags('test1,test2');
        //$uploadVideoRequest->setStorageLocation('outin-xx.oss-cn-beijing.aliyuncs.com');
        //$uploadVideoRequest->setTemplateGroupId('6ae347b0140181ad371d197ebe289326');
        $userData = array(
            "MessageCallback"=>array("CallbackURL"=>"https://demo.sample.com/ProcessMessageCallback"),
            "Extend"=>array("localId"=>"xxx", "test"=>"www")
        );
        $uploadVideoRequest->setUserData(json_encode($userData));
        $res = $uploader->uploadLocalVideo($uploadVideoRequest);
        print_r($res);
    } catch (Exception $e) {
        printf("testUploadLocalVideo Failed, ErrorMessage: %s\n Location: %s %s\n Trace: %s\n",
            $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
    }
}
// Tests the upload of an online video.
function testUploadWebVideo($accessKeyId, $accessKeySecret, $fileURL)
{
    try {
        $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
        $uploadVideoRequest = new UploadVideoRequest($fileURL, 'testUploadWebVideo via PHP-SDK');
        $res = $uploader->uploadWebVideo($uploadVideoRequest);
        print_r($res);
    } catch (Exception $e) {
        printf("testUploadWebVideo Failed, ErrorMessage: %s\n Location: %s %s\n Trace: %s\n",
            $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
    }
}
// Test the upload of an on-premises M3U8 video.
function testUploadLocalM3u8($accessKeyId, $accessKeySecret, $m3u8FilePath)
{
    try {
        $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
        $uploadVideoRequest = new UploadVideoRequest($m3u8FilePath, 'testUploadLocalM3u8 via PHP-SDK');
        // Call the method for parsing the M3U8 playlist to obtain the URLs of parts. If the parsing result is invalid, manually assemble the URLs of parts. By default, the part files and M3U8 files are stored in the same directory.
        $sliceFiles = $uploader->parseM3u8File($m3u8FilePath);
        //print_r($sliceFiles);
        $res = $uploader->uploadLocalM3u8($uploadVideoRequest, $sliceFiles);
        print_r($res);
    } catch (Exception $e) {
        printf("testUploadLocalM3u8 Failed, ErrorMessage: %s\n Location: %s %s\n Trace: %s\n",
            $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
    }
}
// Test the upload of an online M3U8 video.
function testUploadWebM3u8($accessKeyId, $accessKeySecret, $m3u8FileUrl)
{
    try {
        $uploader = new AliyunVodUploader($accessKeyId, $accessKeySecret);
        $uploadVideoRequest = new UploadVideoRequest($m3u8FileUrl, 'testUploadWebM3u8 via PHP-SDK');
        // Call the method for parsing the M3U8 playlist to obtain the URLs of parts. If the parsing result is invalid, manually assemble the URLs of parts. By default, the part files and M3U8 files are stored in the same directory.
        $sliceFileUrls = $uploader->parseM3u8File($m3u8FileUrl);
        //print_r($sliceFileUrls);
        $res = $uploader->uploadWebM3u8($uploadVideoRequest, $sliceFileUrls);
        print_r($res);
    } catch (Exception $e) {
        printf("testUploadWebM3u8 Failed, ErrorMessage: %s\n Location: %s %s\n Trace: %s\n",
            $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
    }
}
####   Run the test code.   ####
$accessKeyId = '<AccessKeyId>';
$accessKeySecret = '<AccessKeySecret>';
//$localFilePath = 'C:\test\sample.mp4';
$localFilePath = '/opt/video/sample.mp4';
//testUploadLocalVideo($accessKeyId, $accessKeySecret, $localFilePath);
$webFileURL = 'http://vod-test1.cn-shanghai.aliyuncs.com/b55b904bc612463b812990b7c8cc95c8/daa30814c0c340cf8199926f78aa5c0e-a0bc05ba62c3e95cc672e88b828148c9-ld.mp4?auth_key=1608774986-0-0-c56acd302bea0c331370d8ed686502fe';
testUploadWebVideo($accessKeyId, $accessKeySecret, $webFileURL);
$localM3u8FilePath = '/opt/video/m3u8/sample.m3u8';
//testUploadLocalM3u8($accessKeyId, $accessKeySecret, $localM3u8FilePath);
$webM3u8FileURL = 'http://vod-test1.cn-shanghai.aliyuncs.com/b55b904bc612463b812990b7c8cc95c8/daa30814c0c340cf8199926f78aa5c0e-195a25af366b5edae324c47e99a03f04-ld.m3u8?auth_key=1608775606-0-0-9fb038deaecd009dadd86721c5855629';
//testUploadWebM3u8($accessKeyId, $accessKeySecret, $webM3u8FileURL);
Другие вопросы по тегам