全部产品

视频剪辑

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

初始化客户端

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

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

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

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

说明

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.ProduceEditingProjectVideo
{
    class MainClass
    {
         /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
                // 构造剪辑工程时间线
                request.Timeline = BuildTimeline();
                // 设置元数据
                request.MediaMetadata = BuildMediaMetadata();
                // 设置工程配置
                request.ProduceConfig = BuildProduceConfig();
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                ProduceEditingProjectVideoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("MediaId = " + response.MediaId);
                Console.WriteLine("ProjectId = " + response.ProjectId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Builds the timeline.
        /// </summary>
        /// <returns>The timeline.</returns>
        private static string BuildTimeline() {
            JObject timeLine = new JObject();
            // Video Track
            JArray videoTracks = new JArray();
            JObject videoTrack = new JObject();

            // Video Track Clips
            JArray videoTrackClips = new JArray();
            JObject videoTrackClip1 = new JObject();
            videoTrackClip1.Add("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
            videoTrackClips.Add(videoTrackClip1);

            JObject videoTrackClip2 = new JObject();
            videoTrackClip2.Add("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
            videoTrackClips.Add(videoTrackClip2);
            videoTrack.Add("VideoTrackClips", videoTrackClips);
            videoTracks.Add(videoTrack);

            timeLine.Add("VideoTracks", videoTracks);

            return timeLine.ToString();
        }

        /// <summary>
        /// Builds the media metadata.
        /// </summary>
        /// <returns>The media metadata.</returns>
        private static string BuildMediaMetadata() {
            JObject mediaMetadata = new JObject();
            // Produce Media Title
            mediaMetadata.Add("Title", "Title");
            // Produce Media Description
            mediaMetadata.Add("Description", "Description");
            // Produce Media UserDefined Cover URL
            mediaMetadata.Add("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
            // Produce Media Category ID
            mediaMetadata.Add("CateId", null);
            // Produce Media Category Name
            mediaMetadata.Add("Tags", "Tag1,Tag2,Test");

            return mediaMetadata.ToString();
        }

        /// <summary>
        /// Builds the produce config.
        /// </summary>
        /// <returns>The produce config.</returns>
        private static string BuildProduceConfig() {
            JObject produceConfig = new JObject();
            /**
             * 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.Add("TemplateGroupId", null);
            return produceConfig.ToString();
        }
    }
}

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

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.ProduceEditingProjectVideoProjectId
{
    class MainClass
    {
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            ProduceEditingProjectVideoResponse response = null;
            try
            {
                // 构造请求
                ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
                // 构造剪辑工程时间线
                request.ProjectId = "ProjectId";
                // 设置元数据
                request.MediaMetadata = BuildMediaMetadata();
                // 设置工程配置
                request.ProduceConfig = BuildProduceConfig();
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("MediaId = " + response.MediaId);
                Console.WriteLine("ProjectId = " + response.ProjectId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Builds the media metadata.
        /// </summary>
        /// <returns>The media metadata.</returns>
        private static string BuildMediaMetadata()
        {
            JObject mediaMetadata = new JObject();

            // Produce Media Title
            mediaMetadata.Add("Title", "Title");
            // Produce Media Description
            mediaMetadata.Add("Description", "Description");
            // Produce Media UserDefined Cover URL
            mediaMetadata.Add("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
            // Produce Media Category ID
            mediaMetadata.Add("CateId", null);
            // Produce Media Category Name
            mediaMetadata.Add("Tags", "Tag1,Tag2,Test");

            return mediaMetadata.ToString();
        }

        /// <summary>
        /// Builds the produce config.
        /// </summary>
        /// <returns>The produce config.</returns>
        private static string BuildProduceConfig()
        {
            JObject produceConfig = new JObject();
            /**
             * 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.Add("TemplateGroupId", null);

            return produceConfig.ToString();
        }
    }
}

创建云剪辑工程

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.AddEditingProject
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                AddEditingProjectRequest request = new AddEditingProjectRequest();
                request.Description = "new Description";
                request.Title = "new Title";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                AddEditingProjectResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.Project != null) {
                    Console.WriteLine("ProjectId = " + response.Project.ProjectId);
                    Console.WriteLine("Title = " + response.Project.Title);
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

修改云剪辑工程

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.UpdateEditingProject
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                UpdateEditingProjectRequest request = new UpdateEditingProjectRequest();
                request.ProjectId = "YourProjectId";
                request.Title = "new Title";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateEditingProjectResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

删除云剪辑工程

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteEditingProject
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteEditingProjectRequest request = new DeleteEditingProjectRequest();
                // Use comma to split Multi Editing Project IDs
                request.ProjectIds = "projectid1,projectid2";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteEditingProjectResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

获取单个云剪辑工程

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetEditingProject
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetEditingProjectRequest request = new GetEditingProjectRequest();
                request.ProjectId = "projectid";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetEditingProjectResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.Project != null)
                {
                    Console.WriteLine("ProjectId = " + response.Project.ProjectId);
                    Console.WriteLine("Title = " + response.Project.Title);
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

搜索云剪辑工程

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.SearchEditingProject
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                SearchEditingProjectRequest request = new SearchEditingProjectRequest();
                request.Title = "Title Keywords";
                request.StartTime = "2017-01-11T12:00:00Z";
                request.EndTime = "2017-01-12T12:00:00Z";
                request.PageSize = 10;
                request.PageNo = 1;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                SearchEditingProjectResponse response = client.GetAcsResponse(request);
                // 打印本次请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.ProjectList != null && response.ProjectList.Count > 0)
                {
                    foreach (var project in response.ProjectList)
                    {
                        Console.WriteLine("ProjectId = " + project.ProjectId);
                    }
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

设置云剪辑工程素材

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.SetEditingProjectMaterials
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                SetEditingProjectMaterialsRequest request = new SetEditingProjectMaterialsRequest();
                // Editing Project ID
                request.ProjectId = "projectid";
                // Set Editing Project Material IDs, use comma to split
                request.MaterialIds = "materialId1,materialId2";

                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                SetEditingProjectMaterialsResponse response = client.GetAcsResponse(request);
                // 打印本次请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

获取云剪辑工程素材

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

Aliyun.Acs.vod.Sdk.GetEditingProjectMaterials
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetEditingProjectMaterialsRequest request = new GetEditingProjectMaterialsRequest();
                request.ProjectId = "projectid";
                request.Type = "video";

                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetEditingProjectMaterialsResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.MaterialList != null && response.MaterialList.Count > 0)
                {
                    foreach (var material in response.MaterialList) 
                    {
                        Console.WriteLine("MaterialId = " + material.MaterialId);
                        Console.WriteLine("Title = " + material.Title);
                    }
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}