全部产品

视频剪辑

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

初始化客户端

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

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

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

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

说明

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

// Build Editing Project Timeline
var timeline = {
    // Video Track
    VideoTracks: [{
        // Video Track Clips
        VideoTrackClips: [{
            MediaId: 'MediaId1'
        },{
            MediaId: 'MediaId2'
        }]
    }]
};
// Set Produce Media Metadata
var mediaMetadata = {
    Title: 'Title',  // Produce Media Title
    Description: 'Description',  // Produce Media Description
    CoverURL: 'http://test.testvod123.com/media/cover/mediaid.jpg',  // Produce Media UserDefined Cover URL
    CateId: null,   // Produce Media Category ID
    Tags: 'Tag1,Tag2'   // Produce Media Category Name
};
// Set Produce Configuration
var produceConfig = {
    /*
     生成过程可以生成媒体夹层文件。您可以使用夹层文件来转码其他媒体文件,就像文件上传完成后的转码过程一样。此字段描述生产夹层完成后的Transocde TemplateGroup ID。
     1. Not required
     2. Use default transcode template group id when empty
     */
    TemplateGroupId: null
};
client.request("ProduceEditingProjectVideo", {
    Timeline: JSON.stringify(timeline),
    MediaMetadata: JSON.stringify(mediaMetadata),
    ProduceConfig: JSON.stringify(produceConfig)
}, {}).then(function (response) {
    // Produce Media ID
    console.log('MediaId = '+ response.MediaId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

// Set Produce Media Metadata
var mediaMetadata = {
    Title: 'Title',  // Produce Media Title
    Description: 'Description',  // Produce Media Description
    CoverURL: 'http://test.testvod123.com/media/cover/mediaid.jpg',  // Produce Media UserDefined Cover URL
    CateId: null,   // Produce Media Category ID
    Tags: 'Tag1,Tag2'   // Produce Media Category Name
};
// Set Produce Configuration
var produceConfig = {
    /*
     生成过程可以生成媒体夹层文件。您可以使用夹层文件来转码其他媒体文件,就像文件上传完成后的转码过程一样。此字段描述生产夹层完成后的Transocde TemplateGroup ID。
     1. Not required
     2. Use default transcode template group id when empty
     */
    TemplateGroupId: null
};
client.request("ProduceEditingProjectVideo", {
    ProjectId: 'ProjectId',    // Set Editing Project ID need to produce
    MediaMetadata: JSON.stringify(mediaMetadata),
    ProduceConfig: JSON.stringify(produceConfig)
}, {}).then(function (response) {
    // Produce Media ID
    console.log('MediaId = '+ response.MediaId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

创建云剪辑工程

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

// Build Editing Project Timeline
var timeline = {
    // Video Track
    VideoTracks: [{
        // Video Track Clips
        VideoTrackClips: [{
            MediaId: 'MediaId1'
        },{
            MediaId: 'MediaId2'
        }]
    }]
};
client.request("AddEditingProject", {
    Timeline: JSON.stringify(timeline),
    Title: 'Editing Project Title',   // Set Editing Project Title
    Description: 'Editing Project Description',   // Set Editing Project Description
    CoverURL: 'http://test.testvod123.com/editingproject/cover/projectid.jpg'  // Set Editing Project Cover URL
}, {}).then(function (response) {
    if (response.Project){
        console.log('Editing Project Id = '+ response.Project.ProjectId);
        console.log('Editing Project Title = '+ response.Project.Title);
        console.log('Editing Project Description = '+ response.Project.Description);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

修改云剪辑工程

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

// Build Editing Project Timeline
var timeline = {
    // Video Track
    VideoTracks: [{
        // Video Track Clips
        VideoTrackClips: [{
            MediaId: 'MediaId1'
        },{
            MediaId: 'MediaId2'
        }]
    }]
};
client.request("UpdateEditingProject", {
    ProjectId: 'ProjectId',
    Timeline: JSON.stringify(timeline),
    Title: 'Editing Project Title',   // Set Editing Project Title
    Description: 'Editing Project Description',   // Set Editing Project Description
    CoverURL: 'http://test.testvod123.com/editingproject/cover/projectid.jpg'  // Set Editing Project Cover URL
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

删除云剪辑工程

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

client.request("DeleteEditingProject", {
    ProjectIds: 'ProjectId1,projectid2'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取单个云剪辑工程

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

client.request("GetEditingProject", {
    ProjectId: 'ProjectId'
}, {}).then(function (response) {
    if (response.Project){
        console.log('Editing Project Id = '+ response.Project.ProjectId);
        console.log('Editing Project Timeline = '+ response.Project.Timeline);
        console.log('Editing Project Title = '+ response.Project.Title);
        console.log('Editing Project Description = '+ response.Project.Description);
        console.log('Editing Project CoverURL = '+ response.Project.CoverURL);
        console.log('Editing Project CreationTime = '+ response.Project.CreationTime);
        console.log('Editing Project ModifiedTime = '+ response.Project.ModifiedTime);
        console.log('Editing Project Status = '+ response.Project.Status);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

搜索云剪辑工程

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

client.request("SearchEditingProject", {
    Title: 'TitleKeywords',
    StartTime: '2018-12-28T14:42:18Z',
    EndTime: '2018-12-30T14:42:18Z',
    PageSize: 10,
    PageNo: 1
}, {}).then(function (response) {
    if (response.ProjectList && response.ProjectList.Project && response.ProjectList.Project.length > 0){
        console.log('Total Size = ' + response.Total);
        for(var i=0; i<response.ProjectList.Project.length; i++){
            var project = response.ProjectList.Project[i];
            console.log('No ' + i + ' Editing Project');
            console.log('Editing Project Id = '+ project.ProjectId);
            console.log('Editing Project Title = '+ project.Title);
            console.log('Editing Project Description = '+ project.Description);
            console.log('Editing Project CoverURL = '+ project.CoverURL);
            console.log('Editing Project CreationTime = '+ project.CreationTime);
            console.log('Editing Project ModifiedTime = '+ project.ModifiedTime);
            console.log('Editing Project Status = '+ project.Status);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

设置云剪辑工程素材

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

client.request("SetEditingProjectMaterials", {
    ProjectId: 'ProjectId',
    MaterialIds: 'MaterialId1,MaterialId2'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

获取云剪辑工程素材

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

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

// 调用样例
var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');

client.request("GetEditingProjectMaterials", {
    ProjectId: 'ProjectId',
    Type: 'video'
}, {}).then(function (response) {
    if (response.MaterialList && response.MaterialList.Material && response.MaterialList.Material.length > 0){
        for(var i=0; i<response.MaterialList.Material.length; i++){
            var material = response.MaterialList.Material[i];
            console.log('No ' + i + ' Editing Project');
            console.log('Editing Project Material Id = '+ material.MaterialId);
            console.log('Editing Project Material Title = '+ material.Title);
            console.log('Editing Project Material Category ID = '+ material.CateId);
            console.log('Editing Project Material Category Name = '+ material.CateName);
            console.log('Editing Project Material Tags = '+ material.Tags);
            console.log('Editing Project Material CoverURL = '+ material.CoverURL);
            console.log('Editing Project Material Create Time = '+ material.CreationTime);
            console.log('Editing Project Material Last ModifiedTime = '+ material.ModifiedTime);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});