阿里云首页 视频点播

转码模板

本篇文档提供了.NET SDK转码模板模块相关功能的API调用示例。包含添加转码模板组、修改转码模板组、删除转码模板组、查询转码模板组、设置默认转码模板组等。

初始化客户端

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

添加转码模板组

调用AddTranscodeTemplateGroup接口,完成添加转码模板组功能。

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

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.AddTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                AddTranscodeTemplateGroupResponse response = AddTranscodeTemplateGroup(client);
                // 打印请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                // 打印转码模板ID
                Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroupId);
            }
            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>
        /// 添加转码模板组
        /// </summary>
        /// <returns>转码模板组</returns>
        /// <param name="client">Client.</param>
        public static AddTranscodeTemplateGroupResponse AddTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
            // 转码模板组名称
            request.Name = "grouptest";
            request.TranscodeTemplateList = BuildTranscodeTemplateList();

            // 返回结果
            return client.GetAcsResponse(request);

        }

        private static String BuildTranscodeTemplateList()
        {
            JArray transcodeTemplateList = new JArray();

            JObject transcodeTemplate = new JObject();
            //视频流转码配置
            JObject video = new JObject();
            video.Add("Width", 640);
            video.Add("Bitrate", 400);
            video.Add("Fps", "25");
            video.Add("Remove", false);
            video.Add("Codec", "H.264");
            video.Add("Gop", 250);
            transcodeTemplate.Add("Video", video);

            //音频流转码配置
            JObject audio = new JObject();
            audio.Add("Codec", "AAC");
            audio.Add("Bitrate", "64");
            audio.Add("Channels", "2");
            audio.Add("Samplerate", "32000");
            transcodeTemplate.Add("Audio", audio);

            //封装容器
            JObject container = new JObject();
            container.Add("Format", "mp4");
            transcodeTemplate.Add("Container", container);

            //条件转码配置
            JObject transconfig = new JObject();
            transconfig.Add("IsCheckReso", false);
            transconfig.Add("IsCheckResoFail", false);
            transconfig.Add("IsCheckVideoBitrate", false);
            transconfig.Add("IsCheckVideoBitrateFail", false);
            transconfig.Add("IsCheckAudioBitrate", false);
            transconfig.Add("IsCheckAudioBitrateFail", false);
            transcodeTemplate.Add("TransConfig", transconfig);

            //加密配置(只支持m3u8)
            //JObject encryptSetting = new JObject();
            //encryptSetting.Add("EncryptType", "Private");
            //transcodeTemplate.Add("EncryptSetting", encryptSetting);

            //清晰度
            transcodeTemplate.Add("Definition", "LD");
            //模板名称
            transcodeTemplate.Add("TemplateName", "testtemplate");
            //水印ID(多水印关联)
            //JArray watermarkIdList = new JArray();
            //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22****");
            //USER_DEFAULT_WATERMARK 代表默认水印ID
            //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
            //transcodeTemplate.Add("WatermarkIds", watermarkIdList);

            transcodeTemplateList.Add(transcodeTemplate);
            return transcodeTemplateList.ToString();
        }
    }
}

修改转码模板组

调用UpdateTranscodeTemplateGroup接口,完成修改转码模板组功能。

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

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.UpdateTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateTranscodeTemplateGroupResponse response = UpdateTranscodeTemplateGroup(client);
                // 打印请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                // 打印转码模版ID
                Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroupId);
            }
            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>
        /// 修改转码模板组
        /// </summary>
        /// <returns>转码模板组</returns>
        /// <param name="client">Client.</param>
        public static UpdateTranscodeTemplateGroupResponse UpdateTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
            request.Name = "newgrouptest";
            // 转码模板组ID
            request.TranscodeTemplateGroupId = "4c71a339fecec0152b4fa6f452****";

            request.TranscodeTemplateList = BuildTranscodeTemplateList();

            // 返回结果
            return client.GetAcsResponse(request);

        }

        private static String BuildTranscodeTemplateList()
        {
            JArray transcodeTemplateList = new JArray();

            JObject transcodeTemplate = new JObject();
            //视频流转码配置
            JObject video = new JObject();
            video.Add("Width", 640);
            video.Add("Bitrate", 400);
            video.Add("Fps", "25");
            video.Add("Remove", false);
            video.Add("Codec", "H.264");
            video.Add("Gop", 250);
            transcodeTemplate.Add("Video", video);

            //音频流转码配置
            JObject audio = new JObject();
            audio.Add("Codec", "AAC");
            audio.Add("Bitrate", "64");
            audio.Add("Channels", "2");
            audio.Add("Samplerate", "32000");
            transcodeTemplate.Add("Audio", audio);

            //封装容器
            JObject container = new JObject();
            container.Add("Format", "mp4");
            transcodeTemplate.Add("Container", container);

            //条件转码配置
            JObject transconfig = new JObject();
            transconfig.Add("IsCheckReso", false);
            transconfig.Add("IsCheckResoFail", false);
            transconfig.Add("IsCheckVideoBitrate", false);
            transconfig.Add("IsCheckVideoBitrateFail", false);
            transconfig.Add("IsCheckAudioBitrate", false);
            transconfig.Add("IsCheckAudioBitrateFail", false);
            transcodeTemplate.Add("TransConfig", transconfig);

            //加密配置(只支持m3u8)
            //JObject encryptSetting = new JObject();
            //encryptSetting.Add("EncryptType", "Private");
            //transcodeTemplate.Add("EncryptSetting", encryptSetting);

            //清晰度
            transcodeTemplate.Add("Definition", "SD");
            //模板名称
            transcodeTemplate.Add("TemplateName", "testtemplate");
            //转码模板ID
            transcodeTemplate.Add("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56****");
            //水印ID(多水印关联)
            //JArray watermarkIdList = new JArray();
            //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22****");
            //USER_DEFAULT_WATERMARK 代表默认水印ID
            //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
            //transcodeTemplate.Add("WatermarkIds", watermarkIdList);

            transcodeTemplateList.Add(transcodeTemplate);
            return transcodeTemplateList.ToString();
        }
    }
}

查询转码模板组列表

调用ListTranscodeTemplateGroup接口,完成查询转码模板组列表功能。

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

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.ListTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                ListTranscodeTemplateGroupResponse response = ListTranscodeTemplateGroup(client);
                // 打印请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                // 打印模板组信息
                if (response.TranscodeTemplateGroupList != null && response.TranscodeTemplateGroupList.Count > 0)
                {
                    foreach (ListTranscodeTemplateGroupResponse.ListTranscodeTemplateGroup_TranscodeTemplateGroup templateGroup in response.TranscodeTemplateGroupList)
                    {
                        Console.WriteLine("Name = " + templateGroup.Name);
                        Console.WriteLine("TranscodeTemplateGroupId = " + templateGroup.TranscodeTemplateGroupId);
                        Console.WriteLine("IsDefault = " + templateGroup.IsDefault);
                        Console.WriteLine("CreationTime = " + templateGroup.CreationTime);
                    }
                }
            }
            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>
        /// 查询转码模板组列表
        /// </summary>
        /// <returns>模板组列表</returns>
        /// <param name="client">Client.</param>
        public static ListTranscodeTemplateGroupResponse ListTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
            // 返回结果
            return client.GetAcsResponse(request);

        }
    }
}

查询单个转码模板组

调用GetTranscodeTemplateGroup接口,完成查询单个转码模板组功能。

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

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.GetTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetTranscodeTemplateGroupResponse response = GetTranscodeTemplateGroup(client);
                // 打印请求ID
                Console.WriteLine("RequestId = " + response.RequestId);
                // 打印模板组信息
                Console.WriteLine("Name = " + response.TranscodeTemplateGroup.Name);
                Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroup.TranscodeTemplateGroupId);
                Console.WriteLine("IsDefault = " + response.TranscodeTemplateGroup.IsDefault);
                Console.WriteLine("CreationTime = " + response.TranscodeTemplateGroup.CreationTime);
            }
            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>
        /// 查询单个转码模板组
        /// </summary>
        /// <returns>模板组</returns>
        /// <param name="client">Client.</param>
        public static GetTranscodeTemplateGroupResponse GetTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
            request.TranscodeTemplateGroupId = "94bcd9366be0df7ffba3b6f7b715****";
            // 返回结果
            return client.GetAcsResponse(request);
        }
    }
}

设置默认转码模板组

调用SetDefaultTranscodeTemplateGroup接口,完成设置默认转码模板组功能。

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

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.SetDefaultTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                SetDefaultTranscodeTemplateGroupResponse response = SetDefaultTranscodeTemplateGroup(client);
                // 打印请求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());
            }
        }

        /// <summary>
        /// 设置默认转码模板组
        /// </summary>
        /// <returns>默认转码模板组</returns>
        /// <param name="client">Client.</param>
        public static SetDefaultTranscodeTemplateGroupResponse SetDefaultTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
            // 设置模板ID
            request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ff85****";
            // 返回结果
            return client.GetAcsResponse(request);
        }
    }
}

删除转码模板组

调用DeleteTranscodeTemplateGroup接口,完成删除转码模板组功能。

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

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.DeleteTranscodeTemplateGroup
{
    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
            {
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteTranscodeTemplateGroupResponse response = DeleteTranscodeTemplateGroup(client);
                // 打印请求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());
            }
        }

        /// <summary>
        /// 删除转码模板组配置
        /// </summary>
        /// <param name="client">Client.</param>
        public static DeleteTranscodeTemplateGroupResponse DeleteTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // 构造请求
            DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
            request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ff65****";
            // 返回结果
            return client.GetAcsResponse(request);

        }
    }
}