All Products
Search
Document Center

Transcoding template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Add a transcoding template group

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                AddTranscodeTemplateGroupResponse response = AddTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the request.
                Console.WriteLine("RequestId = " + response.RequestId);
                // The ID of the transcoding template group.
                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>
        /// Adds a transcoding template group.
        /// </summary>
        /// <returns>The transcoding template group.</returns>
        /// <param name="client">The client.</param>
        public static AddTranscodeTemplateGroupResponse AddTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
            // Sets the name of the transcoding template group.
            request.Name = "grouptest";
            request.TranscodeTemplateList = BuildTranscodeTemplateList();

            // Obtains a response.
            return client.GetAcsResponse(request);

        }

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

            JObject transcodeTemplate = new JObject();
            // Specifies the video stream transcoding configuration.
            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);

            // Specifies the audio stream transcoding configuration.
            JObject audio = new JObject();
            audio.Add("Codec", "AAC");
            audio.Add("Bitrate", "64");
            audio.Add("Channels", "2");
            audio.Add("Samplerate", "32000");
            transcodeTemplate.Add("Audio", audio);

            // Specifies the encapsulation container.
            JObject container = new JObject();
            container.Add("Format", "mp4");
            transcodeTemplate.Add("Container", container);

            // Specifies the conditional transcoding configuration.
            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);

            // Specifies the encryption configuration, which supports only the M3U8 format.
            //JObject encryptSetting = new JObject();
            //encryptSetting.Add("EncryptType", "Private");
            //transcodeTemplate.Add("EncryptSetting", encryptSetting);

            // Sets the definition.
            transcodeTemplate.Add("Definition", "LD");
            // Sets the template name.
            transcodeTemplate.Add("TemplateName", "testtemplate");
            // Associates watermark IDs with transcoding template IDs.
            //JArray watermarkIdList = new JArray();
            //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22a16a");
            // USER_DEFAULT_WATERMARK indicates the default watermark ID.
            //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
            //transcodeTemplate.Add("WatermarkIds", watermarkIdList);

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

Modify a transcoding template group

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                UpdateTranscodeTemplateGroupResponse response = UpdateTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the request.
                Console.WriteLine("RequestId = " + response.RequestId);
                // The ID of the transcoding template group.
                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>
        /// Modifies a transcoding template group.
        /// </summary>
        /// <returns>The transcoding template group.</returns>
        /// <param name="client">The client.</param>
        public static UpdateTranscodeTemplateGroupResponse UpdateTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
            request.Name = "newgrouptest";
            // Sets the ID of the transcoding template group.
            request.TranscodeTemplateGroupId = "4c71a339fecec0152b4fa6f4527b89";

            request.TranscodeTemplateList = BuildTranscodeTemplateList();

            // Obtains a response.
            return client.GetAcsResponse(request);

        }

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

            JObject transcodeTemplate = new JObject();
            // Specifies the video stream transcoding configuration.
            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);

            // Specifies the audio stream transcoding configuration.
            JObject audio = new JObject();
            audio.Add("Codec", "AAC");
            audio.Add("Bitrate", "64");
            audio.Add("Channels", "2");
            audio.Add("Samplerate", "32000");
            transcodeTemplate.Add("Audio", audio);

            // Specifies the encapsulation container.
            JObject container = new JObject();
            container.Add("Format", "mp4");
            transcodeTemplate.Add("Container", container);

            // Specifies the conditional transcoding configuration.
            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);

            // Specifies the encryption configuration, which supports only the M3U8 format.
            //JObject encryptSetting = new JObject();
            //encryptSetting.Add("EncryptType", "Private");
            //transcodeTemplate.Add("EncryptSetting", encryptSetting);

            // Sets the definition.
            transcodeTemplate.Add("Definition", "SD");
            // Sets the template name.
            transcodeTemplate.Add("TemplateName", "testtemplate");
            // Sets the transcoding template ID.
            transcodeTemplate.Add("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56242f");
            // Associates watermark IDs with transcoding template IDs.
            //JArray watermarkIdList = new JArray();
            //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22a16a");
            // USER_DEFAULT_WATERMARK indicates the default watermark ID.
            //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
            //transcodeTemplate.Add("WatermarkIds", watermarkIdList);

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

Query a list of transcoding template groups

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                ListTranscodeTemplateGroupResponse response = ListTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the request.
                Console.WriteLine("RequestId = " + response.RequestId);
                // The encoding template group information.
                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>
        /// Queries a list of transcoding template groups.
        /// </summary>
        /// <returns>The list of encoding template groups.</returns>
        /// <param name="client">The client.</param>
        public static ListTranscodeTemplateGroupResponse ListTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
            // Obtains a response.
            return client.GetAcsResponse(request);

        }
    }
}

Query a transcoding template group

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                GetTranscodeTemplateGroupResponse response = GetTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the request.
                Console.WriteLine("RequestId = " + response.RequestId);
                // The encoding template group information.
                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>
        /// Queries a transcoding template group.
        /// </summary>
        /// <returns>The encoding template group.</returns>
        /// <param name="client">The client.</param>
        public static GetTranscodeTemplateGroupResponse GetTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
            request.TranscodeTemplateGroupId = "94bcd9366be0df7ffba3b6f7b715d826";
            // Obtains a response.
            return client.GetAcsResponse(request);
        }
    }
}

Set the default transcoding template group

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                SetDefaultTranscodeTemplateGroupResponse response = SetDefaultTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the 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());
            }
        }

        /// <summary>
        /// Sets the default transcoding template group.
        /// </summary>
        /// <returns>The default transcoding template group.</returns>
        /// <param name="client">The client.</param>
        public static SetDefaultTranscodeTemplateGroupResponse SetDefaultTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
            // Sets the ID of the transcoding template group.
            request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ffxxxxxx";
            // Obtains a response.
            return client.GetAcsResponse(request);
        }
    }
}

Delete a transcoding template group

For more information about the request and response parameters, see 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
            {
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                DeleteTranscodeTemplateGroupResponse response = DeleteTranscodeTemplateGroup(client);
                // The GUID generated by Alibaba Cloud for the 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());
            }
        }

        /// <summary>
        /// Deletes a transcoding template group.
        /// </summary>
        /// <param name="client">The client.</param>
        public static DeleteTranscodeTemplateGroupResponse DeleteTranscodeTemplateGroup(DefaultAcsClient client)
        {
            // Constructs a request.
            DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
            request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ffxxxxxx";
            // Obtains a response.
            return client.GetAcsResponse(request);

        }
    }
}