全部产品

视频剪辑

本篇文档提供了PHP SDK视频剪辑模块相关功能的API调用示例。包含发起剪辑合成、创建云剪辑工程、修改云剪辑工程、删除云剪辑工程、获取单个云剪辑工程、设置云剪辑工程素材等。

初始化客户端

使用前请先初始化客户端,请参见初始化

通过时间线-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过时间线-发起剪辑合成功能。

绝大多数场景下,使用这种方式即可合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

说明

通过时间线实现剪辑合成的更多Timeline示例请参见视频剪辑-使用示例

function buildMediaMetadata() {
    $mediaMetadata = array();
    // Produce Media Title
    $mediaMetadata['Title'] = 'Title';
    // Produce Media Description
    $mediaMetadata['Description'] = 'Description';
    // Produce Media UserDefined Cover URL
    $mediaMetadata['CoverURL'] = 'http://192.168.0.0/16/media/cover/mediaid.jpg';
    // Produce Media Category ID
    $mediaMetadata['CateId'] = null;
    // Produce Media Category Name
    $mediaMetadata['Tags'] = 'Tag1,Tag2,Test';

    return json_encode($mediaMetadata);
}

function buildProduceConfig() {
    $produceConfig = array();
    /*
     The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
     1. Not required
     2. Use default transcode template group id when empty
     */
    $produceConfig['TemplateGroupId'] = null;
    return json_encode($produceConfig);
}

function buildTimeline() {
    $timeline = array();

    // Video Track
    $videoTracks = array();
    $videoTrack = array();

    // Video Track Clicps
    $videoTrackClips = array();
    $videoTrackClip1 = array();
    $videoTrackClip1['MediaId'] = '6893fca9814640c8821efa52352****';
    $videoTrackClips[] = $videoTrackClip1;

    $videoTrackClip2 = array();
    $videoTrackClip2['MediaId'] = '070bbc13d8294e35b36c3e7ab52****';
    $videoTrackClips[] = $videoTrackClip2;

    $videoTrack['VideoTrackClips'] = $videoTrackClips;
    $videoTracks[] = $videoTrack;
    $timeline['VideoTracks'] = $videoTracks;

    return json_encode($timeline);
}

try {
     $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\ProduceEditingProjectVideoRequest();
    // Set Produce Media Metadata
    $request->setMediaMetadata(buildMediaMetadata());
    // Set Produce Configuration
    $request->setProduceConfig(buildProduceConfig());
    // Build Editing Project Timeline
    $request->setTimeline(buildTimeline());

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

通过云剪辑工程-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过云剪辑工程-发起剪辑合成功能。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

function buildMediaMetadata() {
    $mediaMetadata = array();
    // Produce Media Title
    $mediaMetadata['Title'] = 'Title';
    // Produce Media Description
    $mediaMetadata['Description'] = 'Description';
    // Produce Media UserDefined Cover URL
    $mediaMetadata['CoverURL'] = 'http://192.168.0.0/16/media/cover/mediaid.jpg';
    // Produce Media Category ID
    $mediaMetadata['CateId'] = null;
    // Produce Media Category Name
    $mediaMetadata['Tags'] = 'Tag1,Tag2,Test';

    return json_encode($mediaMetadata);
}

function buildProduceConfig() {
    $produceConfig = array();
    /*
     The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
     1. Not required
     2. Use default transcode template group id when empty
     */
    $produceConfig['TemplateGroupId'] = null;
    return json_encode($produceConfig);
}

try {
     $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\ProduceEditingProjectVideoRequest();
    // Set Editing Project ID need to produce
    $request->setProjectId('7794d3757fe548e0abacb5dd1052****');
    // Set Produce Media Metadata
    $request->setMediaMetadata(buildMediaMetadata());
    // Set Produce Configuration
    $request->setProduceConfig(buildProduceConfig());

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

创建云剪辑工程

调用AddEditingProject接口,完成创建云剪辑工程功能。

接口参数和返回字段请参见AddEditingProject。调用示例如下:

function buildTimeline() {
    $timeline = array();

    // Video Track
    $videoTracks = array();
    $videoTrack = array();

    // Video Track Clicps
    $videoTrackClips = array();
    $videoTrackClip1 = array();
    $videoTrackClip1['MediaId'] = '6893fca9814640c8821efa52352****';
    $videoTrackClips[] = $videoTrackClip1;

    $videoTrackClip2 = array();
    $videoTrackClip2['MediaId'] = '070bbc13d8294e35b36c3e7ab52****';
    $videoTrackClips[] = $videoTrackClip2;

    $videoTrack['VideoTrackClips'] = $videoTrackClips;
    $videoTracks[] = $videoTrack;
    $timeline['VideoTracks'] = $videoTracks;

    return json_encode($timeline);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\AddEditingProjectRequest();
    // Build Editing Project Timeline
    $request->setTimeline(buildTimeline());
   // Set Editing Project Title
    $request->setTitle('Editing Project Title');
    // Set Editing Project Description
    $request->setDescription('Editing Project Description');
    // Set Editing Project Cover URL
    $request->setCoverURL('http://192.168.0.0/16/editingproject/cover/projectid.jpg');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

修改云剪辑工程

调用UpdateEditingProject接口,完成修改云剪辑工程功能。

接口参数和返回字段请参见UpdateEditingProject。调用示例如下:

function buildTimeline() {
    $timeline = array();

    // Video Track
    $videoTracks = array();
    $videoTrack = array();

    // Video Track Clicps
    $videoTrackClips = array();
    $videoTrackClip1 = array();
    $videoTrackClip1['MediaId'] = '6893fca9814640c8821efa523xxxxxx';
    $videoTrackClips[] = $videoTrackClip1;

    $videoTrackClip2 = array();
    $videoTrackClip2['MediaId'] = '070bbc13d8294e35b36c3e7ab52****';
    $videoTrackClips[] = $videoTrackClip2;

    $videoTrack['VideoTrackClips'] = $videoTrackClips;
    $videoTracks[] = $videoTrack;
    $timeline['VideoTracks'] = $videoTracks;

    return json_encode($timeline);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\UpdateEditingProjectRequest();
    // Set Editing Project ID
    $request->setProjectId('e7c5d44105d3487db23703be152****');
    // Build Editing Project Timeline
    $request->setTimeline(buildTimeline());
    // Set Editing Project Title
    $request->setTitle('Editing Project Title2');
    // Set Editing Project Description
    $request->setDescription('Editing Project Description2');
    // Set Editing Project Cover URL
    $request->setCoverURL('http://192.168.0.0/16/editingproject/cover/projectid.jpg');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

删除云剪辑工程

调用DeleteEditingProject接口,完成删除云剪辑工程功能。

接口参数和返回字段请参见DeleteEditingProject。调用示例如下:

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\DeleteEditingProjectRequest();
    // Use comma to split Multi Editing Project IDs
    $request->setProjectIds('e7c5d44105d3487db23703be1352****,12c5d44105d3487db23703be1352****');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

获取单个云剪辑工程

调用GetEditingProject接口,完成获取单个云剪辑工程功能。

接口参数和返回字段请参见GetEditingProject。调用示例如下:

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\GetEditingProjectRequest();
    // Set Editing Project ID
    $request->setProjectId('7794d3757fe548e0abacb5dd152****');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

搜索云剪辑工程

调用SearchEditingProject接口,完成搜索云剪辑工程功能。

接口参数和返回字段请参见SearchEditingProject。调用示例如下:

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\SearchEditingProjectRequest();
    $request->setTitle('Title Keywords');
    $request->setStartTime('2017-01-11T12:00:00Z');
    $request->setEndTime('2017-01-12T12:00:00Z');
    $request->setPageSize(10);
    $request->setPageNo(1);

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

设置云剪辑工程素材

调用SetEditingProjectMaterials接口,完成设置云剪辑工程素材功能。

接口参数和返回字段请参见SetEditingProjectMaterials。调用示例如下:

// 设置云剪辑工程素材
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\SetEditingProjectMaterialsRequest();
    // Set Editing Project ID    
    $request->setProjectId('7794d3757fe548e0abacb5dd1052****');
    // Set Editing Project Material IDs, use comma to split
    $request->setMaterialIds('materialId1,materialId2');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

获取云剪辑工程素材

调用GetEditingProjectMaterials接口,完成获取云剪辑工程素材功能。

接口参数和返回字段请参见GetEditingProjectMaterials。调用示例如下:

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');

    $request = new vod\GetEditingProjectMaterialsRequest();
    // Set Editing Project ID
    $request->setProjectId('7794d3757fe548e0abacb5dd1052****');
    // Set Editing Project Type
    $request->setType('video');

    // Get result
    $result = $client->getAcsResponse($request);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}