Todos os produtos
Search
Central de documentação

ApsaraVideo Media Processing:Modelos de transcodificação

Última atualização: Jun 27, 2026

Se os modelos predefinidos do ApsaraVideo Media Processing não atenderem às suas necessidades, crie modelos de transcodificação personalizados com parâmetros como formato de codificação, taxa de quadros e resolução. Os exemplos a seguir com o SDK Java V2.0 demonstram como adicionar, atualizar, excluir e consultar modelos de transcodificação.

Pré-requisitos

Inicialize o cliente antes de começar. Para mais informações, consulte Inicialização.

Adicionar um modelo

Chame a operação AddTemplate para adicionar um modelo.

Nota
  • Caso receba o erro The resource "Template" quota has been used up ao adicionar um modelo, sua cota de modelos de transcodificação foi esgotada. Envie um ticket envie um ticket para solicitar um aumento de cota.

  • Anote o ID do modelo de transcodificação retornado após a adição do modelo. Também é possível criar e gerenciar modelos de transcodificação no console. Para mais informações, consulte Modelos de transcodificação.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.AddTemplateRequest addTemplateRequest = new com.aliyun.mts20140618.models.AddTemplateRequest()
                // The name of the template.
                .setName("mps-example")
                // The container.
                .setContainer("{\"Format\":\"mp4\"}")
                // The video stream configuration.
                .setVideo("{\"Codec\":\"H.264\",\"Profile\":\"high\",\"Bitrate\":\"500\",\"Crf\":\"15\",\"Width\":\"256\",\"Height\":\"800\",\"Fps\":\"25\",\"Gop\":\"10s\"}")
                // The audio stream configuration.
                .setAudio("{\"Codec\":\"H.264\",\"Samplerate\":\"44100\",\"Bitrate\":\"500\",\"Channels\":\"2\"}")
                // The general transcoding configurations.
                .setTransConfig("{\"TransMode\":\"onepass\"}")
                // The segment configuration field.
                .setMuxConfig("{\"Segment\":{\"Duration\":\"10\"}}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // If you copy the code to run, print the API return value.
            client.addTemplateWithOptions(addTemplateRequest, runtime);
        } catch (TeaException error) {
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Atualizar um modelo

Utilize a operação UpdateTemplate para atualizar um modelo de transcodificação.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.UpdateTemplateRequest updateTemplateRequest = new com.aliyun.mts20140618.models.UpdateTemplateRequest()
                // The template ID.
                .setTemplateId("16f01ad6175e4230ac42bb5182cd****")
                // The name of the template.
                .setName("MPS-example")
                // The container.
                .setContainer("{\"Format\":\"mp4\"}")
                // The video stream configuration.
                .setVideo("{\"Codec\":\"H.264\",\"Profile\":\"high\",\"Bitrate\":\"500\",\"Crf\":\"15\",\"Width\":\"256\",\"Height\":\"800\",\"Fps\":\"25\",\"Gop\":\"10\"}")
                // The audio stream configuration.
                .setAudio("{\"Codec\":\"aac\",\"Samplerate\":\"44100\",\"Bitrate\":\"500\",\"Channels\":\"2\"}")
                // The muxing configuration.
                .setMuxConfig("{\"Segment\":{\"Duration\":\"10\"}}")
                // The general transcoding configurations.
                .setTransConfig("{\"TransMode\":\"onepass\"}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // If you copy the code to run, print the API return value.
            client.updateTemplateWithOptions(updateTemplateRequest, runtime);
        } catch (TeaException error) {
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Excluir um modelo

Invoque a operação DeleteTemplate para excluir um modelo de transcodificação.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.DeleteTemplateRequest deleteTemplateRequest = new com.aliyun.mts20140618.models.DeleteTemplateRequest()
                // The ID of the custom transcoding template to delete.
                .setTemplateId("16f01ad6175e4230ac42bb5182cd****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // If you copy the code to run, print the API return value.
            client.deleteTemplateWithOptions(deleteTemplateRequest, runtime);
        } catch (TeaException error) {
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Consultar modelos por ID

Execute a operação QueryTemplateList para consultar modelos por ID.

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.QueryTemplateListRequest queryTemplateListRequest = new com.aliyun.mts20140618.models.QueryTemplateListRequest()
                // The list of template IDs to query.
                .setTemplateIds("16f01ad6175e4230ac42bb5182cd****,88c6ca184c0e424d5w5b665e2a12****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // If you copy the code to run, print the API return value.
            client.queryTemplateListWithOptions(queryTemplateListRequest, runtime);
        } catch (TeaException error) {
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Consultar modelos por status

Faça uso da operação SearchTemplate para consultar modelos por status.

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.SearchTemplateRequest searchTemplateRequest = new com.aliyun.mts20140618.models.SearchTemplateRequest()
                // The status of the transcoding templates to search for.
                .setState("Normal")
                // The prefix of the template name to search by.
                .setNamePrefix("S00000001")
                // The number of entries per page for paged query results.
                .setPageSize(10L)
                // The current page number.
                .setPageNumber(1L);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // If you copy the code to run, print the API return value.
            client.searchTemplateWithOptions(searchTemplateRequest, runtime);
        } catch (TeaException error) {
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for demonstration only. Handle exceptions with care. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Referências